Jump to content

To write a text


Alhazred

Recommended Posts

I have an horizontal line, by selecting its vertexes my routine should put a text centered above the line.

This is the code I've written, but it doesn't work, the problem occurs when the text should be printed

(defun c:ferri (/ pt1 pt2 pt2x ptc)
 (setq pt1 (getpoint "\nSelect 1st point:"))
 (setq pt2 (getpoint "\nSelect 2nd point:"))
 (setq pt1x (car pt1))
 (setq pt1y (rtos (+(cadr pt1) 0.1))) ;0.1 above the line
 (setq pt2x (car pt2))
 (setq ptc (rtos (/ (+ pt1x pt2x) 2))) ;line's middle point
 (command "_text" "_justify" "_mc" '(ptc pt1y) 0.1 0.0 "Dummy text")
 (princ)
)

The routine looks to not evalate the ptc and pt1y inside the "command", if I put there (90 30.1) the routine works.

The content of ptc and pt1y is correct, I've also tried without the rtos convertion.

Which is the problem?

Link to comment
Share on other sites

Quick guess, you're quoting variables, meaning they are read as their name, not their value. Instead of '(ptc pt1y), try (list ptc pt1y).

Link to comment
Share on other sites

That's it, I hadn't uderstood the difference between '(...) and (list ...).

Thanks.

 

This may help:

 

Explanation of the Apostrophe:

http://www.cadtutor.net/forum/showpost.php?p=258390&postcount=20

Link to comment
Share on other sites

Not sure if you use car cadr etc that if your line is on an angle that you would get true 0.1 offset maybe as below ?

 

defun c:ferri (/ pt1 pt2 pt2x ptc)
 (setq pt1 (getpoint "\nSelect 1st point:"))
 (setq pt2 (getpoint "\nSelect 2nd point:"))
(setq ang (angle pt1 pt2))
(setq dist (/ (distance pt1 pt2) 2.0) )
(setq ang2 (+ ang 1.5707))
(setq pt3 (polar pt1 ang dist))
(setq pt4 (polar pt3 ang 0.1))

(command "_text" "_justify" "_mc" pt4 ang 0.0 "Dummy text")

 (princ)
)

 

next step if you have lines then you can pick line rather than two points

 

(setq objl (entsel "\nPick line : "))
(setq tpp1 (entget (car objl) ) )
(setq pt1 (cdr (assoc 10 tpp1) ) ) 
(setq pt2 (cdr (assoc 11 tpp1) ) ) 

Link to comment
Share on other sites

Thanks BIGAL, I'm now trying to do the same for lines with any angulation.

I've tried to use your code, but it seems to not work for me, or it's probably me to use it incorrectly.

I've used the first code you posted, but the text is not positioned at the middle of the line.

 

I've written this other code (even if I know it is wrong), but depending on the angle of the line the text results closer or crossing the line.

(defun c:test( / pt1 pt1 ang ptc offs)
 (setq pt1 (getpoint "\point 1"))
 (setq pt2 (getpoint "\npoint 2"))
 (setq ang (angle pt1 pt2))
 (setq ang (/ (* ang 180) pi)) ; angle in degrees
 (setq ptc (/ (+ (car pt1) (car pt2)) 2.0)) ;middle point along X axis
 (setq offs (/ (+ (+ (cadr pt1) 0.1) (+ (cadr pt2) 0.1)) 2.0)) ;middle point along Y axix + 0.1 to raise the text from the line
 (setq puntom (list ptc offs))
 (command "_text" "_justify" "_mc" puntom 0.1 ang "text")
 (princ)
)

This is the result

txt.jpg

 

How can I do to have the text always at the same distance from the line and centered?

Link to comment
Share on other sites

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...