• 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 / Using AutoLISP Program to label point coordinate

Using AutoLISP Program to label point coordinate

November 25, 2010 by Edwin Prakoso 26 Comments

label

I have posted an AutoCAD tip how you can create your own label coordinate in AutoCAD using block attributes. It is nice that you can create your own block, create your own block shapes, and customize it to look anything you want to.

But there is a limitation. It will only recognize the point position from global coordinate. If you move the UCS, it will still use global coordinate. It makes sense, because if we want to label our coordinate, then usually we do use global coordinate. But what if you want to label the coordinate from UCS?

Because I’m currently learning AutoLISP, then I decided to take it as a challenge to create a program to do that. You can download the file in link you’ll find below this post.

How to use the program?

  1. Download the LISP file
  2. Load the LISP program. There are several ways to load AutoLISP program, but this is the easiest way.
  3. I wrote the code to run when I type LB then [enter]. You should be able to use it after you load the program.
  4. You need to click twice: the point you want to label and label location.
  5. It will use leader command. So if it’s too large, too small, or you want to customize it, change your style.
  6. It is also use file UNITS settings. If you want to change the format to decimal or architecture format, change it in UNITS settings.
  7. The program will continue to ask you for points until you press [esc] or [enter]. I decide to make it this way because mostly we want to create several labels at once. So you don’t need to reactivate it after you have labeled one point.

If you are following AutoLISP tutorial in CAD Notes, be patience! We will get there. Here is the code.

; Automatic coordinate labeling
; Edwin Prakoso
; https://www.cad-notes.com
;
; Limitation
; ----------
; Will use current leader style and current units setting

 

(defun c:lb (/ p x y ptcoord textloc)
(while
(setq p (getpoint "
Pick Point: "))
(setq textloc (getpoint "
Pick Label Location: "))
(setq x (rtos (car p)))
(setq y (rtos (cadr p)))
(setq z (rtos (caddr p)))
(setq ptcoord (strcat x ", " y ", " z))
(command "_LEADER" p textloc "" ptcoord "")
)
)

And if you want to simply download and use it, download this file. There are two files in the zip file.

  1. LB.lsp is for Labeling Coordinate (X and Y only)
  2. LBZ.lsp is for Labeling Coordinate (X, Y, and Z)

Enjoy the LISP, and share it to your friends!

Notes: After I wrote this, I realize that Shawki abo zeed have published similar code in labeling coordinate tips. It looks it has more features. If this one doesn’t work fine, you may want to try his code too. Thank you to Shawki!

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: AutoCAD, AutoLISP Tagged With: automatic coordinate label

2.3 3 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

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

26 Comments
Inline Feedbacks
View all comments
Antonio Gomes
Antonio Gomes
11 years ago

Hello
the routine described above, it is possible to change the text on the leader by verticall.
Thank you

0
Reply
Edwin Prakoso
Edwin Prakoso
Author
Reply to  Antonio Gomes
11 years ago

Antonio,

QLEADER only can be horizontal if we use MTEXT for the annotation. But it is possible if you use block.

0
Reply
Javier Mayol
Javier Mayol
11 years ago

For me this is a homerun!!, Very nice! Very useful !. I do have on question. Is there a posibility to make the cordinates come in in decimal feet (not deciaml inches). I have played with the units setting in AutoCAD as well as the Dimension style(s) and nothing worked for me. Any help would be highly appreciated.

0
Reply
Edwin Prakoso
Edwin Prakoso
Reply to  Javier Mayol
11 years ago

Hi Javier,

I'm glad you like it!
The value the code generate is following units settings in AutoCAD.
If you want to add feet symbol, you can set units to feet then tweak the code a little.
You can replace the 4th line from bottom with below to add feet symbol.

<code>(setq ptcoord (strcat x "'" ", " y "'" ", " z "'"))</code>

0
Reply
Javier Mayol
Javier Mayol
Reply to  Edwin Prakoso
11 years ago

My drawing units are: 1" = 1drawing unit, so my coordinates will always be in decimal inches.
So is there a way to divide the answer by 12 inside of the lisp so my answer will be in decimal feet?

0
Reply
Edwin Prakoso
Edwin Prakoso
Reply to  Javier Mayol
11 years ago

This is not perfect, but can do what you want:
https://skydrive.live.com/redir?resid=60CE1DE8DFF…

0
Reply
Javier Mayol
Javier Mayol
Reply to  Edwin Prakoso
11 years ago

It is perfect for me! It works great!!!
Thank you very much, you have a new fan :)

0
Reply
Italo Ramos
Italo Ramos
12 years ago

Thank you!!

0
Reply
saeed
saeed
12 years ago

tanks

0
Reply
Rameeshbinrazak Remi
Rameeshbinrazak Remi
12 years ago

Iam rameesh dear friends i have a doubt in auto cad when i open tha new file in cad its zooming is very slovly if i reset the setings its ok how i can solve this problem

0
Reply
Edwin Prakoso
Edwin Prakoso
Reply to  Rameeshbinrazak Remi
12 years ago

Hi Rameesh,
What did you do to reset settings? And what did you change that can cause the zoom tool become slow?

0
Reply
Araza
Araza
13 years ago

very good lisp lb,lbz

0
Reply
T S Jamalon
T S Jamalon
13 years ago

Back to "coordinate labels". As suggested by you,  I cannot find transparent background in text style. Now what is the solution?

0
Reply
Edwin Prakoso
Edwin Prakoso
Reply to  T S Jamalon
13 years ago

Strange. My text style doesn't have any background. So it's pretty much like you expected. What is your font? Can you send part of your drawing to my email address? I just need to see your current text style and font.

0
Reply
Edwin Prakoso
Edwin Prakoso
Reply to  T S Jamalon
13 years ago

 Apparently it's something dimension style controls. In dimension style dialog, text tab, change fill color to None.

0
Reply
T S Jamalon
T S Jamalon
13 years ago

Your program for "coordinate labels" filled a long felt vacuum in my meagre knowledge bank.  
Is it possible to do a small change?  I find that the label comes on an opaque(black background) and covers the part of the drawing where the label is. Is it possible to make the background transparent so that the part of the drawing under the label will be visible. 

Your site has cured many a headache.  Many thanks

0
Reply
Edwin Prakoso
Edwin Prakoso
Reply to  T S Jamalon
13 years ago

Hi there.

It depends on text style you use. I don't have AutoCAD open right now, check if you can make your text style has transparent background.

0
Reply
alim
alim
Reply to  Edwin Prakoso
8 years ago

hi sir i want whiteout decimal and text size bigger please help me

0
Reply
Edwin Prakoso
Edwin Prakoso
Author
Reply to  alim
7 years ago

Hi Alim,
The text format follows the drawing units settings. And the text size follows the style settings. You can change those settings to get what you want.

0
Reply
Ahmed
Ahmed
14 years ago

Thank You

very simple

and very powerful

0
Reply
Moataz Abbas
Moataz Abbas
14 years ago

i need this book i am from cairo egypt ?

0
Reply
1 2 Next »
wpdiscuz   wpDiscuz

Featured

Free e-book: Working with AutoCAD Annotation Scaling

To celebrate CADnotes 8th anniversary, we provide this e-book for all readers. It is free. It covers how Annotation Scaling works and how to use it. We hope you will like it!

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