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

Lisp to display bearing and distance between two points

21 REPLIES 21
Reply
Message 1 of 22
Anonymous
6833 Views, 21 Replies

Lisp to display bearing and distance between two points

Hi

 

I have written a Lisp (shown below) that currently functions, and displays a distance between two points picked off of the screen, written in code as 'x1' and 'x2', and then applies a scale factor. I currently have to draw a line between two points, and select the line, and read the angle in the properties taskbar. I would like to be able to add a function to the lisp routine that in addition to displaying the distance, would also display a bearing (where the angle is measured from 'x1', North being 0°, and then in a clockwise direction to 'x2') in the command line. Any help would be greatly appreciated.

 

Thanks

 

Ahmed

 

 

 

 

(defun c:DM ()
(setq TD 0)
(setq x1 (getpoint "\nSelect First Point: "))
(setq x2 (getpoint x1 "\nSelect Second Point: "))
(prompt
(strcat
(rtos (distance x1 x2))
(rtos (setq TD (+ TD (/(distance x1 x2) 0.999848))))
)
)
(prompt (strcat "\nTotal Distance = " (rtos TD)))
(princ)
)

 

 

 

Thanks again

21 REPLIES 21
Message 2 of 22
MMcCall402
in reply to: Anonymous

Try this tool to get a label between two points.  It says 'add line' but it really just adds a label between two selected locations on the screen.  You can re-select the label and you'll get prepositional grips at the two points and another at the label location. 

 

 

image.png

Mark Mccall 
CAD Mangler



Hammer Land Engineering


Linkedin

Message 3 of 22
Anonymous
in reply to: Anonymous

I forgot to mention, ideally, the bearing that will be displayed would show up in the command line as Degrees Minutes Seconds (73°54'33").

 

if there are any questions, please let me know.

 

Thanks

Message 4 of 22
Anonymous
in reply to: MMcCall402

Thanks for the suggestion. for the purpose of my work, I am required to dimension between points. The suggested function would require me to break up every line at every point.

Message 5 of 22
CodeDing
in reply to: Anonymous

surveyscad2018,

 

Try this Command >> CGLIST <<< (presuming you are using Civil 3D). Use "P" for "Points".

 

Should be what you're looking for. You can also Code it with LISP. Something like..

 

Best,

~DD

 

(defun c:MyCGList ()

(setq x1 (getpoint))
(setq x2 (getpoint))
(command "CGLIST" "p" x1 x2 "")

(PRINC) );defun

Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 6 of 22
Anonymous
in reply to: CodeDing

Thank you

 

this command closer suits my needs, but unfortunately, using this command removes my ability to apply a custom scale factor/ do you know of a way to possibly combine mine and yours? additionally, can I have the CGList command display the bearing without direction? (so N56° 15' 48"W would be 303° 44' 12")?

 

Thanks

Message 7 of 22
jmayo-EE
in reply to: Anonymous

C3D can do this OOTB.

 

Use the Label Line Between Points command (type AddLabels and set Line and Curve current, the Line Between Points as the line label style.) with a label set up to your liking. This style can automatically draw the line and label the inverse.

 

After you make the style use the AliasEditor to make a one or two key command for AddLineBetweenPoints.

 

 

John Mayo

EESignature

Message 8 of 22
ChrisRS
in reply to: Anonymous

Please look at the suggestion from @MMcCall402 again. @jmayo-EE also gave this tip and more detail.

 

The "Add Line Between Two Point Label" is poorly named. It would be more clear if named "Add Line Label between Two Points"

 

The required input is a start point and an end point, not a line. In fact there does not even need to be a line between the points. You would not need to break up lines.

 

Here is a clip from the command line window:

     Command: _AeccAddLineBetweenPoints
     Adds label at midpoint between two points.
     Start point:
     End point:

 

 

You can apply whatever line label style you prefer to the resulting "Line Between 2 Points Label" object. 

 

This is pretty handy. Here are some examples:

 line between 2 points label.PNG

 

 

 

 

 

Christopher Stevens
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 9 of 22
KMercier_C3D
in reply to: ChrisRS

As one further note to those above, you can change the Measurement type to North Azimuth instead of Bearings if you prefer. 

 

image.png



Kati Mercier, P.E. | LinkedIn | AutoCAD Civil 3D Certified Professional
Pronouns: She/Her
Co-author of "Mastering AutoCAD Civil 3D 2013"
AU2019 Speaker::: CES321590: Analyze and Revise Existing Subassembly Composer PKT Files for AutoCAD Civil 3D
AU2017 Speaker::: CI125544: Analyze and Devise in Subassembly Composer
AU2012 Speaker::: CI3001: Reverse Engineering with Subassembly Composer for AutoCAD Civil 3D
AU2011 Speaker::: CI4252: Create Subassemblies That Think Outside the Box With Subassembly Composer for AutoCAD® Civil 3D®

Message 10 of 22
Anonymous
in reply to: KMercier_C3D

thanks everybody. these are all great suggestions. the problem remains though; I need to be able to apply a scale factor to the distances. in using the line labels, not only would I be adding dimensions that are not required to a drawing, I would have to individually calculate the distance with the scale factor for every dimension. with that said, it would still be easier for me to use my initial lisp, and select each line individually to see the bearings.

 

additionally, not everybody I work with has C3D, so a lisp routine would provide me with not only the most versatile tool, but the most efficient tool as well.

 

Thanks

Message 11 of 22
AllenJessup
in reply to: Anonymous

This may give you some clues.

 

(prompt"\nList bearings and distances by S. Crowell")
(defun c:inv ()
(setq osnp (getvar "OSMODE"))
(Command "OSNAP" "END,INTERSECTION" )
(setq fromp (getpoint "\nSelect Start point: "))
(setq nextp (getpoint "\nSelect Next point: "))
;(command "line" fromp nextp "") 		;Remove semicolon at beginning of this line to draw lines
;(command "point" fromp) 			;Remove semicolon at beginning of this line to draw points
;(command "point" nextp)			;Remove semicolon at beginning of this line to draw points
(princ "\nAngle is: ")
(princ (angtos (angle fromp nextp) 4 4))
(setq ang (angtos (angle fromp nextp) 4 4))
(princ "\nDistance is: ")
(princ (distance fromp nextp))
(while
(setq newp (getpoint "\nSelect Next point: Enter to quit: "))
;(command "line" nextp newp "")			;Remove semicolon at beginning of this line to draw lines
;(command "point" NEWP)				;Remove semicolon at beginning of this line to draw points
(princ "\nAngle is: ")				
(princ (angtos (angle nextp newp) 4 4))
(princ "\nDistance is: ")
(princ (distance nextp newp))
(setq nextp newp))
(setvar "OSMODE" osnp)
(prin1)
)

Allen Jessup
CAD Manager - Designer
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 12 of 22
jmayo-EE
in reply to: Anonymous

What kind of scale factor are you talking about? A unit conversion or a dwg scale? Is the scale factor constant or variable?

John Mayo

EESignature

Message 13 of 22
Anonymous
in reply to: jmayo-EE

the short answer, consider it a conversion, and it is constant (per drawing).

 

the long answer is as follows. this lisp is intended for checking plans of Survey. so the scale factor is either calculated, or provided to us through geodetic databases, and usually works out to be roughly 0.9996 (though normally held to six decimals). though this may seem minimal, over large distances, the discrepancy grows, and miscalculation can lead to a propagation of that error. the combined scale factor (CSF) is used to scale the distance between two points; to convert the measurements from Grid to Ground distances. the CSF changes based on where the location of the survey is. when required, I manually edit CSF in the lisp, and store that lisp routine with the corresponding drawing.

 

 

Message 14 of 22
jmayo-EE
in reply to: Anonymous

OK so grid to ground. Mostly one scale factor per dwg.

 

C3D can still do this.

 

Make an expression called scale factor that is your most common conversion factor. This can be changed in any dwg and at any time in the work process to meet your needs.

 

Use this expression in a second to compute the scaled distance and use this in the label.

John Mayo

EESignature

Message 15 of 22
ChrisRS
in reply to: jmayo-EE

I had the same thought.

 

This will work if you have an actual line or line segment to label (Civil 3d does both), but not using the Add Line Between Two Points Label, (See: Add Label Line Between 2 Points can't resolve an expression. As of October: This is a known issue. No workaround.) Illustrations follow below.

 

It is unfortunate that the Add Line Between Two Points Label does not work. I think that if you use a separate layer for checking to place these labels and any necessary intermediate lines, the existing line label will work. You could put intermediate lines on a non-plot layer. These label can be exploded to block if you need to share with no-Civil 3D users.

 

You might want to consider and alternate workflow. (Just a suggestion - only you know all of your needs)
If you can do you checking in a separate drawing: Start a new drawing, xref the subject drawing applying the scale factor to X and Y. You can use the Add Line Between Two Points Label to show the scaled distances.   

 

I'm pretty sure that there is an AutoCAD Only solution using a tricky dynamic block that includes fields. Tip: In a field, the angle of a line can be formatted as survey units, resulting in a bearing.

 

 

 

SCALE FACTOP EXPRESSION:

Line 2 point scale factor expression.PNG

 

SCALED DISTANCE EXPRESSION:

Line 2 point scaled distance expression.PNG

 

USING EXPRESSIONS IN THE STYLE:

 

Line 2 point style.PNG

 

SAMPLES:

Line 2 point sample.PNG


 

 

Christopher Stevens
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 16 of 22
Anonymous
in reply to: ChrisRS

Thanks. the expressions are a good idea, but unfortunetaly not everyone in my office will have the ability to use that tool. we have people who do not use C3D (plain AutoCAD, MicroSurvey Cad, etc), so a lisp remains the best option. additionally, the expressions seem to be like quite a bit of work and training is involved, whereas a lisp already exists to calculate the new distance.

Message 17 of 22
_Hathaway
in reply to: Anonymous

While every office is different and has different workflows I would ask why your surveyor is providing grid data when you want ground data or vice versa.  We deal with this daily and always work with ground units when in Cad.

Message 18 of 22
Anonymous
in reply to: _Hathaway

the data given to us is initially gathered through GPS RTK systems. additionally, when producing a survey plan, we are trying to show a 3d surface on a 2d paper. with that said, converting from grid to ground allows us to account for curvature of the earth, while staying in a fixed coordinate system (UTM, 3TM, 10TM, etc.).

 

if we were to pretend this was as simple as measing between points on an imperial drawing, and wanted it to be metric, say feet to meters), I would amend my lisp to show 0.3048 as my scale factor. this would allow me to get metric distances without changing the scale of the drawing, or positions of the coordinates/points. all I need in addition to that would be a way to display a bearing between the two points in the command line.

 

hopefully this explanation clears things up.

Message 19 of 22
_Hathaway
in reply to: Anonymous

I understand the concepts and work with them daily.  Our difference is that we work with ground coordinates.  It makes things significantly easier due to numerous reasons.  Yours is a prime example.

Message 20 of 22
MMcCall402
in reply to: _Hathaway

(Bear in mind that I'm out of my element in the grid to ground area)

 

I see in the label composer for a line label that there is a selection for Segment Length and Segment Grid Length.    Not sure if this is useful.

Mark Mccall 
CAD Mangler



Hammer Land Engineering


Linkedin

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

Post to forums  

Rail Community


Autodesk Design & Make Report