Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp move multiple text to line

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
cjandress
6543 Views, 12 Replies

Lisp move multiple text to line

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

12 REPLIES 12
Message 2 of 13
_Tharwat
in reply to: cjandress

Hope this help ..... Smiley Happy

 

(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)
)

 

Message 3 of 13
pbejse
in reply to: cjandress

(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

Message 4 of 13
cjandress
in reply to: pbejse

Thank you so much, this work perfectly!!! 

Message 5 of 13
cjandress
in reply to: _Tharwat

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.

Message 6 of 13
_Tharwat
in reply to: cjandress


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

Message 7 of 13

Lisp is not work

I want multiple text in single line
Thank u
Message 8 of 13


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

Kent Cooper, AIA
Message 9 of 13

Pls check the sample DWG
Give me the solution
Thank
Message 10 of 13


@sathyanarayanandme21 wrote:
Pls check the sample DWG
....

[Nothing attached]

Kent Cooper, AIA
Message 11 of 13
guywhiteing
in reply to: cjandress

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

Message 12 of 13
guywhiteing
in reply to: _Tharwat

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 you in advance.

Guy
Message 13 of 13
Kent1Cooper
in reply to: guywhiteing


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

Kent Cooper, AIA

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

Post to forums  

Autodesk Design & Make Report

”Boost