Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Drewpan
1489 Vistas, 6 Respuestas

Beginner: Help with lisp script - display co-ordinates of a point

Hi Community,

 

I am teaching myself AutCAD and really enjoying the challenge. (I am also NOT doing some

school or university course, so I am also NOT asking you to do my homework for me :cara_con_una_leve_sonrisa:

 

The Tutorial I am doing is very good for me and is found here: https://www.mycadsite.com/

 

One of the things I have found is that I can so far do most things, but in the how to videos

it does NOT tell me how to display the x and y coordinates as a label on the screen, even though

the drawings I copy have then displayed. There must be some easy way to do this but I have not

found it yet.

 

Notice the (1,1) and (4.1,1) point co-ordinates are displayed. This is what I want to do.

 

Since I am learning this great program I did a search of a few forums.

I have discovered this lisp script that ALMOST does what I want but NOT QUITE

 

(defun C:LP(/ PNT1 P1X P1Y STDY DY COORDN COORDE PTXT)
 (setq PNT1 (getpoint
 "\nPick coordinate point: "))
 (setq P1X (car pnt1)) ;x coord
 (setq P1Y (cadr pnt1)) ;y coord
 (setq STDX (rtos P1X 2 2))
 (setq STDY (rtos P1Y 2 2))
 (setq COORDE (strcat "X " STDX ))
 (setq COORDN (strcat "Y " STDY ))
 (setq PTXT (getpoint
 "\nPick text location: "))
 (command "LEADER" PNT1 PTXT "" COORDE COORDN "")
 (princ)
 )

 

I have modified the script slightly from the original so that when I fire it up using the LP command

- it will ask for a point then ask where to put the leader, and then display the point coordinates in

the following format:

 

X 4.5

Y 2.2

 

Where I need help is that I want it to display (X 4.5, Y 2.2) instead, but I don't know enough about Lisp

to do this. It would also be nice if I can make it display only what it has to and kill any trailing zeros

eg. the point X = 4, Y = 2.2 would be displayed (4, 2.2) instead of something like (4.000, 2.200)

 

 

It also seems to me to be straight forward to modify this script to work in 3D CAD by adding something like:

 

(defun C:LP3(/ PNT1 P1X P1Y P1Z STDY DY COORDN COORDE COORDQ PTXT)
 (setq PNT1 (getpoint
 "\nPick coordinate point: "))
 (setq P1X (car pnt1)) ;x coord <<-- If car returns the x coordinate, and;
 (setq P1Y (cadr pnt1)) ;y coord <<-- cadr returns the y coordinate, then;

 

 (setq P1Z (cadr pnt1)) ;z coord  <<-- what variable returns the actual z coordinate here?

 

 (setq STDX (rtos P1X 2 2))
 (setq STDY (rtos P1Y 2 2))

 

 (setq STDZ (rtos P1Z 2 2))


 (setq COORDE (strcat "X " STDX ))
 (setq COORDN (strcat "Y " STDY ))

 

 (setq COORDQ (strcat "Z " STDZ ))


 (setq PTXT (getpoint
 "\nPick text location: "))
 (command "LEADER" PNT1 PTXT "" COORDE COORDN COORDQ "")
 (princ)
 )

 

I am pretty sure this will NOT work - but I am also sure it is pretty close to working - I just don't know

HOW to make it work.

 

Another question is will the 3D version of the script kick an error if I am using 2D? or in

other words must I have two separate scripts for this in 2D and 3D or will the one script just

ignore the missing z coordinate in a 2D environment?

 

My final question is can you please give me step by step instructions on how to automatically

load this script when I fire up AutoCAD. I can run it by pasting the script into the command

line and it will work for the session but I don't see much point in that if I may use it often.

 

I have tried to find this in the Help files but it is a bit too advanced for where I am right now.

 

Thanks in advance.

 

Drewpan