Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AutoLisp: Move texts from insertion point to nearest intersection

0 REPLIES 0
Reply
Message 1 of 1
ireGVHN7
794 Views, 0 Replies

AutoLisp: Move texts from insertion point to nearest intersection

Hi,

 

I need a macro to move all the text objects in a layer to the nearest intersection osnap of any entities in that layer.

It is to place the elevation text on its corresponding point and afterwards "eattext"a point file.

 

I did found this surfing the internet:

 

 

(defun c:txt2int ( / ss n eg tb ptc pt )
(setvar "CMDECHO" 0)
(command "._UNDO" "_GROUP")
(command ".-LAYER" "OFF" "*" "Y" "ON" "_text" "") ; turns all layers OFF except _text
(command "_.ZOOM" "_E")
(setq ss (ssget "x" '((0 . "TEXT") (8 . "_text"))))
(setq n -1)
(repeat (sslength ss)
(setq eg (entget (ssname ss (setq n (1+ n)))))
(setq tb (textbox eg))
(setq ptc (polar (car tb) (angle (car tb) (cadr tb))
(* 0.5 (distance (car tb) (cadr tb))))) ; center point of text
(command "_UCS" "_OB" (cdr (assoc -1 eg)))
(setq ptc (trans ptc 1 0)) ; trans ptc from User (Current) UCS to World (WCS)
(command "_UCS" "_P") ; previous UCS
(while (null (setq pt (osnap ptc "int"))) ;finds the nearest intersection
(command "_.ZOOM" "0.1X")
);while
(entmod (append eg (list (cons 72 4) (cons 11 pt)))) ; changes justification to middle and moves text to the nearest inters.
);repeat
(command "_.ZOOM" "_E")
(command ".-LAYER" "ON" "*" "") ; turns all layers ON
(command "._UNDO" "_E")
(princ)
); defun c:txt2int

 

 

The problem is that it takes the bottom center of the text as reference point, and I need it to be the insertion point.

I did try to change (cons 72 4) for (cons 72 0), but didn´t work.

Maybe the problem is in this part?: (setq ptc (polar (car tb) (angle (car tb) (cadr tb))
(* 0.5 (distance (car tb) (cadr tb))))) ; center point of text

 

I add a simple dwg to help understand the problem

 

Thanks a lot for your help before hand!! 

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report