June 20, 2013

Using AutoLISP Program to label point coordinate

10 Flares 10 Flares ×

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
; http://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!

10 Flares Twitter 0 Facebook 6 LinkedIn 0 Google+ 4 Email -- Email to a friend 10 Flares ×

Advertisement



You might also interested to

About Edwin Prakoso

Edwin works as an Application Engineer in Jakarta, Indonesia. He has 4 years experience in building industry, then start to work for Autodesk reseller.
He is certified as Revit Architecture 2010 certified professional and AutoCAD 2013 certified professional.
He loves sharing his experience and starts to blog on CAD notes. Now using CAD is more to a lifestyle for him than working.
You can reach him on twitter @CADnotes. You can also connect with him on LinkedIn. If you prefer email, reach him at edwin.prakoso@cad-notes.com.

  • Moataz Abbas

    i need this book i am from cairo egypt ?

  • Pingback: AutoLISP tutorial: using Lists and Strings | CAD Notes

  • Ahmed

    Thank You
    very simple
    and very powerful

  • T S Jamalon

    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

    • http://cad-notes.com Edwin Prakoso

      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.

  • T S Jamalon

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

    • http://cad-notes.com Edwin Prakoso

      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.

    • http://cad-notes.com Edwin Prakoso

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

  • Araza

    very good lisp lb,lbz

  • http://www.facebook.com/rameeshbinrazak.remi Rameeshbinrazak Remi

    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

    • http://cad-notes.com Edwin Prakoso

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

  • Pingback: AutoLISP program for labeling coordinate in AutoCAD | CAD Notes

  • saeed

    tanks

  • Italo Ramos

    Thank you!!