Author Topic: Modifying Alignment to Profile View help  (Read 592 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Modifying Alignment to Profile View help
« on: April 12, 2024, 12:36:41 PM »
I found this lisp which you can select the alignment and it would zoom to the associated profile view.
I am trying to find a way to reverse it so that if I select the profile view, it would select / zoom to the alignment.

Code: [Select]
(defun c:zztop2 (/ ALIGN ELEV ss d PNT PROFVIEW PT SEL STA X Y profview_max profview_min)
;;https://forums.autodesk.com/t5/civil-3d-customization/lisp-routine-select-alignment-then-zoom-to-profile/td-p/9349483
(command "undo" "begin")
(vl-load-com)
(princ "\nSelect Alignment near station to zoom: ")
(setq ss (ssget ":S" '((0 . "AECC_ALIGNMENT"))))
(setq d (ssnamex ss 0))
(setq pt (last (last (car d))))
(setq ent (cadar d))
(setq align (vlax-ename->vla-object ent))
(setq profview (vlax-invoke (vlax-get align 'profileviews) 'item 0))
(setq profview_max (vlax-get-property profview 'ElevationMax)); ElevationMax
(setq profview_min (vlax-get-property profview 'ElevationMin)); ElevationMin
(SETQ elev (+ (/ (- profview_max profview_min) 2) profview_min))
(vlax-invoke-method align 'StationOffset (car pt) (cadr pt) 'sta 'off)
(vlax-invoke-method profview 'FindXYAtStationAndElevation sta elev 'x 'y)
(setq pnt (list x y))
(command "zoom" "c" pnt "300")
(command "undo" "end")
(princ)
);end defun

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:PV2AL (/ ss d ent align profview ) ;;Profile view to zoom to alignment
  (command "undo" "begin")
  (vl-load-com)
  (setq ss (ssget ":S" '((0 . "AECC_PROFILE_VIEW"))))
  (if ss
      (progn
        (setq d (ssnamex ss 0))
        (setq ent (cadar d))
        (setq profview (vlax-ename->vla-object ent))
        (setq align(vlax-invoke (vlax-get profview 'Alignment) 'Item 0))
        (if align
            (progn
              (command "zoom" "c" pnt "300")
              (command "undo" "end")
              (princ "Zoomed to Alignment.")
              )
            )
        )
      )
  (princ)
)

I wonder if i am going about this totally wrong. thank you.
Civil3D 2020

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Modifying Alignment to Profile View help
« Reply #1 on: April 13, 2024, 02:12:55 PM »
Give this a try, @MSTG007

Code - Auto/Visual Lisp: [Select]
  1. (defun c:PV2AL (/ ss ent align profview endstation midstation pnt startstaion x y)
  2.   ;;Profile view to zoom to alignment
  3.   (setq ss (ssget ":S+." '((0 . "AECC_PROFILE_VIEW"))))
  4.   (if ss
  5.     (progn
  6.       (setq ent (ssname ss 0))
  7.       (setq profview (vlax-ename->vla-object ent))
  8.       (setq startstaion (vlax-get profview 'stationstart)
  9.             endstation  (vlax-get profview 'stationend)
  10.             midstation  (/ (+ startstaion endstation) 2)
  11.       )
  12.       (setq align (vlax-get profview 'parent))
  13.       (vlax-invoke-method align 'pointlocation midstation 0 'x 'y)
  14.       (setq pnt (list x y))
  15.       (command "zoom" "c" pnt 300)
  16.       (princ "Zoomed to Alignment.")
  17.     )
  18.   )
  19.   (princ)
  20. )
  21.  

BIGAL

  • Swamp Rat
  • Posts: 1429
  • 40 + years of using Autocad
Re: Modifying Alignment to Profile View help
« Reply #2 on: April 13, 2024, 08:04:28 PM »
If your using "Civil Site Design" when in a profile design view you have a marker on your plan view showing where you are, as you move in the profile it moves in the model, if you have enough screen area can have cross sections open also so as vertical levels are changed the cross sections update.

Much easier and has so much more options at a reasonable price.
A man who never made a mistake never made anything

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: Modifying Alignment to Profile View help
« Reply #3 on: April 15, 2024, 08:09:37 AM »
Thanks Jeff, works. It made sense what you did as well.  I was trying to add the ability to select the alignment, but i keep getting this error.

Code: [Select]
Command: PV2AL
Select objects:
; error: bad argument type: lselsetp #<VLA-OBJECT IAeccAlignment 000001e9a48be8d0>

Code: [Select]
...
      (setq align (vlax-get profview 'parent))

(vla-highlight (vlax-ename->vla-object (ssname align (setq in (1- in)))) :vlax-true)

      (vlax-invoke-method align 'pointlocation midstation 0 'x 'y)
...


Thank you for sharing that BIGAL, When using civil3d. I usually use the stationtracker which works.

This brings up a great idea, if you were to modify Jeffs code, where you could select anywhere on the profile view, it would zoom right to that spot.
Civil3D 2020

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Modifying Alignment to Profile View help
« Reply #4 on: April 15, 2024, 12:06:47 PM »
Added alignment highlighting and zoom to the picked point station if lies withing the alignment stationing, else it goes to the midstation...the PV may be longer than the alignment.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:PV2AL (/ ss ent align profview endstation midstation pnt startstaion x y)
  2.   ;;Profile view to zoom to alignment
  3.   (command "undo" "begin")
  4.   (setq ss (ssget ":S+." '((0 . "AECC_PROFILE_VIEW"))))
  5.   (if ss
  6.     (progn
  7.       (setq ent (ssname ss 0))
  8.       (setq pickpt  (last (last (car (ssnamex ss 0)))))
  9.       (setq profview (vlax-ename->vla-object ent))
  10.       (vlax-invoke-method profview 'findstationandelevationatxy (car pickpt)(cadr pickpt) 'sta 'elev)
  11.       (setq startstation        (vlax-get profview 'stationstart)
  12.             endstation  (vlax-get profview 'stationend)
  13.             midstation  (/ (+ startstation endstation) 2)
  14.       )
  15.       (setq align (vlax-get profview 'parent))
  16.       (vla-highlight align :vlax-true)
  17.       (if (and (> sta (vlax-get align 'startingstation))
  18.                (< sta (vlax-get align 'endingstation))
  19.                )
  20.         (setq midstation sta)
  21.         )
  22.       (vlax-invoke-method align 'pointlocation midstation 0 'x 'y)
  23.       (setq pnt (list x y))
  24.       (command "zoom" "c" pnt 200)
  25.       (princ "Zoomed to Alignment.")
  26.     )
  27.   )
  28.   (princ)
  29. )
  30.  

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: Modifying Alignment to Profile View help
« Reply #5 on: April 15, 2024, 05:35:56 PM »
Again, Thank you Jeff. Making it look simple with Civil3D. ;)
Civil3D 2020

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: Modifying Alignment to Profile View help
« Reply #6 on: May 08, 2024, 12:59:15 PM »
I got another one for you within this. I was hoping to Select the Profile View to Grab the Alignment. However, with this setup, I have to pick the alignment first. Then it will select all the Civil3D PN parts and the PressureN Parts, and place them into the selected profile view. I was trying to use the original selection set and apply it to both these commands (AddNetworkPartsToProf, AddPressurePartsToProf). Not having much luck. Any ideas?



Code: [Select]
(defun c:PN2PV (/ add ss i e l d g lst s n alignEnt alignObj startSta endSta)
  (setq add (ssadd))
  (princ "\nSelect Alignment: ")
  (if (setq ss (ssget '((0 . "AECC_ALIGNMENT"))))
      (progn
        ;; If selection set is not empty
        (repeat (setq i (sslength ss))
          (setq e (ssname ss (setq i (1- i)))
                l (vlax-curve-getdistatpoint e (vlax-curve-getendpoint e))
                d (/ l 300.)
                g d
                lst nil)
          (repeat 300
            (setq lst (cons (vlax-curve-getpointatdist e g) lst)
                  g (+ g d)))
          (setq lst (append lst (list (vlax-curve-getstartpoint e))))
          (if (setq s (ssget "_F" lst '((0 . "AECC_STRUCTURE,AECC_PIPE,AECC_PRESSUREPIPE,AECC_FITTING,AECC_APPURTENANCE"))))
              (repeat (setq n (sslength s))
                (ssadd (ssname s (setq n (1- n))) add))))
       
        (sssetfirst nil add)
        (command "AddNetworkPartsToProf"))

          (if (setq s (ssget "_F" lst '((0 . "AECC_STRUCTURE,AECC_PIPE,AECC_PRESSUREPIPE,AECC_FITTING,AECC_APPURTENANCE"))))
              (repeat (setq n (sslength s))
                (ssadd (ssname s (setq n (1- n))) add))))

        (sssetfirst nil add)
        (command "AddPressurePartsToProf"))
     
      (princ "\nNo entities selected."))
  (princ))
Civil3D 2020