Hey guys. I have been struggling with an idea for a lisp. I have some general knowledge in lisp coding. But I can't seem to figure this one out (even to get started).
What I want to do is make a lisp that:
- selects a line
then
- select any amount of text (any type)
then
- moves all the text to that selected line without rotating the text
if a line is perfectly horizontal then move the text of the y axis.
if the line is vertical then move the text of the x axis.
or there can be a prompt asking the user to chose the angle or axis in which the text will move (say if they want to move the text to a slanted line, you can choose to move the text on an angle, while keeping the same format and not rotating the text, or you can ask the user if they want to move it only vertically or horizontally)
I hope this wasn't too confusing.
I would really like the code to integrate into my autocad
Please let me know if you have any questions about my request.
Thank you very much
See pictures
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
Hope this help .....
(defun c:test (/ l ss i sn v p e) (vl-load-com) ;;; Tharwat 31. May. 2012 ;;; (if (and (setq l (car (entsel "\n Select Line :"))) (eq (cdr (assoc 0 (entget l))) "LINE") (progn (prompt "Select texts to move to selected line") (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT")))) ) ) (repeat (setq i (sslength ss)) (setq sn (ssname ss (setq i (1- i)))) (setq v (vlax-ename->vla-object sn)) (setq p (vlax-curve-getclosestpointto l (cdr (assoc 10 (entget sn))) ) ) (if (eq (cdr (assoc 0 (setq e (entget sn)))) "MTEXT") (progn (entmod (subst (cons 71 2) (assoc 71 e) e)) (vla-put-insertionpoint v (vlax-3d-point p)) ) (progn (vla-put-alignment v acAlignmentTopCenter) (vla-put-TextAlignmentPoint v (vlax-3D-point p)) ) ) ) ) (princ) )
(Defun c:MoveText (/ li txts e)
(if
(and (princ "\nSelect Line for Alignment")
(setq li (ssget "_+.:S:E" '((0 . "*LINE"))))
(princ "\nSelect Texts to Align")
(setq txts (ssget "_:L" '((0 . "TEXT,MTEXT")))))
(repeat (sslength txts)
(vla-move
(setq e (vlax-ename->vla-object
(ssname txts 0)))
(vla-get-insertionpoint e)
(vlax-3d-point
(vlax-curve-getclosestpointto
(ssname li 0)
(vlax-get e 'insertionpoint)))
)
(ssdel (ssname txts 0) txts)
)
)
(princ)
)
HTH
thank, this is very helpful, however it does not work with plines and didn't quite line up the text the way I wanted.
Very close though.
No need to tweek it however. I have the solution now.
@dragonman101 wrote:thank, this is very helpful, however it does not work with plines and didn't quite line up the text the way I wanted.
Very close though.
No need to tweek it however. I have the solution now.
You showed into your aim image that the texts are located on the line at the center of each text . Am I right ?
And for polyline , it is too simple to add to codes .
@sathyanarayanandme21 wrote:
Lisp is not work
I want multiple text in single line
....
Welcome to these Forums! We need more information: what does "not work" mean? In a quick test, it seems to do what it is intended to do, but if that is not what you want, describe in more detail what you want it to do differently. Maybe change the rotation of each Text/Mtext object to align with the Line? Maybe space them equally along it, rather than Move each to the nearest point on it? Better yet, post a sample drawing or image showing before and after conditions.
Hi there,
This is perfect for the scenario I have, Please may you advise where I would post this code within AutoCAD and would it work with 14?
Thank in advance.
Guy
@guywhiteing wrote:
.... Please may you advise where I would post this code within AutoCAD and would it work with 14?
....
Welcome to these Forums!
If you Search for things like "load AutoLisp" and APPLOAD, you will find lots of descriptions of how to do it.
If by "14" you mean AutoCAD 2014, yes, it should work fine. If perhaps you mean Release 14, I think it should, but I'm not positive -- that's a pretty long time ago.