label to polyline

label to polyline

inaamazmi
Enthusiast Enthusiast
436 Views
6 Replies
Message 1 of 7

label to polyline

inaamazmi
Enthusiast
Enthusiast

Is there lisp that converts the lebel written as text or mtext into polyline of exact length

 

examle : mtext 32.123  then it should create a perpendicular polyline of 32.123 

according to drawing unit

0 Likes
Accepted solutions (1)
437 Views
6 Replies
Replies (6)
Message 2 of 7

Sea-Haven
Mentor
Mentor
Accepted solution

Something like this

 

 

 

(defun c:tpl ( / ss x ent len pt)
(setq ss (ssget '((0 . "*TEXT"))))
(if (= ss nil)
(alert "no text selected")
(progn
(repeat (setq x (sslength ss))
(setq ent (entget (ssname ss (setq x (1- x)))))
(setq len (atof  (cdr (assoc 1 ent)))); returns zero if not a number 
(setq pt (cdr (assoc 10 ent)))
(if (> len 0.0) 
(command "line" pt (polar pt 0.0 len) "")
)
)
)
)
(princ)
)
(c:tpl)

 

 

0 Likes
Message 3 of 7

inaamazmi
Enthusiast
Enthusiast

Exactly the same but line should be created vertically

@Sea-Haven 

0 Likes
Message 4 of 7

stevor
Collaborator
Collaborator

Try a replacement of "pt 0.0" by "pt (/ pi 2)"

S
0 Likes
Message 5 of 7

Kent1Cooper
Consultant
Consultant

A little fine-tuning question:

Do you want the vertical Polyline to be drawn always from the insertion point [what you would get from INSert Object Snap]?  The accepted solution uses the DXF code 10 entry in entity data, which is the insertion point for Mtext, and for Left-justified Text.  But if plain Text has any other justification, the insertion point is the DXF code 11 entry.  The 10 entry is always the left end of the baseline, regardless of justification, which is also the insertion point only when Left-justified [in which case the 11 entry is always 0,0].  Is that something that you would want to account for, to use the actual insertion point and not always the left end of the baseline?

 

Also, I suggest preventing Object Snap causing problems:

 

(command "_.pline" "_non" pt "_non" (polar pt (/ pi 2) len) "")

 

Kent Cooper, AIA
0 Likes
Message 6 of 7

Sea-Haven
Mentor
Mentor

Thank you for suggestions I used 0.0 for angle as I had rows of text not columns when testing, so maybe an extra question would be enter angle, need to use the DTR function, degrees to radians.

 

;The dtr function converts degrees to radians
;The rtd function converts radians to degrees
(defun dtr (a)
(* pi (/ a 180.0))
)
;
(defun rtd (a)
(/ (* a 180.0) pi)
)
(setq ang (dtr (getreal "\nEnter angle ")))


(command "_.pline" "_non" pt "_non" (polar pt ang len) "")

 

Note Autocad measures angles Counter Clockwise.

0 Likes
Message 7 of 7

calderg1000
Mentor
Mentor

Regards @inaamazmi 

You have 2 options, horizontal and vertical polyline, selecting the insertion pointry this code.

 

 

(defun c:pltext (/ spm s tx p1 p2 opc ang plt ptemp)
  (setq
    spm (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
  )
  (setq s  (car (entsel "\nSelect Text: "))
        tx (cdr (assoc 1 (entget s)))
        p1 (getpoint "\nPick Insert line: ")
  )
  (initget "H P")
  (setq opc (getkword "\nLine Horizontal/Perpendicular:[H/P]<H>: "))
  (if (= opc "H")
    (setq ang 0)
    (setq ang (/ pi 2))
  )
  (setq p2  (polar p1 ang (atof tx))
        plt (cons p1 plt)
        plt (cons p2 plt)
  )
  (setq plt   (apply 'append plt)
        ptemp (vlax-make-safearray
                vlax-vbDouble
                (cons 0 (- (length plt) 1))
              )
  )
  (vlax-safearray-fill ptemp plt)
  (vla-addpolyline spm ptemp)
  (princ)
)

 

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes