• Home
  • Training Books
  • Subscribe to Our Email Newsletter
  • About
    • Contributors
    • Feedback
    • Contact
    • Privacy policy
    • Cookie Policy

CADnotes

CAD Tutorials and Best Practices for professionals and students

  • Featured
  • AutoCAD
    • AutoLISP
  • Revit
    • Revit Architecture Basic
    • Revit MEP Basic Tutorial
  • Inventor
  • MicroStation
    • MicroStation Basic Tutorial
You are here: Home / AutoCAD / AutoLISP / AutoLISP: Adding New Line in Multiline text

AutoLISP: Adding New Line in Multiline text

March 11, 2011 by Edwin Prakoso 3 Comments

We created an AutoLISP program to create leader to label coordinate before. It will be very useful for surveyors who use vanilla AutoCAD. But you may want to use multileader instead of leader in your AutoLISP program. MLEADER is neat, and you can have more control and flexibility with it.

The problem is it uses multiline text, not single line text in leader. When working with multiline text, we press [enter] when we want to add another text line. But using “” in AutoLISP to simulate pressing enter, it will not work. When we use “” AutoCAD thinks we want to end the command. But not adding new line.

enter

I posted a reply in the comment section, but just in case you miss it I write it as a post. To solve this, we need to use ANSI character to add a new line. chr 10 will add new line (or line feed) to our variable.

Let’s take an example. We add that character to our string variable:

(setq ptcoordN (strcat "N=" y))
(setq ptcoordE (strcat "E=" x))
(setq ptcoordN (strcat ptcoordN (chr 10) ptcoordE))

The first and second line will get x and y value, then add prefix. The 3rd line will combine them both. That AutoLISP code will combine N coordinate, new line, then place E coordinate there.

The complete AutoLISP code will be:
(defun c:cnlabel (/ p x y ptcoordN ptcoordE textloc oldprec)
(setq oldprec (getvar "LUPREC"))
(setvar "LUPREC" 4)
(while ; start while loop
(setq p (getpoint "
Pick Point to Label:")) ; asking user to click point to label and save it
(setq textloc (getpoint p "
Pick Text Location:")) ;asking user to click text location
(setq x (rtos (car p)))
(setq y (rtos (cadr p)))
(setq ptcoordN (strcat "N=" y))
(setq ptcoordE (strcat "E=" x))
(setq ptcoordN (strcat ptcoordN (chr 10) ptcoordE))
(command "mleader" p textloc ptcoordN) ;ativate label command and use the input
(setvar "LUPREC" oldprec)
(princ)
)
)

I don’t know if there is other solution for this. If you know the other way, please share it here!

Share the knowledge:

About Edwin Prakoso

I work as a Sr. Consultant in PT Cipta Satria Informatika. I've been using AutoCAD since R14 and Revit since Revit Building 9. I occasionally write for AUGIWorld magazine and I am also active in Autodesk discussion forum. I'm a member of Autodesk Expert Elite, an appreciation for individuals who give contributions to the Autodesk community.
Connect with me on twitter or LinkedIn.

Filed Under: AutoLISP Tagged With: ansi character, autolisp, new line

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

3 Comments
Bernard Sales
Bernard Sales
11 years ago

dear Edwin
i have decided to use the MULTILINE comand to draw wall lines ( i am an architect) the autocad setup allows you to set line spacing, colour, all on one layer,,, is there any way to do this with lines on specific layers,
any help would be apprecited, Bernie

0
Reply
Edwin Prakoso
Edwin Prakoso
Author
Reply to  Bernard Sales
11 years ago

Bernie,

You can’t have a line like that. You need to override the line properties. Or you can create a line with custom properties, then drag it to tool palettes so you can use it later easily.

0
Reply
Erik
Erik
Reply to  Bernard Sales
11 years ago

just use ‘txt2mtxt’ to change a single line text item to multiline text.

0
Reply
wpdiscuz   wpDiscuz

Featured

Revit extensions: Must have tools for Revit productivity

Do you use Revit extensions? There are so many tools available to extend your Revit capabilities, to increase your productivity. If you haven’t used it, then you should try it now!

Recent Articles

  • AI Is an Assistant, Not a Replacement
  • Open Large Revit Models Faster: Incremental Model Open
  • 10 AutoCAD Commands Only Veterans Know

Advertisement

New on CADnotes

  • AI Is an Assistant, Not a Replacement
  • Open Large Revit Models Faster: Incremental Model Open
  • 10 AutoCAD Commands Only Veterans Know
  • Is Your Revit Model Healthy?
  • Older Revit Will Lose Access to Cloud Models

Tags

360 annotation scaling AutoCAD autocad 3D AutoCAD 2011 AutoCAD 2012 AutoCAD 2013 AutoCAD 2014 AutoCAD 2015 AutoCAD 2016 AutoCAD Basic Series autocad tips AutoCAD troubleshoots AutoCAD WS Autodesk 360 autolisp block command line cui cui tutorial customization dimension dimension styles DWG dynamic block dynamic block tutorial Hatch hotfix layer macro MicroStation Basic MicroStation Tips rendering material Revit 2023 Revit Architecture Basic Revit MEP Basic Revit what's new service pack system variable template tool palettes view viewport WBWA2014 xref

Sharing is Caring

© 2009 – 2026 CADnotes · Feedback · Privacy Policy · Become an affiliate

wpDiscuz