Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help with Lisp for multiple elevation PVIs on a Feature line

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
753 Views, 6 Replies

Need help with Lisp for multiple elevation PVIs on a Feature line

Does anyone know how to or have a lisp that will insert multiple PVI elevations from a txt file kind of like the alignment command to create points on alignment from txt file. 

Labels (3)
6 REPLIES 6
Message 2 of 7
Jeff_M
in reply to: Anonymous

I've not been able to get the SetPointElevation or SetPointsElevation Featureline methods to work in lisp. Using the .NET API this is fairly simple.

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 7
Anonymous
in reply to: Jeff_M

@Jeff_M Could you give me an example script on how to do this?

Message 4 of 7
hosneyalaa
in reply to: Anonymous

;;https://forums.autodesk.com/t5/civil-3d-customization/flatten-feature-line-elevations-by-single-command/m-p/8320039?fbclid=IwAR3gs-46v7wDPCgQwLKawQK7IGT7yA3gke1tQG3UiTMNmHPdvF4LUZ-dG6o#M15525


;;flatten feature line elevations by single command 
(defun c:StraightGrade ()
  ;Prompt for Featureline
  (princ "\nSelect Featureline: ")
  (setq ss (ssget ":s" '((0 . "AECC_FEATURE_LINE"))))

  ;If we have a Selection Set then proceed
  (if ss
    (progn
      ;Get Object from SelectionSet
      (setq obj (vlax-ename->vla-object (ssname ss 0)))
      
      ;Get All Points (3)   |  (1)=PI Points (2)=Elevation Points
      (setq pnts (vlax-safearray->list (vlax-variant-value (vlax-invoke-method obj 'GetPoints  3))))
      
      ;Get the Point Count - ;(setq pCount (vlax-get-property obj 'PointsCount))
      (setq pCount (/ (length pnts) 3))

      ;Compute
      (setq sp (list (nth 0 pnts)(nth 1 pnts)(nth 2 pnts)))
      (setq ep (list (nth (- (length pnts) 3) pnts)(nth (- (length pnts) 2) pnts)(nth (- (length pnts) 1) pnts)))
      (setq zDiff (- (caddr ep) (caddr sp) ))
      (setq len (vlax-get-property obj 'Length2D))
      (setq slope (/ zDiff len))

      ;Report
      (princ (strcat "\nStart Point Elev: " (rtos (caddr sp) 2 2)))
      (princ (strcat "\nEnd Point Elev: " (rtos (caddr ep) 2 2)))
      (princ (strcat "\nElevation Difference: " (rtos zDiff 2 2)))
      (princ (strcat "\nTotal 2D Length: " (rtos len 2 2)))
      (princ (strcat "\nUsing Slope of: " (rtos (* slope 100.00) 2 2) "%"))

      ;Set increment to Beginning of Second Point
      (setq i 3)

      ;Repeat for each point except the first and last
      (repeat (- pCount 2)
	
	;Get Current Point
	(setq p (list (nth i pnts) (nth (+ i 1) pnts) (nth (+ i 2) pnts)))
	
	;Get its 2D Distance along the Featureline
	(setq dist (vlax-curve-getDistAtPoint obj p))
	
	;Compute
	(setq newZ (+ (* dist slope) (caddr sp)))
	(setq newP (list (car p)(cadr p) newZ))

	;Set the Elevation
	(vlax-invoke-method obj 'SetPointElevation (vlax-3d-point newp))

	;Increment
	(setq i (+ i 3))
	)
      )
    )
  (command "REGENALL")
  (princ)
  )

 

Message 5 of 7
Jeff_M
in reply to: hosneyalaa

@hosneyalaa thanks for this. It looks like you are editing existing elevation points, which I do believe works. The OP was wanting to add new elevation points which I have been unable to find a solution for.

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 7
hosneyalaa
in reply to: Jeff_M

MS @Jeff_M 

Thank you, you are our teacher

Sorry for my english is not good

 

I'm after a test
It only works if the entire Feature line height is zero
like the photo

 

التقاط0.PNG

 

 

 

(defun c:LPer (/ #Ent #Read ptT)
   (and
    (setq #Ent (car (entsel "\nSelect FEATURE_LINE: ")))
    (vl-position (cdr (assoc 0 (entget #Ent))) '("AECC_FEATURE_LINE"))
    (setq pipeObj (vlax-ename->vla-object #Ent))
    );_ and
    (while (SETQ pt (GETPOINT "\n-> Pick point"))
      ;;http://docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/com/AeccXLandLib__IAeccLandFeatureLine.htm
      (if pt
	(PROGN
	  (SETQ ptT (vlax-curve-getclosestpointto #Ent (trans pt 1 0) T))
	  (vlax-invoke-method pipeObj 'InsertFeaturePoint (vlax-3d-point ptT) 1)
	  
	  )
      ) ;_ if
    ) ;_ while
   
  (redraw)
  (princ)
) ;_ defun

 

 

التقاط1.PNG

 

 

I have an idea
If the Feature line is high
You can make a list of point heights
Then make  Feature line  equal to zero
Then he made new points in another list, making it LEVEL

From the Follower

;;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/interpolate-vertex-elevation-on-3d-polylines/td-p/6536727?fbclid=IwAR38evRplZDcPzgp-Z1fnyXUkv1jygZFhn8sRc-0XdlKpdR8XIAk8yD5-qU

   (defun interpolare (pct / d1 d2 p1 p2 p3 z1 z2)
  (if

    
    (and
      (setq p1 (vl-some '(lambda (a) (if (caddr a) a)) pct))
      (setq p2 (vl-some '(lambda (a) (if (caddr a) a)) (cdr (member p1 pct))))
      )

    
    (mapcar
        '(lambda (p / z1 z2 d1 d2 p3)
           (setq z1 (caddr p1) d1 (cadddr p1)
                 z2 (caddr p2) d2 (cadddr p2)
           )
           (if
             (caddr p)
             (progn
               (cond
                 ((< (cadddr p) d2)
                  (setq p1 p)
                  )
                 ((= (cadddr p) d2)
                  (if
                    (setq p3 (vl-some '(lambda (a) (if (caddr a) a)) (cdr (member p2 pct))))
                    (setq p1 p p2 p3)
                    )
                  )
                 )
               (list (car p) (cadr p) (caddr p))
               )
             (list (car p) (cadr p) (/ (+ (* z2 (- (cadddr p) d1)) (* z1 (- d2 (cadddr p)))) (- d2 d1)))
             )
           )
        pct
        )

    
    (mapcar '(lambda (a) (list (car a) (cadr a) (if z1 (caddr z1) 0.0))) pct)
    
  );if
);  interpolare

 

 

Then introduce the heights again on the  Feature line

ALL POINTS 

 

I hope to be clear idea

Message 7 of 7
Jeff_M
in reply to: hosneyalaa

@hosneyalaa @Anonymous I'm feeling quite dumb right now. I was using some old testing code and neglected to look at the help file. I was also working on something else at the time so wasn't thinking clearly I guess.

 

Here is some code that shows hows to read a list of pairs that could come from a text file. The pairs represent the distance along the featureline and the elevation at that point. It creates ElevationPoints, not pi's.

 

 

(setq thelist '(10 24.3 30 25.6 50 27.1))
(setq fl (vlax-ename->vla-object (car (entsel))))
(setq i -1)
(while (setq dist (nth (setq i (1+ i)) thelist))
  (setq pt (vlax-curve-getpointatdist fl dist)
	pt(list (car pt) (cadr pt) (nth (setq i (1+ i)) thelist))
	)
   (vlax-invoke-method fl 'insertfeaturepoint (vlax-3d-point pt) 2)
  )
Jeff_M, also a frequent Swamper
EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report