Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
dragonman101
Posts: 11
Registered: ‎05-31-2012
Message 1 of 6 (1,615 Views)
Accepted Solution

Lisp move multiple text to line

1615 Views, 5 Replies
05-31-2012 12:52 PM

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

Distinguished Mentor
_Tharwat
Posts: 600
Registered: ‎07-02-2010
Message 2 of 6 (1,594 Views)

Re: Lisp move multiple text to line

05-31-2012 02:24 PM in reply to: dragonman101

Hope this help ..... :smileyhappy:

 

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

 

____________________________________________________
Get learn and learn and practice , to become experienced guy .
*Expert Elite*
pbejse
Posts: 2,462
Registered: ‎11-24-2009
Message 3 of 6 (1,576 Views)

Re: Lisp move multiple text to line

05-31-2012 08:43 PM in reply to: dragonman101

(Defun c:MoveText  (/ li txts e)
      (if
            (and (princ "\nSelect Line for Alignment")
                 (setq li (ssget "_+.:smileyfrustrated::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

Contributor
dragonman101
Posts: 11
Registered: ‎05-31-2012
Message 4 of 6 (1,558 Views)

Re: Lisp move multiple text to line

06-01-2012 04:46 AM in reply to: pbejse

Thank you so much, this work perfectly!!! 

Contributor
dragonman101
Posts: 11
Registered: ‎05-31-2012
Message 5 of 6 (1,553 Views)

Re: Lisp move multiple text to line

06-01-2012 04:48 AM 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.

Distinguished Mentor
_Tharwat
Posts: 600
Registered: ‎07-02-2010
Message 6 of 6 (1,547 Views)

Re: Lisp move multiple text to line

06-01-2012 04:53 AM in reply to: dragonman101

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 .

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.