Jump to content

How to create a lisp program displaying coordinates


Recommended Posts

Posted

Hi Guys,

 

I'm fairly new to this 'lisp' program. I'm a trainee setting out engineer and have a question.

 

How do I display both eastings and northings coordinates on one line?

My senior engineer has it on his Auto CAD but got it done from somebody else and he doesn't know how to do it.

 

See Image - Shows coordinates X and Y

 

cadlisp.jpg

 

This is how it should be - Please note I typed them coordinates in myself

 

cad_xy.jpg

 

Any help would be greatly appreciated

 

Taj.

  • Replies 49
  • Created
  • Last Reply

Top Posters In This Topic

  • bharthts01

    24

  • Lee Mac

    11

  • MSasu

    7

  • Tiger

    3

Posted

I believe you should provide more details on your issue. Are you looking to modify an existing routine? Then you should post at least an excerpt from it – the part that manages those coordinates insertion.

Basically, those coordinates should be strings, so the function you were looking for is STRCAT.

Posted
I believe you should provide more details on your issue. Are you looking to modify an existing routine? Then you should post at least an excerpt from it – the part that manages those coordinates insertion.

Basically, those coordinates should be strings, so the function you were looking for is STRCAT.

 

This is how I get coordinates, dimensions > ordinates. This displays the eastings and northings of the point.

 

cadlisp.jpg

 

This looks very messy to me, all I want to know is how do I make it so instead of it displaying it like above, which looks very messy and can get quite confusing.

 

cad_xy.jpg

 

Does that make sense? Sorry, not very good on CAD

Posted

To display coordinates like that you are most likely using a Lisp of some sort, a Lisp is a custom-made command that someone have created for you sometime in the past. If the peeps here don't get to look at the routine behind the command, there is not much they can help you with - besides writing a brand new routine which is unneccesary since you have one that works almost as you want.

Posted
To display coordinates like that you are most likely using a Lisp of some sort, a Lisp is a custom-made command that someone have created for you sometime in the past. If the peeps here don't get to look at the routine behind the command, there is not much they can help you with - besides writing a brand new routine which is unneccesary since you have one that works almost as you want.

 

I think I should reword the thread,

 

I know in order for me to view coordinates in the second image I have to use a lisp program.

The question is, how do I do this?

 

I see where I'm creating confusion though.

Posted

Somewhere in the Lisp-routine there is code that determines how the text is displayed - if you can post the actual lisp routine then it is very likely that you can get help in changing the code.

Posted

(defun c:ne ()(setvar "osmode" 1)
(setq ne1 (getpoint"\nPick point..."))
(setvar "osmode" 0)
(if (/= ne1 nil)(go_ne)(princ"\nInvalid Location !"))
(princ)
)
(setq tx-ht 0.5)
(defun go_ne ()(setvar "luprec" 2)
(setq prmt (strcat "Enter TEXT HEIGHT<"(rtos tx-ht)">: "))
(princ prmt)
(setq x-ht (getreal))(if (= x-ht nil)(setq x-ht tx-ht))
(setq tx-ht x-ht)
(setq e-x (car ne1))(setq xx (rtos e-x))
(setq n-y (cadr ne1))(setq yy (rtos n-y))
(tx-f)
)
(defun tx-f ()
(setq vx (strcat " E " xx))
(setq vy (strcat " N " yy))
(command "text" "j" "ml" ne1 x-ht "0" vy)
(command "text" "j" "ml" ne1 x-ht "90" vx)
)

 

This is what I've been told would work.

Posted

Also how do I implement this? Make it actually work? I've saved the program but when it comes to opening the program it never works.

I type in (load "myprog") and it comes up with "error load failed".

Posted

This is because AutoCAD isn't able to locate that file - you should either add container folder in Options --> Files --> Support Files Search Path list or input the loading path (please note the double back-slashes):

(load "[color=red]C:\\MyLispTool\\[/color]myprog")

Posted

@bharthts01

possibly this lisp will do the job for you

 


;LBLCOORD - plain label point w/coords 
(defun c:LBLCOORD 
()
 (setvar "CMDECHO" 0)
 (setq pt 1)
 (while (/= pt 
nil)
   (setq pt (getpoint "\n PICK POINT TO LABEL 
"))
   (if (/= pt nil)
     
(progn (setq n (strcat "N " (rtos (cadr 
pt))))
            
(setq e (strcat "E " (rtos (car 
pt))))
            
(setq tp (getpoint "\n PICK POINT FOR COORDINATES 
"))
            
(command "TEXT" tp "0" 
n)
            
(command "TEXT" "" e)
     )
   
)
 )
)
(princ)

 

Cheers and good luck, be sure to read post #9

Posted

@bharthts01: I did some changes to your code to print both labels on the same line (the order is the one you stated in the first post).

(defun c:ne ()(setvar "osmode" 1)
(setq ne1 (getpoint"\nPick point..."))
(setvar "osmode" 0)
(if (/= ne1 nil)(go_ne)(princ"\nInvalid Location !"))
(princ)
)
(setq tx-ht 0.5)
(defun go_ne ()(setvar "luprec" 2)
(setq prmt (strcat "Enter TEXT HEIGHT<"(rtos tx-ht)">: "))
(princ prmt)
(setq x-ht (getreal))(if (= x-ht nil)(setq x-ht tx-ht))
(setq tx-ht x-ht)
(setq e-x (car ne1))(setq xx (rtos e-x))
(setq n-y (cadr ne1))(setq yy (rtos n-y))
(tx-f)
)
(defun tx-f ()
(setq vx (strcat " E " xx))
(setq vy (strcat " N " yy))
[color=red](command "_.TEXT" "_J" "_ML" "_non" ne1 x-ht 0.0 (strcat vx " / " vy))[/color]
)

Posted

Thanks guy, one last question... I've loaded the lisp into cad, how do I use it now?

Posted

Your code define a new command named NE that you may call at prompter like built-in commands.

Posted

It works fine now, just a few minor adjustments I need to it now.

 

cad_xy.jpg

 

First one, I need an arrow showing where it points to.

Second one, I want it where it shows 9 digits

 

e.g. (in the picture above) 430315507 & 434191791

 

Edit - is it normal for your object snap to turn on and off when using this lisp?

Posted

For OSNAP, try this version of the code:

(defun c:ne( / oldOsmode e-x n-y ne1 prmt tx-ht vx vy x-ht xx yy )
(defun go_ne()
 (setvar "luprec" 2)
 (setq prmt (strcat "Enter TEXT HEIGHT<" (rtos tx-ht) ">: "))
 (princ prmt)
 (setq x-ht (getreal))
 (if (= x-ht nil)
  (setq x-ht tx-ht)
 )
 (setq tx-ht x-ht)
 (setq e-x (car ne1))
 (setq xx (rtos e-x))
 (setq n-y (cadr ne1))
 (setq yy (rtos n-y))
 (tx-f)
)

(defun tx-f()
 (setq vx (strcat " E " xx))
 (setq vy (strcat " N " yy))
 (command "_.TEXT" "_J" "_ML" ne1 x-ht 0.0 (strcat vx " / " vy))
)

(setq tx-ht 0.5)
(setq oldOsmode (getvar "OSMODE"))
(setvar "osmode" 1)
(setq ne1 (getpoint "\nPick point..."))
(setvar "osmode" 0)
(if (/= ne1 nil)
 (go_ne)
 (princ "\nInvalid Location !")
)
(setvar "OSMODE" oldOsmode)
(princ)
)

For sure, your code require more adjustements.

Posted

Possible to get code with these settings in object snap mode?

 

Thanks

 

cad_code.jpg

 

Also, would be great if I could have the 'arrow' pointing at the point which the coordinate is set to.

Posted

Change this line

(setvar "osmode" 1)

to

(setvar "osmode" [color=red]427[/color])

Posted

Nearly there,

 

lisp_new.jpg

 

Also keep it at 9 digits if possible, (get rid of the last 2 after the decimal places)

Posted

To get the numbers without decimals adjust those lines:

[color=red];[/color](setvar "luprec" 2)
...
(setq xx (rtos e-x [color=red]2 0[/color]))
...
(setq yy (rtos n-y [color=red]2 0[/color]))

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...