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

Lisp Routine to match the text rotation only

11 REPLIES 11
Reply
Message 1 of 12
Anonymous
2580 Views, 11 Replies

Lisp Routine to match the text rotation only

Is there a LISP routine to match the rotation of different text to a chosen rotated text. Im new with LISP and would appreciate your help greatly. I tried changing the settings on "_matchprop", but it changes other attributes I dont want changed.
Thanks......
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: Anonymous

Hi gatordea,test my script ; mrto is stand for match rotation of text to others ; Design by Ade Suharna ; 23 February 2005 ; program no. 200/02/2005 ; edit by (defun c:mrto (/ ent info50 opt ed) (setq osm (getvar "osmode")) (setvar "osmode" 64) (prompt "\nCLICK A TEXT AS SOURCE FOR ROTATION") (setq ss1 (ssget '((0 . "TEXT"))) ssn1 (ssname ss1 0) sse1 (entget ssn1) ang1 (cdr (assoc 50 sse1))) (prompt "\nCLICK A TEXT TO BE CHANGE") (setq ss2 (ssget '((0 . "TEXT"))) ssn2 (ssname ss2 0) sse2 (entget ssn2) ang2 (cdr (assoc 50 sse2)) ed (subst (cons 50 ang1)(assoc 50 sse2) sse2)) (entmod ed) (princ) (setvar "osmode" osm) ) gatordea wrote in message news:12544498.1109117483005.JavaMail.jive@jiveforum1.autodesk.com... > Is there a LISP routine to match the rotation of different text to a chosen rotated text. Im new with LISP and would appreciate your help greatly. I tried changing the settings on "_matchprop", but it changes other attributes I dont want changed. > Thanks......
Message 3 of 12
Anonymous
in reply to: Anonymous

nice. If you don't, I might tweak it some more to make it select base text and then be able to apply that rotation to any number of selected text/mtext entities - but here it is as a start with mtext included: ; mrto stands for match rotation of text to others ; Design by Ade Suharna ; 23 February 2005 ; program no. 200/02/2005 ; edit by (defun c:mrto (/ ent info50 opt ed) (setq osm (getvar "osmode")) (setvar "osmode" 64) (prompt "\nCLICK A TEXT AS SOURCE FOR ROTATION") (setq ss1 (ssget '((-4 . ""))) ssn1 (ssname ss1 0) sse1 (entget ssn1) ang1 (cdr (assoc 50 sse1))) (prompt "\nCLICK A TEXT TO BE CHANGE") (setq ss2 (ssget '((-4 . ""))) ssn2 (ssname ss2 0) sse2 (entget ssn2) ang2 (cdr (assoc 50 sse2)) ed (subst (cons 50 ang1)(assoc 50 sse2) sse2)) (entmod ed) (princ) (setvar "osmode" osm) )
Message 4 of 12
Anonymous
in reply to: Anonymous

Hi DaveD,thanks for your corrected,it's good feedback for me. DaveD wrote in message news:421e035e$1_3@newsprd01... > nice. If you don't, I might tweak it some more to make it select base text > and then be able to apply that rotation to any number of selected text/mtext > entities - but here it is as a start with mtext included: > > ; mrto stands for match rotation of text to others > ; Design by Ade Suharna > ; 23 February 2005 > ; program no. 200/02/2005 > ; edit by > (defun c:mrto (/ ent info50 opt ed) > (setq osm (getvar "osmode")) > (setvar "osmode" 64) > (prompt "\nCLICK A TEXT AS SOURCE FOR ROTATION") > (setq ss1 (ssget '((-4 . ""))) > ssn1 (ssname ss1 0) > sse1 (entget ssn1) > ang1 (cdr (assoc 50 sse1))) > (prompt "\nCLICK A TEXT TO BE CHANGE") > (setq ss2 (ssget '((-4 . ""))) > ssn2 (ssname ss2 0) > sse2 (entget ssn2) > ang2 (cdr (assoc 50 sse2)) > ed (subst (cons 50 ang1)(assoc 50 sse2) sse2)) > (entmod ed) > (princ) > (setvar "osmode" osm) > ) > >
Message 5 of 12
hulioman
in reply to: Anonymous

first... read and understand the AutoCAD help file on dxf codes. You will understand that text objects have specific dxf codes for each property.
The codes you can use with this routine...
1= the text value
40= the text height
50= the text rotation angle

In your example you wanted to match the rotation angle.
So... run the following routine and enter 50 for the dxf value.
Then select the source text entity. Then select the text entities to be changed.

This can match any dxf code... so look at the dxf help file.


(DEFUN C:TMATCHDXF()
(if dxfval
(progn
(setq xx dxfval)
(setq dxfval (getint (strcat "\nDXF VALUE?: <" (RTOS XX 2 0) ">")))
(IF (NOT DXFVAL)
(SETQ DXFVAL XX)
)
)
(SETQ DXFVAL (GETINT "\nDXF VALUE?: "))
)
(SETQ ENT (CAR (ENTSEL "\nSELECT THE TEXT TO MATCH")))
(SETQ EN (ENTGET ENT))
(REDRAW ENT 3)
(sETQ INS (CDR (ASSOC DXFVAL EN)))
(SETQ SS (SSGET (LIST (CONS 0 "TEXT,MTEXT,RTEXT,DTEXT"))))
(REDRAW ENT 4)
(IF (/= SS NIL)
(PROGN
(REPEAT (SSLENGTH SS)
(SETQ ENT (SSNAME SS 0))
(SETQ EN (eNTGET ENT))
(ENTMOD (SUBST (CONS DXFVAL INS) (ASSOC DXFVAL EN) EN))
(SSDEL ENT SS)
)
)
)
)
Message 6 of 12
jshore
in reply to: hulioman

@hulioman

 

I am pretty much teaching myself so go easy on me. lol This routine works great... I added a tools based on the code for each of the variables. I do have one question however, for Dtext and Mtext the DXFvalue for rotation is 50, if you try to include Mleader text the DFXval for rotation is 41, how would I rewrite to allow the match to work with Mleader as well... I would have to setq an the additional DXF at the beginning and add an (if to the end to allow for this right? 

Message 7 of 12
roland.r71
in reply to: jshore

@jshore

You are aware of the fact that you just replied to a 12.5 years old post?

 

To answer your question, if setting rotation is all you wish to do, it might be best to rewrite that script to fit your needs.

 

To change it will require a lot of work, as it works with any DXF code. Which means you need to account for all variations, with 2 directions.

(copy the 41 rotation from the leader to text rotation at 50 -or- copy 41 width from text to leader at #?)

Message 8 of 12
jshore
in reply to: roland.r71

Yes. I set it as new hoping that someone even if he is not able to answer someone would be able to.
Message 9 of 12
roland.r71
in reply to: jshore

I think this should do it (untested):

 

You will have to complete the list of DXF codes that are different for it to work for all codes.

 

!!! NOTE/WARNING: This will copy the suplied DXF code from selected object to a target object, which means:

To copy DXF code 41 from a TEXT to MLEADER is NOT THE SAME as copying DXF code 41 from MLEADER to TEXT !!!

 

(defun c:tmatchdxf()
   (if dxfval
      (progn
         (setq xx dxfval)
         (setq dxfval (getint (strcat "\nDXF value?: <" (rtos xx 2 0) ">")))
         (if (not dxfval)
            (setq dxfval xx)
         )
      )
      (setq dxfval (getint "\nDXF value?: "))
   )
   (setq ent (car (entsel "\nselect the text to match")))
   (setq en (entget ent))
   (redraw ent 3)
   (setq ins (cdr (assoc dxfval en)))
   (setq et1 (cdr (assoc 0 en)))
   (setq ss (ssget (list (cons 0 "TEXT,MTEXT,RTEXT,DTEXT,MLEADER"))))
   (redraw ent 4)
   (if (/= ss nil)
      (progn
         (repeat (sslength ss)
            (setq ent (ssname ss 0))
            (setq en (entget ent))
            (setq et2 (cdr (assoc 0 en)))
            (cond
               ; if we copy from (M/R/D/)TEXT to (M/R/D/)TEXT -or- MLEADER to MLEADER
               ; we can just copy to the same DXF code
               ((or 
                      (and (or (= et1 "TEXT")(= et1 "MTEXT")(= et1 "RTEXT")(= et1 "DTEXT"))
                           (or (= et2 "TEXT")(= et2 "MTEXT")(= et2 "RTEXT")(= et2 "DTEXT"))
                      )
                      (and (= et1 "MLEADER")(= et2 "MLEADER"))
                  )
                  (entmod (subst (cons dxfval ins) (assoc dxfval en) en))
               )
               ; if we copy from TEXT to MLEADER, or vice versa, we need to swap numbers
               ((or
                     (and (or (= et1 "TEXT")(= et1 "MTEXT")(= et1 "RTEXT")(= et1 "DTEXT"))
                          (= et2 "MLEADER")
                      )
                      (and (or (= et2 "TEXT")(= et2 "MTEXT")(= et2 "RTEXT")(= et2 "DTEXT"))
                          (= et1 "MLEADER")
                  )
                  (setq dxftar dxfval)
                  (cond
                      ; swap the target DXF codes which are different between TEXT and MLEADER
;                     ((= dxfval 40)(setq dxftar #?))
                     ((= dxfval 41)(setq dxftar 50))
;                     ((= dxfval 42)(setq dxftar #?))
;                     ((= dxfval 43)(setq dxftar #?))
                     ((= dxfval 50)(setq dxftar 41))
                  )
                  (entmod (subst (cons dxfval ins) (assoc dxftar en) en))
               )
            )
            (ssdel ent ss)
         )
      )
   )
)
Message 10 of 12
Kent1Cooper
in reply to: jshore


@jshore wrote:

.... I do have one question however, for Dtext and Mtext the DXFvalue for rotation is 50, if you try to include Mleader text the DFXval for rotation is 41, how would I rewrite to allow the match to work with Mleader as well.... 


[Nothing wrong with reviving an old thread if it's still relevant for you!]  Rotation is actually 42  for MLeaders, so fix that in other suggestions, but in any case....

 

For a rotation-only version, this works for me.  I had trouble getting (subst)/(entmod) to work assigning a rotation to MLeaders, for some reason I haven't figured out, so I used VLA methods for the assignment part.  [The extraction part could be done that way, too, but that was working in the original form so I left it.]  But it at least gives you a way of dealing with the difference, which you may be able to apply into a larger any-property matching routine.  It sets a 'ml' variable for whether the object in question is a MultiLeader or not, and uses a different (assoc) number to extract the rotation from the source one depending on that variable, and a different VLA Property to assign that to in the target object(s) depending on that variable:

 

(defun C:MTR (/ tsel tdata ss ml rot tobj); = Match Text Rotation
  (if
    (and
      (setq tsel (entsel "\nTextual object source for Rotation: "))
      (wcmatch (cdr (assoc 0 (setq tdata (entget (car tsel))))) "*TEXT,MULTILEADER")
      (setq ss (ssget '((0 . "*TEXT,MULTILEADER"))))
    ); and
    (progn
      (setq
        ml (member '(0 . "MULTILEADER") tdata)
        rot (cdr (assoc (if ml 42 50) tdata))
      ); setq
      (repeat (setq n (sslength ss))
        (setq
          tobj (vlax-ename->vla-object (ssname ss (setq n (1- n))))
          ml (= (vla-get-ObjectName tobj) "AcDbMLeader")
        ); setq
        (vlax-put tobj (if ml 'TextRotation 'Rotation) rot)
      ); repeat
    ); progn
  ); if
  (princ)
); defun
(vl-load-com)

 

BY THE WAY, forget/eliminate any references to DTEXT  in things like (ssget) filter liists and options in other code.  There is no such entity type.  It's just TEXT.

Kent Cooper, AIA
Message 11 of 12
john.uhden
in reply to: Anonymous

Be careful.  The text rotation property of mtext is different from that of text.  The text rotation is relative to the WCS, but the mtext rotation is relative to the current UCS.  I used to write routines including (command "_.UCS" "_W"), but I decided long ago to add code to figure out the difference and include it as an adjustment.

John F. Uhden

Message 12 of 12
jshore
in reply to: Kent1Cooper

mtr Works perfectly with all... Thanks to all for the help... 

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

Post to forums  

Autodesk Design & Make Report

”Boost