• 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!

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
Inline Feedbacks
View all comments
Bernard Sales
Bernard Sales
10 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
10 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
10 years ago

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

0
Reply
wpdiscuz   wpDiscuz

Featured

best training

The Best, the Rest, the Rare: 100 AutoCAD Tips You Should Know

A compilation of AutoCAD tips. Read all 100 of them to increase your productivity!

Recent Articles

  • Autodesk Construction Cloud Activity Log
  • Exporting AutoCAD Plant 3D Model to Navisworks
  • Autodesk Data Connector for Power BI is Now Available

Advertisement

New on CADnotes

  • Autodesk Construction Cloud Activity Log
  • Exporting AutoCAD Plant 3D Model to Navisworks
  • Autodesk Data Connector for Power BI is Now Available
  • Autodesk Forma Design Contest
  • Revit 2025: Toposolid Enhancements

Meet the Authors

avatar for
avatar for
avatar for
avatar for
avatar for
avatar for

Get Connected

CADnotes on FacebookCADnotes on InstagramCADnotes on TwitterCADnotes on YouTube

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

wpDiscuz