Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help modifying this Lisp.

17 REPLIES 17
Reply
Message 1 of 18
mark
749 Views, 17 Replies

Help modifying this Lisp.

Hi guys,

 

Id like some help modifying the attached labelling lisp. I use it to label conoutrs (polylines) with their elevations. Currently it works fine however id like it to put the text on the contour rather than offset above it, and also take the alignment of the polyline (where i click on the polyline) rather than having to click a second time for the label alignment. A option for text height would also be awesome. 

 

Thanks in advance.

Alex

17 REPLIES 17
Message 2 of 18
braudpat
in reply to: mark

 

Hello Alex

 

Please post here :

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/bd-p/130

 

Regards, Patrice (I am not an Autodesk Advisor)

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 3 of 18
Kent1Cooper
in reply to: mark

You may be able to combine that with elements of this routine, by either taking its way of determining the rotation and putting it into yours, or taking the determining of the text content from yours and putting it into LabelTextMask.lsp.

Kent Cooper, AIA
Message 4 of 18
Balaji_Ram
in reply to: mark

Hi Mark,

 

Kent's Lisp code has all that is needed to implement what you mentioned. 

Here is a bare-bone implementation that can help you understand the approach with option to set text height.

 

http://adndevblog.typepad.com/autocad/2015/04/aligning-mtext-with-picked-point-on-a-curve.html

 

Regards,

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

Message 5 of 18
mark
in reply to: Balaji_Ram

Okay so ive tried modifying it myself but no go. Basically id really appreciate if someone could customise Kents code to do this contour labelling workflow in this order:

 

- Prompt for text height

- Prompt for elevation value (getreal)

- Ask to pick where i want to place the labels (with ability to click on multiple points to label contours with same elevation)

- Enter to get back to the "Enter elevation" prompt

 

I like kents code as it oncorporates a mask background instead of the polyline background of my old routine. His code for setting the angle also doesnt seem to have the problem that my old routine had in that with some files it gets confused with the rotation and doesnt align it properly.

 

Thanks in advance

Alex

Message 6 of 18
Kent1Cooper
in reply to: mark


@mark wrote:

Okay so ive tried modifying it myself but no go. Basically id really appreciate if someone could customise Kents code to do this contour labelling workflow in this order:

 

- Prompt for text height

- Prompt for elevation value (getreal)

- Ask to pick where i want to place the labels (with ability to click on multiple points to label contours with same elevation)

- Enter to get back to the "Enter elevation" prompt

....


Are your contours drawn at their actual elevation in 3D?  If so, try this modification of the routine in the earlier link.  The LEM command in LabelElevMask.lsp has a height option to take care of your first step, and once the height is set, you don't need to answer a prompt for it every time.  It finds the elevation of the selected object for you, so you don't need to tell it what the text content should be [second step], and therefore don't need an option to enter a new elevation [fourth step].  And you can label as many as you want in one running of the command [third step].  [It also has a width factor option, because that was part of what the originator of that thread wanted, and Style and Layer options for the labels.]  Look for the "<--EDIT as desired" and similar indications, to set up your typical defaults.

 

[I thought I had worked up something like that, but it's not on the Cadalyst CAD Tips site, and it was easier to find the other one there than to Search here, which is why the earlier link was to there rather than to wherever it is here.  Your workflow list spurred me to do the Search here for the elevation-specific version.]

Kent Cooper, AIA
Message 7 of 18
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:
....

Are your contours drawn at their actual elevation in 3D?  If so, try this modification of the routine in the earlier link.  The LEM command in LabelElevMask.lsp ....


So I looked through that, and found it was still using (command) for Undo End in the error handler, which is a no-no in Acad2015+.  Here's an updated version [with a few other little tweaks] that should be good in any version.

Kent Cooper, AIA
Message 8 of 18
mark
in reply to: Kent1Cooper

Thanks for that Kent, however im now getting an error when i run the LEM command;

 

Error: bad argument type: numberp: nil

 

Any idea why? Im running Civil 3D 2016. Also how do I invoke the option to use the elevation of the polyline?

 

Thanks

Alex

Message 9 of 18
Kent1Cooper
in reply to: mark


@mark wrote:

Thanks for that Kent, however im now getting an error when i run the LEM command;

 

Error: bad argument type: numberp: nil

 

Any idea why? Im running Civil 3D 2016. Also how do I invoke the option to use the elevation of the polyline?

....


You probably haven't yet gone through and followed the instructions to EDIT various things for your initial defaults [see the advisory at the end of the longer paragraph in Post 6].  That error could be because you left it calling for ROMANS as a text Style [not the font, but a Style name to which, in our usual setup, that font happens to be assigned], but you don't have a Style defined in your drawing by that name.

Kent Cooper, AIA
Message 10 of 18
Kent1Cooper
in reply to: mark


@mark wrote:

.... Also how do I invoke the option to use the elevation of the polyline?

....


Forgot to address that part in my previous Reply....

 

There's no option for that -- LEM always and only uses the elevation of the selected object for the text content [the elevation at the point of selection, if it varies].

Kent Cooper, AIA
Message 11 of 18
mark
in reply to: Kent1Cooper

Thanks Kent, its working nicely now. 

 

Alex

Message 12 of 18
mark
in reply to: mark

Kent,  just a quick question. can the lisp be modified to drop the trailing zeros from the label?

 

Alex

Message 13 of 18
Kent1Cooper
in reply to: mark


@mark wrote:

Kent,  just a quick question. can the lisp be modified to drop the trailing zeros from the label?

....


Trailing zeros after a decimal point?  It shouldn't be supplying any of those, unless you've changed this:

....

          elevtxt (rtos (caddr inspt) 2 0);; <-- EDIT mode/precision as desired
            ; [mode 2 & precision 0 round to nearest integer, typical of use with contour lines]

....

to some value other than zero.

Kent Cooper, AIA
Message 14 of 18
mark
in reply to: Kent1Cooper

I have contours ranging from full meter intervals down to 1/8m intervals, but id like the labels to display as this to save space;

 

68

68.5

68.25

68.125

 

Is that possible to do?

 

Thanks

Alex

Message 15 of 18
Kent1Cooper
in reply to: mark


@mark wrote:

I have contours ranging from full meter intervals down to 1/8m intervals, but id like the labels to display as this to save space;

 

68

68.5

68.25

68.125

....


(vl-string-right-trim ".0" "YourString")

will take off all trailing zeros and decimals.  BUT if you use it on something like "60.0000", it will turn that into just "6".  So:

 

(if (= (rem (atof "YourString") 10.0) 0); it's a whole multiple of 10 [keep any zero(s) before the decimal]

  (itoa (atoi "YourString")); then

  (vl-string-right-trim ".0" "YourString"); else

); if

Kent Cooper, AIA
Message 16 of 18
mark
in reply to: Kent1Cooper

I really appreciate your help Kent, but i have no idea where to put that code in to make it work. As i said, i have no coding experience at all, im just an end user. 

 

Alex

 

 

Message 17 of 18
Kent1Cooper
in reply to: mark


@mark wrote:

.... i have no idea where to put that code in to make it work. ....


Try this adjustment -- LabelElevMask2.lsp but using the same LEM command name [lightly tested].  You will still need to EDIT certain things for your preferences [Text Style name, etc.].

Kent Cooper, AIA
Message 18 of 18
mark
in reply to: Kent1Cooper

You are an absolute legend Kent. Thanks, works perfectly. Smiley Happy

 

Many many thanks again. 

 

Alex

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

Post to forums  

Autodesk Design & Make Report

”Boost