Code Red > AutoLISP (Vanilla / Visual)

Modifying Alignment to Profile View help

(1/2) > >>

MSTG007:
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: ---(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)
)
--- End code ---

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

Jeff_M:
Give this a try, @MSTG007


--- Code - Auto/Visual Lisp: ---(defun c:PV2AL (/ ss ent align profview endstation midstation pnt startstaion x y)  ;;Profile view to zoom to alignment  (vl-load-com)  (setq ss (ssget ":S+." '((0 . "AECC_PROFILE_VIEW"))))  (if ss    (progn      (setq ent (ssname ss 0))      (setq profview (vlax-ename->vla-object ent))      (setq startstaion (vlax-get profview 'stationstart)            endstation  (vlax-get profview 'stationend)            midstation  (/ (+ startstaion endstation) 2)      )      (setq align (vlax-get profview 'parent))      (vlax-invoke-method align 'pointlocation midstation 0 'x 'y)      (setq pnt (list x y))      (command "zoom" "c" pnt 300)      (princ "Zoomed to Alignment.")    )  )  (princ)) 

BIGAL:
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.

MSTG007:
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: ---Command: PV2AL
Select objects:
; error: bad argument type: lselsetp #<VLA-OBJECT IAeccAlignment 000001e9a48be8d0>

--- End code ---


--- Code: ---...
      (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)
...

--- End code ---


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.

Jeff_M:
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: ---(defun c:PV2AL (/ ss ent align profview endstation midstation pnt startstaion x y)  ;;Profile view to zoom to alignment  (command "undo" "begin")  (vl-load-com)  (setq ss (ssget ":S+." '((0 . "AECC_PROFILE_VIEW"))))  (if ss    (progn      (setq ent (ssname ss 0))      (setq pickpt  (last (last (car (ssnamex ss 0)))))      (setq profview (vlax-ename->vla-object ent))      (vlax-invoke-method profview 'findstationandelevationatxy (car pickpt)(cadr pickpt) 'sta 'elev)      (setq startstation        (vlax-get profview 'stationstart)            endstation  (vlax-get profview 'stationend)            midstation  (/ (+ startstation endstation) 2)      )      (setq align (vlax-get profview 'parent))      (vla-highlight align :vlax-true)      (if (and (> sta (vlax-get align 'startingstation))               (< sta (vlax-get align 'endingstation))               )        (setq midstation sta)        )      (vlax-invoke-method align 'pointlocation midstation 0 'x 'y)      (setq pnt (list x y))      (command "zoom" "c" pnt 200)      (princ "Zoomed to Alignment.")    )  )  (princ)) 

Navigation

[0] Message Index

[#] Next page

Go to full version