Visual LISP, AutoLISP and General Customization

## Visual LISP, AutoLISP and General Customization

Distinguished Contributor
Posts: 155
Registered: ‎02-10-2004
Message 1 of 10 (358 Views)

# Measure Vertical distance...........

358 Views, 9 Replies
02-22-2013 06:19 AM

Hi,

I need to extract a list of chainage (horiz measurement) coupled with the vertical distance between two selected polylines. The chainage would be user input and the vertical distance would be calculated as a distance measured from Line 'A' to Line 'B' and positve or negative to indicate if Line 'B' is above/below Line 'A' at that chainage.

Can someone point me to a lisp that can do this or perhaps get me started with the right approach.

Thanks in advance

Regards

Sean

Please use plain text.
Valued Mentor
Posts: 355
Registered: ‎04-11-2010
Message 2 of 10 (355 Views)

# Re: Measure Vertical distance...........

02-22-2013 06:36 AM in reply to: sean.keohane

Hi,

Can you post a dwg or picture with the geometry and references of the problem?

Gaston Nunez

Please use plain text.
*Expert Elite*
Posts: 4,804
Registered: ‎09-13-2004
Message 3 of 10 (343 Views)

# Re: Measure Vertical distance...........

02-22-2013 06:46 AM in reply to: sean.keohane

sean.keohane wrote:

Hi,

I need to extract a list of chainage (horiz measurement) coupled with the vertical distance between two selected polylines. The chainage would be user input and the vertical distance would be calculated as a distance measured from Line 'A' to Line 'B' and positve or negative to indicate if Line 'B' is above/below Line 'A' at that chainage.

....

I don't work with chainage, but if the User-input chainage number is the same distance along both Polylines [which I will assume are running in the same direction], then you should be able to do something like [in simplest terms, without selection controls or error handling, in the World Coordinate System, etc.] this:

(defun CeltaZatChain (/ plA plB chain)

(setq

plA (car (entsel "\nSelect Polyline A: "))

plB (car (entsel "\nSelect Polyline B: "))

chain (getdist "\nChainage for vertical comparison: ")

deltaZ

(-

(caddr (vlax-curve-getPointAtDist plB chain)); Z component

(caddr (vlax-curve-getPointAtDist plA chain)); Z component

); - & deltaZ

); setq

(prompt

(strcat

"\nPolyline B is "

(rtos (abs deltaZ))

(if (minusp deltaZ) " below" " above")

" Polyline A."

); strcat

); prompt

); defun

The difference will be in the deltaZ variable, positive if B is above A at that distance along, negative if it's below.  If the chainage could be different along the two Polylines, it's an easy adjustment to account for two chainage values.  The same concept can be expanded to take a list of chainage values and return a list of deltaZ values, but first see whether the above is the right general idea for a single chainage value.  And it could be adjusted to report differently if they're at the same elevation.

Kent Cooper
Please use plain text.
Distinguished Contributor
Posts: 155
Registered: ‎02-10-2004
Message 4 of 10 (341 Views)

# Re: Measure Vertical distance...........

02-22-2013 06:47 AM in reply to: gasty1001

Thank you for replying. I have attachaed a dwg file with a sample of what I need.

Please use plain text.
*Expert Elite*
Posts: 4,804
Registered: ‎09-13-2004
Message 5 of 10 (336 Views)

# Re: Measure Vertical distance...........

02-22-2013 07:02 AM in reply to: sean.keohane

sean.keohane wrote:

Thank you for replying. I have attachaed a dwg file with a sample of what I need.

Ah....  My first suggestion won't do what you want.  The situation in the sample drawing is more complicated, because the chainage increments are not based on distances along the Polylines, but on equal spacings in the X direction [in this kind of view of the two Polylines -- I was picturing something in plan view, but this looks like an elevation/section view].

I'm sure it can be done, but it will probably require temporarily drawing Lines, or moving one along at the chainage increment, and using the VLA intersect-with method to find the locations along the two Polylines.  That's more than I can work out right now, but I may come back if someone doesn't beat me to it.

Kent Cooper
Please use plain text.
Distinguished Contributor
Posts: 155
Registered: ‎02-10-2004
Message 6 of 10 (333 Views)

# Re: Measure Vertical distance...........

02-22-2013 07:07 AM in reply to: Kent1Cooper

Thank you Kent for your reply,

I tested your code on the drawing I've attached earlier and it reports line B is above line A by 0.0000 at any given chainage. I need to end up with a text file showing the horiz distances and the positive/negative vertical distance values.

Does your code measure horiz or along the polyline? How would the list I need be compiled?

I appreciate your help,

Regards

Sean

Please use plain text.
*Expert Elite*
Posts: 4,804
Registered: ‎09-13-2004
Message 7 of 10 (321 Views)

# Re: Measure Vertical distance...........

02-22-2013 09:08 AM in reply to: sean.keohane

sean.keohane wrote:

Thank you Kent for your reply,

I tested your code on the drawing I've attached earlier and it reports line B is above line A by 0.0000 at any given chainage. I need to end up with a text file showing the horiz distances and the positive/negative vertical distance values.

Does your code measure horiz or along the polyline? How would the list I need be compiled?

....

It measures along the Polylines, based on my misunderstanding of your original description, and more to the point, it was written assuming something like a model-of-reality setup using 3D Polyline routes that are at varying elevation, viewed in plan, rather than the section/elevation view of your sample drawing.  That's why it reports 0 at any chainage distance in your sample -- those two Polylines are both flat, and at the same elevation if the viewed direction represented a plan.

But seeing your sample drawing configuration, I did manage to work something out that I think does what you're really after, including making the text file.  I tested it only a little, but it seems to work.  See the NOTEs in it, and the comments about editing various things to suit your circumstances.

It could also be made to test whether the User selected the right kind of object for both Polylines, and ask again if they didn't, and/or to save the designated chainage increment and offer it as a default on subsequent use, and/or probably some other enhancements.

Kent Cooper
Please use plain text.
Distinguished Contributor
Posts: 155
Registered: ‎02-10-2004
Message 8 of 10 (278 Views)

# Re: Measure Vertical distance...........

02-25-2013 12:01 AM in reply to: Kent1Cooper

Hi Kent,

Thank you for taking the time to help me. I'm getting the following error report

question - assignment to protected symbol: REPORT enter break loop y/n (this is a dialogue box)
I tried yes and no with same result
; User warning: assignment to protected symbol: REPORT <- #<file
"C:/TEMP/DECreport.txt">

The file was created but was empty.

I guess, since it works for you, its something to do with my Autocad.

Any idea what might be causing this error?

Thanks again for your time and effort,

Regards

Sean

Please use plain text.
*Expert Elite*
Posts: 4,804
Registered: ‎09-13-2004
Message 9 of 10 (265 Views)

# Re: Measure Vertical distance...........

02-25-2013 05:30 AM in reply to: sean.keohane

sean.keohane wrote:

....

I'm getting the following error report

question - assignment to protected symbol: REPORT enter break loop y/n (this is a dialogue box)
I tried yes and no with same result
; User warning: assignment to protected symbol: REPORT <- #<file
"C:/TEMP/DECreport.txt">

The file was created but was empty.

I guess, since it works for you, its something to do with my Autocad.

....

I assume the "protected symbol" language means that in some later version of AutoCAD than mine, 'report' must come to have a special meaning in AutoLISP, as for example 'T' [true] does, and it won't let you use that as a variable name.  Try changing the 'report' name of the variable, to anything else -- just 'r', or 'decireport', or whatever.  Make sure you change it everywhere it occurs [except where it's part of the longer file name].

Kent Cooper
Please use plain text.
Distinguished Contributor
Posts: 155
Registered: ‎02-10-2004
Message 10 of 10 (260 Views)

# Re: Measure Vertical distance...........

02-25-2013 06:06 AM in reply to: sean.keohane

Hi Kent,

WOW. That was it. It does exactly what I need. Thank you for spending time to help me out.

Regards

Sean

Please use plain text.

### You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

### Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Recently Solved

• ## Is it possible to populate an existing XLS sheet

### Browse Forums

AutoCAD Customization