Point Elevation Difference Lisp Routine

Point Elevation Difference Lisp Routine

JBACH1012
Contributor Contributor
3,245 Views
19 Replies
Message 1 of 20

Point Elevation Difference Lisp Routine

JBACH1012
Contributor
Contributor

I am trying to find a Lisp Routine that will allow me to select two Cogo Points and list the difference in elevation (z) in Inches with a Multileader. I have seen other posts on here about doing this but none seem to work for me. I have tried to Frankenstein a Lisp Routine from other posts but I do not know coding very well (see below). Any help on this matter will be greatly appreciated.

 

(defun c:ped ()

(setq Pt1 (ssget '((0 . "AECC_COGO_POINT"))))

(setq pt2 (ssget '((0 . "AECC_COGO_POINT"))))

(setq E1 (nth 0 Pt1))

(setq N1 (nth 1 Pt1))

(setq Z1 (nth 2 Pt1))

(setq E2 (nth 0 pt2))

(setq N2 (nth 1 pt2))

(setq Z2 (nth 2 pt2))

(princ (- z1 z2))

(command "_TEXT" pause "0.06" "0" (rtos (- z1 z2)))

;finish cleanly

);end of defun

John A. Bach Jr., CST II
High Definition Survey Manager
C3D 2024
Dell Precision 3660
Windows 11 Pro
128GB RAM
0 Likes
Accepted solutions (2)
3,246 Views
19 Replies
Replies (19)
Message 2 of 20

hosneyalaa
Advisor
Advisor
0 Likes
Message 3 of 20

JBACH1012
Contributor
Contributor

Thanks for the link but I am getting "Error: Automation Error. Problem in loading application" when I try to run it in Civil 3D 2021. It may be because this Lisp Routine was created in 2014.

John A. Bach Jr., CST II
High Definition Survey Manager
C3D 2024
Dell Precision 3660
Windows 11 Pro
128GB RAM
0 Likes
Message 4 of 20

Jeff_M
Consultant
Consultant
Accepted solution

@JBACH1012 attached is a lisp which does this. Be sure you have your desired Mleader style set current prior to running. It gives the option to select the points by Number or by Selection, it then will loop through as long as 2 points are provided.

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 20

JBACH1012
Contributor
Contributor

Thank you! This works perfectly!

John A. Bach Jr., CST II
High Definition Survey Manager
C3D 2024
Dell Precision 3660
Windows 11 Pro
128GB RAM
0 Likes
Message 6 of 20

albertluus2J23M
Community Visitor
Community Visitor

hi,

 

what is the command to use with this lisp.

0 Likes
Message 7 of 20

hosneyalaa
Advisor
Advisor

Hi @albertluus2J23M 

 

Comment is PED

Message 8 of 20

qchenTPPXV
Collaborator
Collaborator

Thank you for sharing this. I have one question, Ithe file is loaded and I enter cogo but couldn't search for this commend. Any ideas for this? Thank you very much for your help!

0 Likes
Message 9 of 20

hippe013
Advisor
Advisor

The command name in the lisp that @Jeff_M posted is "PED".

0 Likes
Message 10 of 20

qchenTPPXV
Collaborator
Collaborator

Thanks. Do you know how to modify the result to round to 3 decimals. And delete the symbol after the number

qchenTPPXV_0-1713382095230.png

 

0 Likes
Message 11 of 20

hippe013
Advisor
Advisor

Yes. You can do it though.

 

Look for the following code:

(rtos diff 4)

And modify it to be this:

(rtos diff 2 3)

 

 

0 Likes
Message 12 of 20

qchenTPPXV
Collaborator
Collaborator
Thank you very much for getting back to me. When I change to code, I get 3 decimals but the result is not correct.
[cid:db046cd7-f935-4df2-bf33-7382aee95d65]
0 Likes
Message 13 of 20

hippe013
Advisor
Advisor
Accepted solution

It looks like he is multiplying the elevation difference by a factor of 12.

 

You can modify this block of code.

(setq diff (* 12 (- (last pt1) (last pt2)))
	  midpt (mapcar '(lambda (x y) (/ (+ x y) 2)) pt1 pt2);;for mleader inspt
	  inspt (getpoint midpt "...pick text insertion point: ")
	  mldrpts (list (car midpt)(cadr midpt) 0 (car inspt)(cadr inspt) 0)
	  ptlist (vlax-make-safearray vlax-vbdouble '(0 . 5))
          ptlist (vlax-safearray-fill ptlist mldrpts)
	  )

 

To be this:

(setq diff (- (last pt1) (last pt2))
	  midpt (mapcar '(lambda (x y) (/ (+ x y) 2)) pt1 pt2);;for mleader inspt
	  inspt (getpoint midpt "...pick text insertion point: ")
	  mldrpts (list (car midpt)(cadr midpt) 0 (car inspt)(cadr inspt) 0)
	  ptlist (vlax-make-safearray vlax-vbdouble '(0 . 5))
          ptlist (vlax-safearray-fill ptlist mldrpts)
	  )

 

Sorry, I should have caught that. 

 

Message 14 of 20

qchenTPPXV
Collaborator
Collaborator
Thank you so much. It works perfectly now.
0 Likes
Message 15 of 20

Andrey_Goretoy
Explorer
Explorer

this LISP routine works perfect (with noted corrections) - thank you  hippe013 !  I am not a LISP programmer, but a constant user.  Would be nice if this Mleader would automatically pick 1st picked point as a start and the last picked point as a text inset location, so it kind of visually points which 2 points involved in calculation of a result that is displayed in Mleader, for example - see the screen clip below.  As of now - Mleader draws start leader point as MIDPOINT between 2 picked points (upper yellow arrow in inset) , and if points are close to each other - this is ok and will be well understood, but if they are far apart and some other points are around - it might be confusing.

Arrow pointer below is what I mean as it would be clearly pointing between two selected points exact locations.

 

ELEV DIFFERENCE EXAPLE.jpg

 

Either way - this LISP routine is excellent!

0 Likes
Message 16 of 20

hippe013
Advisor
Advisor

@Andrey_Goretoy 

The credit should really go to @Jeff_M I just helped with modifications.

 

To have the arrow be the first point instead of the midpoint is an easy modification. 

 

Find this block of code, notice the midpt variable is being set to the mid between pt1 & pt2.

(setq diff (- (last pt1) (last pt2))
   midpt (mapcar '(lambda (x y) (/ (+ x y) 2)) pt1 pt2);;for mleader inspt
   inspt (getpoint midpt "...pick text insertion point: ")
   mldrpts (list (car midpt)(cadr midpt) 0 (car inspt)(cadr inspt) 0)
   ptlist (vlax-make-safearray vlax-vbdouble '(0 . 5))
   ptlist (vlax-safearray-fill ptlist mldrpts)
)

 

Remove the midpt assigning and replace its usage with pt1. 

(setq diff (- (last pt1) (last pt2))
   inspt (getpoint pt1 "...pick text insertion point: ")
   mldrpts (list (car pt1)(cadr pt1) 0 (car inspt)(cadr inspt) 0)
   ptlist (vlax-make-safearray vlax-vbdouble '(0 . 5))
   ptlist (vlax-safearray-fill ptlist mldrpts)
)

 

I will leave it to you to modify and test. 

Cheers! and Happy Coding!

 

0 Likes
Message 17 of 20

saqib_tipa
Advocate
Advocate

@Jeff_M

@hippe013 

Hello,

May you please modify this Lisp.

I want to subtract cogo point elevation from already existing 2-line Mtext. From 1st line it should take numeric value and subtract it from cogo point elevation and put it in 2nd line numeric values as replaced. (As in example picture).

 

If this is possible, I will be so thankful to you.

Thank you.

 

 

SS-18-7-2024 9.45.11 AM.png

 

0 Likes
Message 18 of 20

MPD_TECH
Explorer
Explorer

Hey!

 

Thanks so much for all this work really helped me get my work done fast. I was wondering as well how would I go about making this metric (meters) and can I include spot elevations in the pick points?  Thanks again

0 Likes
Message 19 of 20

hosneyalaa
Advisor
Advisor

@MPD_TECH 

Can you attached sample drawing 

0 Likes
Message 20 of 20

MPD_TECH
Explorer
Explorer

Yes for sure, here is a screen shot of what I mean, essentially I have a bunch of slopes that runs perpendicular and need to show the diff in elevations, I've been doing them by hand with leaders. 

0 Likes