Total Length of Civil 3D Objects (e.g. Feature Lines, Survey Figures)

Total Length of Civil 3D Objects (e.g. Feature Lines, Survey Figures)

alexka
Advocate Advocate
4,422 Views
7 Replies
Message 1 of 8

Total Length of Civil 3D Objects (e.g. Feature Lines, Survey Figures)

alexka
Advocate
Advocate

Has anyone come across a lisp routine that outputs a total length of multiple C3D objects such as feature lines and survey figures? I've found a couple lisp routines that will sum the lengths of non-C3D objects like lines, polylines, and arcs. Below is a link to one of the forum posts with the lisp:

 

https://forums.autodesk.com/t5/autocad-forum/how-to-calculate-the-total-length-of-multiple-lines/td-...

 

I haven't had any luck finding something similar that works for 3D polylines, feature lines, and  survey figures. Ideally, I would be able to total non-C3D and C3D objects with one command. I'm currently just exploding these objects to non-C3D objects in a temporary drawing and using the lisp routine from the link above to get a total length.

 

Thanks.

0 Likes
Accepted solutions (1)
4,423 Views
7 Replies
Replies (7)
Message 2 of 8

Jeff_M
Consultant
Consultant
Which of the lisps in that link are you using?
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 8

alexka
Advocate
Advocate

@Jeff_M,

 

I've just been using the TLEN.lsp

 

Thanks.

0 Likes
Message 4 of 8

hippe013
Advisor
Advisor
Accepted solution
(defun c:TlenC3D ( / ss n)
  (setq gTotalLength 0)
  (setq ss (ssget ))
  (setq n 0)
  (if ss
    (progn
      (repeat (sslength ss)
      (setq obj (vlax-ename->vla-object (ssname ss n)))
      (setq objName (vlax-get-property obj 'ObjectName))
      (cond
        ((= objName "AeccDbFeatureLine")(C3D:AddFeatureLineLength obj))
        ((= objName "AeccDbSvFigure")(C3D:AddSurveyFigureLength obj))
        ((= objName "AcDb3dPolyline")(C3D:AddPolyline3DLength obj))
        ((= objName "AcDbPolyline")(C3D:AddPolylineLength obj))
        ((= objName "AcDbArc")(C3D:AddArcLength obj))
        ((= objName "AcDbLine")(C3D:AddLineLength obj))
        )
      (setq n (+ n 1))
      )
    (princ (strcat "\nTtotal Length: " (rtos gTotalLength 2 2)))
      )
    )
  (princ)
  )

(defun C3D:AddFeatureLineLength (obj / len)
  (setq len (vlax-get-property obj 'Length2D))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nFeatureline: " (rtos len 2 2)))
  )

(defun C3D:AddSurveyFigureLength (obj / len)
  (setq len (vlax-get-property obj 'Length2D))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nSurveyFigure: " (rtos len 2 2)))
  )

(defun C3D:AddPolyline3DLength (obj / len)
  (setq len (vlax-get-property obj 'Length))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nPolyline3D: " (rtos len 2 2)))
  )

(defun C3D:AddPolylineLength (obj / len)
  (setq len (vlax-get-property obj 'Length))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nPolyline: " (rtos len 2 2)))
  )

(defun C3D:AddArcLength (obj / len)
  (setq len (vlax-get-property obj 'ArcLength))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nArc: " (rtos len 2 2)))
  )

(defun C3D:AddLineLength (obj / len)
  (setq len (vlax-get-property obj 'Length))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nLine: " (rtos len 2 2)))
  )

    

 

 

Feel free to modify to suit your needs.

Message 5 of 8

alexka
Advocate
Advocate

Thanks @hippe013.

 

That works great!

0 Likes
Message 6 of 8

vaughan.giles7AGEV
Advocate
Advocate

Thanks for the C3D TLEN adaptation.

 

I have tested it on both 3D Polylines and Featurelines and unfortunately the resulting figures came back with their 2D equivalent values, not their 3D Lengths.

 

Has anyone encountered the same issue with this code?

0 Likes
Message 7 of 8

hosneyalaa
Advisor
Advisor

@vaughan.giles7AGEV 

For feature line can you trying this 

In code @hippe013  change property Length2D in function C3D:AddFeatureLineLength to property Length3D

(setq len (vlax-get-property obj 'Length2D)

 To 

(setq len (vlax-get-property obj 'Length3D))

 

Message 8 of 8

alexka
Advocate
Advocate

That's a great update to the lisp.

 

Since the original post, I updated the lisp to also work with C3D pipe segments. It sums the 3D length (center-to-center) of selected pipe segments. Here is the complete code:

 

(defun c:TlenC3D ( / ss n)  
  (setq gTotalLength 0)
  (setq ss (ssget ))
  (setq n 0)
  (if ss
    (progn
      (repeat (sslength ss)
      (setq obj (vlax-ename->vla-object (ssname ss n)))
      (setq objName (vlax-get-property obj 'ObjectName))
      (cond
        ((= objName "AeccDbFeatureLine")(C3D:AddFeatureLineLength obj))
        ((= objName "AeccDbSvFigure")(C3D:AddSurveyFigureLength obj))
        ((= objName "AcDb3dPolyline")(C3D:AddPolyline3DLength obj))
        ((= objName "AcDbPolyline")(C3D:AddPolylineLength obj))
        ((= objName "AcDbArc")(C3D:AddArcLength obj))
        ((= objName "AcDbLine")(C3D:AddLineLength obj))
		((= objName "AeccDbPipe")(C3D:AddPipeLength obj))
        )
      (setq n (+ n 1))
      )
    (princ (strcat "\nTotal Length: " (rtos gTotalLength 2 2)))
      )
    )
  (princ)
  )

(defun C3D:AddFeatureLineLength (obj / len)
  (setq len (vlax-get-property obj 'Length2D))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nFeatureline: " (rtos len 2 2)))
  )

(defun C3D:AddSurveyFigureLength (obj / len)
  (setq len (vlax-get-property obj 'Length2D))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nSurveyFigure: " (rtos len 2 2)))
  )

(defun C3D:AddPolyline3DLength (obj / len)
  (setq len (vlax-get-property obj 'Length))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nPolyline3D: " (rtos len 2 2)))
  )

(defun C3D:AddPolylineLength (obj / len)
  (setq len (vlax-get-property obj 'Length))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nPolyline: " (rtos len 2 2)))
  )

(defun C3D:AddArcLength (obj / len)
  (setq len (vlax-get-property obj 'ArcLength))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nArc: " (rtos len 2 2)))
  )

(defun C3D:AddLineLength (obj / len)
  (setq len (vlax-get-property obj 'Length))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nLine: " (rtos len 2 2)))
  )

(defun C3D:AddPipeLength (obj / len)
  (setq len (vlax-get-property obj 'Length3D))
  (setq gTotalLength (+ gTotalLength len))
  (princ (strcat "\nPipe: " (rtos len 2 2)))
  ) 

 

 

Hopefully someone else can get some use out of it.