Author Topic: Few Civil 3d Routines  (Read 3705 times)

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Few Civil 3d Routines
« on: August 02, 2015, 05:03:04 AM »
Before I tackled .Net and when first diving into Civil3d I was desperate to access objects using lisp. Just some of the remnants of the past, and likely lots of rookie mistakes, but they did the job :)

;;;;Streams surface elevations in the command line

(defun c:SEI ()
  (vl-load-com)
  (setq obj (vlax-ename->vla-object (car (entsel "\nSurface:"))))
  (while
    (setq pt (cadr (grread t)))
     (setq pt (trans pt 0 1))
     (print
       (vlax-invoke obj 'FindElevationAtXY (car pt) (cadr pt))
     )
     (princ)
  )
)

;;;add elevation tags along a feature line...use with a block that has two attributes...one for elevation...another for description

(defun c:flt ()
(command "undo" "begin")

(setq mydwgscale (getvar "dimscale"))
(setq suffix (getstring "\nSuffix?"))
(print "Select Featureline:")
(setq featureobj (vlax-ename->vla-object (car (entsel))))
(while (= 0 0)
(setq location (getpoint "\nPoint Along Feature Line:"))
(setq location (vlax-curve-getClosestPointToProjection featureobj location '(0 0 1)))
(setq param (vlax-curve-getParamAtPoint featureobj location))
(setq pointdata (vlax-curve-getPointAtParam featureobj param))
(setq xpt (car pointdata))
(setq ypt (cadr pointdata))
(setq xy (list xpt ypt))
(setq elev (caddr pointdata))
(setq elev (rtos elev 2 2))
(command "-insert" "ELV-TAG DYN" xy 30 "45.0" elev suffix)
)
(command "undo" "end")
(princ));;;

;;;used to draw polylines in a profile view using stations and elevations

(defun c:pstal ()
(princ "\nPress Return to draw line")
(setq ptlist nil)
(vl-load-com)
(command "-layer" "n" "B-CONST" "S" "B-CONST" "C" "140" "" "")
(setq ent (entsel "\nSelect profile view:"))
(while
(setq sta (getreal "\nStation:"))
(setq elev (getreal "\nElevation:"))
(setq obj (vlax-ename->vla-object (car ent)))
(vlax-invoke-method obj 'FindXYAtStationAndElevation sta elev 'x 'y)
(setq pnt (list x y))
(setq ptlist (append ptlist (list pnt)))
)
(setq ptlen (length ptlist))
(if (= ptlen 1)
(command "line" pnt)
(progn
(command "line")(foreach pnt ptlist (command pnt))(command nil)
)
)
(princ));;;;


;;;;;use with a block with 2 attributes... your finish grade profile should be named exactly the same as your alignment with "-CL-FG" at the end. It inserts the block and places the elevation and station

;;;adds sta and elevation label to profile view

(defun c:pstl ()
(vl-load-com)
(command "undo" "begin")
(command "-layer" "n" "C-PROF-T" "S" "C-PROF-T" "C" "GREEN" "" "")
(setq ent (entsel "\nSelect profile view:"))
(while (= 0 0)
(setq obj (vlax-ename->vla-object (car ent)))
(setq proparent (vlax-get-property obj 'parent))
(setq nam (vlax-get-property proparent 'Name))
(setq pro (vlax-get-property proparent 'profiles))
(vlax-put (vlax-invoke-method pro 'item 0) 'name (strcat nam "-CL-FG"))
(setq pro (vlax-get-property proparent 'profiles))
(setq pronam (vlax-invoke-method pro 'item (strcat nam "-CL-FG")))
(setq propvi (vlax-get-property pronam 'pvis))
(setq pnt (getpoint "\nPoint to Label:"))
(setq xpnt (car pnt))
(setq ypnt (cadr pnt))
(setq staoff (vlax-invoke-method obj 'FindStationAndElevationAtXY xpnt ypnt 'sta 'elev))

;;;covert to station;;;
  (setq stat (rtos sta 2 2))
    (setq stal (- (strlen stat) 1))
    (if   (= stal 6)
      (progn
   (setq lta (substr stat 1 2))
   (setq ltb (substr stat 3 6))
   (setq sta (strcat lta "+" ltb))
      )               ;end progn
               ;else
      (if (= stal 5)
   (progn
     (setq lta (substr stat 1 1))
     (setq ltb (substr stat 2 5))
     (setq sta (strcat lta "+" ltb))
   )            ;end progn
               ;else
   (if (= stal 4)
     (progn
       (setq lta (substr stat 1 1))
       (setq ltb (substr stat 2 4))
       (setq sta (strcat "00+" lta ltb))
     )            ;end progn
               ;else
     (if (= stal 3)
       (progn
         (setq lta (substr stat 1 1))
         (setq ltb (substr stat 2 3))
         (setq sta (strcat "00+0" lta ltb))
       )
     )
   )
      )
    )
;;;end conversion;;;;

(setq elev (rtos elev 2 2))
(command "-insert" "PROF-NOTE" pnt "40.0" "" "45.0" (strcat "STA.=" sta)(strcat "INV.=" elev)"")
)
(command "undo" "end")
(princ));;;;



;;;;adds pvi to profile view...profiles need to have exact name of alignment with "-CL-FG" at the end;;;;

(defun c:apvi ()
(vl-load-com)
(command "undo" "begin")
(setq ent (entsel "\nSelect profile view:"))
(while (= 0 0)
(setq obj (vlax-ename->vla-object (car ent)))
(setq proparent (vlax-get-property obj 'parent))
(setq nam (vlax-get-property proparent 'Name))
(setq pro (vlax-get-property proparent 'profiles))
(setq pronam (vlax-invoke-method pro 'item (strcat nam "-CL-FG")))
(setq propvi (vlax-get-property pronam 'pvis))
(setq pnt (getpoint "\nAdd PVI:"))
(setq xpnt (car pnt))
(setq ypnt (cadr pnt))
(setq staoff (vlax-invoke-method obj 'FindStationAndElevationAtXY xpnt ypnt 'sta 'elev))
(vlax-invoke-method propvi 'add sta elev 1)
(setq pviat (vlax-invoke-method propvi 'itemat sta elev))
(setq pviin (vlax-get-property pviat 'gradein))
(setq pvigout (vlax-get-property pviat 'gradeout))
)
(command "undo" "end")
(princ));;;;

;;;;delete pvi from profile view...profiles need to have exact name of alignment with "-CL-FG" at the end;;;

(defun c:dpvi ()
(command "undo" "begin")
(setq ent (entsel "\nSelect profile view:"))
(while (= 0 0)
(setq obj (vlax-ename->vla-object (car ent)))
(setq proparent (vlax-get-property obj 'parent))
(setq nam (vlax-get-property proparent 'Name))
(setq pro (vlax-get-property proparent 'profiles))
(setq pronam (vlax-invoke-method pro 'item (strcat nam "-CL-FG")))
(setq propvi (vlax-get-property pronam 'pvis))
(setq pnt (getpoint "\nDelete PVI:"))
(setq xpnt (car pnt))
(setq ypnt (cadr pnt))
(setq staoff (vlax-invoke-method obj 'FindStationAndElevationAtXY xpnt ypnt 'sta 'elev))
(vlax-invoke-method propvi 'RemoveAt sta elev)
)
(command "undo" "end")
(princ));;;;



;;;;fgpoly creates multi-3dpoly at profile alignment....profile needs to be named exactly like alignment with "-CL-FG" at the end

(defun c:fgpm ()
(command "undo" "begin")
(setq ptlist nil)
(vl-load-com)
(setq adj (getreal "\nChange in Elevation:"))
(setq sel (entsel "\nSelect Alignment: "))
(setq inc 1)
(setq ent (car sel))
(setq obj (vlax-ename->vla-object ent))
(setq end (vlax-get obj 'EndingStation))
(setq nam (vlax-get-property obj 'Name))
(setq pro (vlax-get-property obj 'profiles))
(setq pronam (vlax-invoke-method pro 'item (strcat nam "-CL-FG")))
(setq pviobj (vlax-get pronam 'pvis))
(setq countpvis (vlax-get-property pviobj 'count))
(setq lastpvis (- countpvis 1))
(setq firstpvi (vlax-invoke pviobj 'item 0))
(setq lastpvi (vlax-invoke pviobj 'item lastpvis))
(setq stapvi (vlax-get firstpvi 'Station))
(setq endpvi (vlax-get lastpvi 'Station))
(setq sta (+ stapvi 1.0))
(while (< sta endpvi)
(vlax-invoke-method obj 'PointLocation sta 0 'east 'north)
(vlax-invoke-method obj 'StationOffset east north 'sta 'off)
(setq elev (vlax-invoke-method pronam "ElevationAt" sta))
(setq datum (+ elev adj))
(setq elevfnl (atof (rtos datum 2 2)))
(setq points (list (atof (rtos east 2 2)) (atof (rtos north 2 2)) elevfnl))
(setq ptlist (append ptlist (list points)))
(vlax-invoke-method obj 'PointLocation sta 17 'east 'north)
(vlax-invoke-method obj 'StationOffset east north 'sta 'off)
(setq elevr (vlax-invoke-method pronam "ElevationAt" sta))
(setq datumr (+ elev adj))
(setq datumr (- datumr 0.34))
(setq elevfnlr (atof (rtos datumr 2 2)))
(setq pointsr (list (atof (rtos east 2 2)) (atof (rtos north 2 2)) elevfnlr))
(setq ptlistr (append ptlistr (list pointsr)))
(vlax-invoke-method obj 'PointLocation sta -17 'east 'north)
(vlax-invoke-method obj 'StationOffset east north 'sta 'off)
(setq elevl (vlax-invoke-method pronam "ElevationAt" sta))
(setq datuml (+ elev adj))
(setq datuml (- datuml 0.34))
(setq elevfnll (atof (rtos datuml 2 2)))
(setq pointsl (list (atof (rtos east 2 2)) (atof (rtos north 2 2)) elevfnll))
(setq ptlistl (append ptlistl (list pointsl)))s
(setq sta (+ sta inc))
)
(command "3dpoly")(foreach points ptlist (command points)"")(command nil)
(command "3dpoly")(foreach pointsr ptlistr (command pointsr)"")(command nil)
(command "3dpoly")(foreach pointsl ptlistl (command pointsl)"")(command nil)
(command "undo" "end")
(princ));;;;




;;;draw line on alignment by station;;;

(defun c:stal ()
(command "undo" "begin")
(vl-load-com)
(setq sel (entsel "\nSelect Alignment: "))
(while (= 0 0)
(setq sta (getreal "\nStation: "))
(setq ent (car sel))
(setq lst (entget ent))
(setq obj (vlax-ename->vla-object ent))
(vlax-invoke-method obj 'PointLocation sta -100 'east 'north)
(setq start (strcat (rtos east 2 2) "," (rtos north 2 2)))
(vlax-invoke-method obj 'PointLocation sta 100 'east 'north)
(setq end (strcat (rtos east 2 2) "," (rtos north 2 2)))
(command "line" start end "")
)
(command "undo" "end")
(princ));;;;


;;;label station and offset;;;
(defun c:stl ()
(command "undo" "begin")
(vl-load-com)
(setq lst nil)
(setq sel (entsel "\nSelect Alignment: "))
(while T
(setq pt1 (getpoint "\nPoint: "))
(setq rtpoint pt1)
(setq ent (car sel))
(setq lst (entget ent))
(setq obj (vlax-ename->vla-object ent))
    (setq nam (vlax-get-property obj 'Name))
    (setq sta1 (vlax-get-property obj 'StartingStation))
    (setq sta2 (vlax-get-property obj 'EndingStation))
    (vlax-invoke-method obj 'StationOffset (car pt1) (cadr pt1) 'sta 'off)
    (setq sta (rtos sta 2 2))
    (setq off (rtos off 2 2))
;;;convert to station format;;;;
(setq sta2 (atof sta))
(setq x sta2)
(setq n 2)
(setq pref (fix (/ x 100.00)))
(setq suff (rtos (- x (* 100 pref)) 2 n))
(setq fnl (strcat (itoa pref) "+" suff))
;;;add left or right to offset;;;
(setq off2 (atof off))
(if (< off2 0)(setq side "' LT.")(setq side "' RT."))
(setq off (atof off))
(setq off (abs off))
(setq off (rtos off 2 2))
(setq off (strcat off side))
(command "text" pt1 "" FNL)
(setq ent1 (entlast))
(command "text" "" off)
(setq ent2 (entlast))
(command "rotate" ent1 ent2 "" rtpoint pause)
);end while
(command "undo" "end")
(princ));;;

HOSNEYALAA

  • Newt
  • Posts: 103
Re: Few Civil 3d Routines
« Reply #1 on: April 19, 2020, 02:22:52 PM »

Thank you very much

HOSNEYALAA

  • Newt
  • Posts: 103
Re: Few Civil 3d Routines
« Reply #2 on: April 19, 2020, 02:45:43 PM »
 HI nobody
please
Is there any reason for a PRESSUREPIPE network IN CIVIL 3D ?
Determine the length or coordinates
Or parameters about it
Code: [Select]

;https://forums.autodesk.com/t5/civil-3d-customization/get-point3d-values-in-property-set/m-p/9436843#M17896
(defun c:PipeInverts ()
  (setq ss (ssget ":s" '((0 . "AECC_PRESSUREPIPE"))))
  (if ss
    (progn
      (setq pipeObj (vlax-ename->vla-object (ssname ss 0)))
      (setq sp (vlax-safearray->list (vlax-variant-value (vlax-get-property pipeObj 'PointAtParam 0))))
      (setq ep (vlax-safearray->list (vlax-variant-value (vlax-get-property pipeObj 'PointAtParam 1))))
      (setq PipeStyles  (vlax-get-property pipeObj 'HYPERLINKS  ))
      (setq Alignment (vlax-get-property pipeObj 'PipeStyles ))
      (setq Connectors (vlax-get-property pipeObj 'Connectors))
      (setq EGLDown (vlax-get-property pipeObj 'EGLDown))
      (setq EGLUp  (vlax-get-property pipeObj 'EGLUp ))
      (setq   (vlax-get-property pipeObj 'EGLUp ))
      (setq EndStructure  (vlax-get-property pipeObj 'EndStructure ))
        FlowDirection
      (setq FlowDirection  (vlax-get-property pipeObj 'FlowDirection ))
      (setq FlowDirectionMethod   (vlax-get-property pipeObj 'FlowDirectionMethod  ))
      (setq HGLDown   (vlax-get-property pipeObj 'HGLDown  ))
      (setq HGLUp   (vlax-get-property pipeObj 'HGLUp  ))
      (setq HoldOnResize   (vlax-get-property pipeObj 'HoldOnResize  ))
      (setq  InnerHeight   (vlax-get-property pipeObj 'InnerHeight  ))
      (setq Labels   (vlax-get-property pipeObj 'Labels  ))
      (setq Length2D   (vlax-get-property pipeObj 'Length2D  ))
      (setq Length3D   (vlax-get-property pipeObj 'Length3D  ))
      (setq MaximumCover   (vlax-get-property pipeObj 'MaximumCover  ))
      (setq MinimumCover   (vlax-get-property pipeObj 'MinimumCover  ))
      (setq OuterDiameterOrWidth   (vlax-get-property pipeObj 'OuterDiameterOrWidth  ))
      (setq  OuterHeight  (vlax-get-property pipeObj 'OuterHeight ))
      (setq  pdr    (vlax-get-property pipeObj 'PartDataRecord   ))
      (setq idx 0)
      (vlax-for rec pdr
(princ (strcat "\nIndex: " (itoa idx) " - Context String: " (vlax-get-property rec 'ContextString) " | Value: " (vl-princ-to-string (vlax-variant-value (vlax-get-property rec 'Tag)))))
(setq idx (+ idx 1))
);end vlax-for
     
      (setq PartFamily   (vlax-get-property pipeObj 'PartFamily  ))
      (setq PartSizeName  (vlax-get-property pipeObj 'PartSizeName ));"600 mm Concrete Pipe"
      (setq PartType   (vlax-get-property pipeObj 'PartType  ))
      (setq ProfileNetworkParts   (vlax-get-property pipeObj 'ProfileNetworkParts  ))
      (setq Radius   (vlax-get-property pipeObj 'Radius  ))
      (setq Slope   (vlax-get-property pipeObj 'Slope  ))
      (setq StartPoint   (vlax-get-property pipeObj 'StartPoint  ))
      (setq StartStructure   (vlax-get-property pipeObj 'StartStructure  ))
      (setq  STMPipeMetadata   (vlax-get-property pipeObj 'STMPipeMetadata  ))
      (setq Style   (vlax-get-property pipeObj 'Style  ))
      (setq SubEntityType   (vlax-get-property pipeObj 'SubEntityType  ))
      (setq Surface   (vlax-get-property pipeObj 'Surface  ))
      (setq  SweptShape   (vlax-get-property pipeObj ' SweptShape  ))
      (setq WallThickness   (vlax-get-property pipeObj 'WallThickness  ))
   






     
      (setq EndPoint (vlax-get-property pipeObj 'EndPoint))
     
     
      (setq invSp (- (caddr sp) (/ innerPipeDiameter 2.0)))
      (setq invEp (- (caddr ep) (/ innerPipeDiameter 2.0)))
      (princ (strcat "\nStart Invert: " (rtos invSp 2 3) "\nEnd Invert: " (rtos invEp 2 3)))
      )
    )
  (princ)
  )



http://docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/com/AeccXPipeLib__IAeccPipe.htm?_ga=2.26271101.1521064891.1585343442-1137725286.1539614530

http://docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/com/AeccXPipeLib__IAeccStructure.htm