- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
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 ![]()
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
¡Resuelto! Ir a solución.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
I've edited your program to include a z coordinate and output all three coordinates on the same line.
(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 P1Z (caddr pnt1)) ;z coord <-- (setq STDX (rtos P1X 2 2)) (setq STDY (rtos P1Y 2 2)) (setq STDZ (rtos P1Z 2 2)) ;;;(setq COORDE (strcat "X " STDX )) <-- remove ;;;(setq COORDN (strcat "Y " STDY )) <-- remove (setq msg (strcat "X " STDX ", Y " STDY ", Z " STDZ)) (setq PTXT (getpoint "\nPick text location: ")) (command "LEADER" PNT1 PTXT "" msg "") (princ) )
To automatically load the program when you start up AutoCAD go here.
The program will work in 2D or 3D but will always output a Z coordinate.
To delete trailing zeros you may need to write a custom vlisp program that examines the text string of the coordinate from the last character backwards and deletes it if it is a zero and until the first non-zero number or the decimal point has been encountered. Perhaps there is such a routine already available that you can find via a web search.
BTW, are you familiar with the coordinates command? If not, try it out!
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
Drewpan wrote >>and KC replies :
....
(command "LEADER" PNT1 PTXT "" COORDE COORDN "")....
I want it to display (X 4.5, Y 2.2) instead
>> Further use for the (strcat) function:
(strcat "(X " COORDE ", Y " COORDN ")")
... 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)
>>Read about the DIMZIN System Variable, which affects trailing zeros in (rtos), among other things.
... to modify this script to work in 3D ....
(setq P1Z (cadr pnt1)) ;z coord <<-- what variable returns the actual z coordinate here?
>> Another d: (setq P1Z (caddr pnt1))
leading to:
(strcat "(X " COORDE ", Y " COORDN ", Z " COORDQ ")" )
... 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?
>>There's no such thing as a 2D environment -- AutoCAD works in 3D, and if you're not involving the Z direction, that's up to you. The return of points from (getpoint) always includes a Z coordinate. And most point information about objects [Circle centers, Line endpoints, etc.] also has a Z coordinate.
However, there is a complication with a LWPolyline. It must be "flat," and its entity data includes an elevation in the Z direction, which applies to all of it, and then it stores all the vertex locations with XY coordinates only. So if you're pulling point locations from entity data about a LWPolyline, and you need the Z coordinate, you must get the XY from the vertex information, and the Z from the global elevation. Write back if you need to know how to do that.
If by "a 2D environment" you mean just working in the World Coordinate System's XY plane only, a single routine could be made to display only the X and Y coordinates if the Z coordinate is 0, but display all three if it's not.
.... can you please give me step by step instructions on how to automatically load this script when I fire up AutoCAD. ....
>> [It's not a "script" -- that word has a specific, and different, meaning in AutoCAD.] Read about the acaddoc.lsp file. Put your code into that, and put that in a location in the Support File Search Path list in OPTIONS, and it will be loaded in every drawing. [There are other possibilities, but that's the "standard" approach.]
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
@leeminardi wrote:
....
To delete trailing zeros you may need to write a custom vlisp program that examines the text string of the coordinate from the last character backwards and deletes it if it is a zero and until the first non-zero number or the decimal point has been encountered. Perhaps there is such a routine already available that you can find via a web search.
....
Not necessary. Set DIMZIN appropriately [to 8 or 12] and get the strings without the trailing zeros right from (rtos).
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
Kent, I wasn't aware of DIMZIN. That makes it easy!
Drewpan, just put (command "dimzin" 8) at the start of the program. You may also want to set it back to the default when the command is done so put (command "dimzin" 0) at the end.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
@leeminardi wrote:
... put (command "dimzin" 8) at the start of the program. You may also want to set it back to the default when the command is done so put (command "dimzin" 0) at the end.
I would use (setvar 'dimzin 8) instead. There was a time when you had to do it that way, or through a SETVAR command. Somewhere along the way they made System Variable names themselves usable as if they were "command names," which is easier from the Command line doing it manually, but the (setvar) function is better in coded routines. It's not only [ever-so-slightly!] shorter, but it's also faster than calling up the command processor [though the difference would not be remotely noticeable in a single-instance case like this -- probably a matter of a few milliseconds].
And if you want to reset it afterwards, it might not have been 0 to begin with -- in the US where we're pretty much stuck with Imperial units, a lot of Architects like me have it set to 3 [read about what that means in Help], and people will have various reasons to use other values. So it's better to save the current value to a variable, and reset that:
(setq dimz (getvar 'dimzin))
(setvar 'dimzin 8)
.... routine ....
(setvar 'dimzin dimz)
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar