[LISP] - obtaining the Z label

[LISP] - obtaining the Z label

pakula.michalina
Participant Participant
6,528 Views
5 Replies
Message 1 of 6

[LISP] - obtaining the Z label

pakula.michalina
Participant
Participant
Hi,
I kindly ask for help. Programming is not my forte, especially the syntax I will refer to.
 
I am preparing a simple LISP for use in Autodesk software. Its main tasks are to get the Z value indicated by clicking the point and insert the point and the label with the height value as text.
 
Target appearance:
Untitled.png
My problem is not knowing how to correct this rather trivial code that I am enclosing, to:
 
1. The text was inserted in the height of 0.3m (no need to define by the user in the program).
 
2. The position of the text (Position Z) corresponds to the Z value of the indicated point.
 
 
Code:
(defun c:lh (/  p x y ptcoord textloc)
(while
    (setq p (getpoint "\nPick Point: "))
    (command "_POINT" p)
    (setq z (rtos (caddr p)))
    (setq ptcoord (strcat z))
    (setq textloc (getpoint "\nPick Label Location: "))
    (command "_TEXT" textloc p "" ptcoord "")
  )
)

Thanks in advance for any tips! 🙂 

0 Likes
Accepted solutions (1)
6,529 Views
5 Replies
Replies (5)
Message 2 of 6

ronjonp
Mentor
Mentor

Have you thought about using an attributed block and fields for this? Attached is an example.

 

0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

I would use a point coordinate filter to get the X & Y coordinates of the Text insertion point from the 'textloc' variable, but the Z coordinate from the point.  And I would specify the rotation -- depending on your version, AutoCAD may or may not default to the latest rotation used, which if it does, may not be 0.  Also, unlike in manual Text operation, within a (command) function the supplying of the text content ends the command -- you don't give it the extra Enter "" to do that.  Try this [untested]:

 

(defun c:lh (/ p z textloc)
  (while
    (setq p (getpoint "\nPick Point: "))
    (command "_POINT" p)
    (setq z (rtos (caddr p)))
;;;    (setq ptcoord (strcat z))  ;;; not doing anything for you
    (setq textloc (getpoint "\nPick Label Location: "))
    (command "_TEXT" ".XY" textloc (caddr p) 0.3 0 z)
  )
)

That requires that the current Text Style is defined without a fixed height.  You could also define a Style with a fixed height of 0.3, call for that Style in the Text command, and not supply an answer to the height question that won't be asked.  Even with a non-fixed-height Style, I would suggest calling for the Style with that option in the Text command, since you won't usually know what the current Style is.

Kent Cooper, AIA
Message 4 of 6

pakula.michalina
Participant
Participant

Yes, I tried this solution. This is the option I actually use. However, it is sometimes tiring when you have to place a lot of such height points. I was thinking about the possibility of optimizing my work using LISP, hence my question 🙂

But that is also a good solution!

I can recommend! Thank you very much!

0 Likes
Message 5 of 6

pakula.michalina
Participant
Participant

Thank you very much for your help!

This is exactly what I was trying to achieve.

It is true, depending on the version of AutoCAD, the inserted text may be rotated, but it is a matter of adjusting it to your needs (e.g. defining the angle value in the code).

0 Likes
Message 6 of 6

ronjonp
Mentor
Mentor

@pakula.michalina wrote:

Yes, I tried this solution. This is the option I actually use. However, it is sometimes tiring when you have to place a lot of such height points. I was thinking about the possibility of optimizing my work using LISP, hence my question 🙂

But that is also a good solution!

I can recommend! Thank you very much!


So do you need to actually pick these points or do they exist as another type of object already? This might have potential to be automated even more.

0 Likes