Results 1 to 7 of 7

Thread: Rotate Text

  1. #1
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Hartford, Michigan
    Posts
    3,086

    Default Rotate Text

    I am trying to write a routine that will change the justification of text from middle-left/middle-right to middle center, rotate it 180 degrees and change the justification to the opposite of what it was before.

    This is what I have so far, I cant figure out how to select the rotation point as the insertion of the text, that is where I keep getting errors, any help would be appreciated.

    Code:
    (defun c:tre ()
      (vl-load-com)
      (setq	ss	(ssget (list (cons 0 "TEXT,attdef,MTEXT")))
    	counter	0
      );end of setq
      (repeat (sslength ss)
        (setq Ent (ssname ss 0))
        (setq tempObj (vlax-ename->vla-object Ent)
    	  jp (vla-get-alignment tempObj)
        );end of setq
        (command "_.justifytext" ss "" "mc")
        (setq ins (vla-get-textalignmentpoint tempObj))
        (command "rotate" ss "" ins pi)
        (if	(= jp "middleleft")
          (setq na "mr")
          (setq na "ml")
        );end of if
        (vla-put-alignment ss na)
        (setq counter (1+ counter))
      );end of repeat
      (princ)
      (setq ss nil)
      (reset)
      (princ)
    );end of defun
    Last edited by ccowgill; 2005-11-28 at 10:10 PM. Reason: Mike Please move this to AutoLisp, I was in the wrong forum

  2. #2
    AUGI Addict Glenn Pope's Avatar
    Join Date
    2001-05
    Location
    Austin, TX USA
    Posts
    2,201

    Default Re: Rotate Text

    Hi ccowgill,

    Since Mike is busy at AU I hope you don't mind if I move it for you

    Thanks.
    Glenn Pope
    Civil Designer/CAD Manager
    River City Engineering
    AutoCAD Civil 3D 2011 Ver. 3
    Windows 7 Pro 64bit
    I explode MTEXT.

  3. #3
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Hartford, Michigan
    Posts
    3,086

    Default Re: Rotate Text

    Thanks Glenn

  4. #4
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043

    Default Re: Rotate Text

    Using this will return a variant
    Code:
    (setq ins (vla-get-textalignmentpoint tempObj))
    To get a point from the variant you would have to do something like
    Code:
    (setq ins
     (safearray-value
      (variant-value
       (vla-get-TextAlignmentPoint tempObj)
      )
     )
    )
    Or you could just use the ActiveX controls like
    Code:
    (setq ins (vlax-get tempObj 'TextAlignmentPoint))
    Hope that is clear.
    Tim

  5. #5
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Hartford, Michigan
    Posts
    3,086

    Default Re: Rotate Text

    Thanks, that helped my routine get a little further before it spit back an error.
    When I use my code now, it gives me this output:

    Command: tre
    Select objects: 1 found

    Select objects: _.justifytext
    Select objects: 1 found

    Select objects:
    Enter a justification option
    [Left/Align/Fit/Center/Middle/Right/TL/TC/TR/ML/MC/MR/BL/BC/BR] <ML>: mc
    Command: rotate
    Current positive angle in UCS: ANGDIR=counterclockwise ANGBASE=0

    Select objects: 1 found

    Select objects:
    Specify base point:
    Specify rotation angle or [Reference]: 180
    Command: ; error: lisp value has no coercion to VARIANT with this type:
    "middleleft"

    Here is my new code:
    Code:
    (defun c:tre ()
      (vl-load-com)
      (setq	ss	(ssget (list (cons 0 "TEXT,attdef,MTEXT")))
    	counter	0
      );end of setq
      (repeat (sslength ss)
        (setq Ent (ssname ss 0))
        (setq tempObj (vlax-ename->vla-object Ent)
    	  jp	  (vla-get-alignment tempObj)
        );end of setq
        (command "_.justifytext" ss "" "mc")
        (setq ins (vlax-get tempObj 'TextAlignmentPoint))
        (vla-put-rotation tempobj pi)
        (command "rotate" ss "" ins 180)
        (if	(= jp "middleleft")
          (setq na "middleright")
          (setq na "middleleft")
        );end of if
        (vla-put-alignment tempObj na)
        (setq counter (1+ counter))
      );end of repeat
      (princ)
      (setq ss nil)
      (reset)
      (princ)
    );end of defun
    I am sure the problem is the vla-put-alignment line but I am not sure. Again, thanks in advance for the help

  6. #6
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2002-12
    Location
    Brandon, Florida
    Posts
    687

    Default Re: Rotate Text

    Look at the routine peter posted.

    ; Written By Peter Jamtgaard Dec. 2002
    ; This function will allow the user to change the justification of text or
    ; attributes programatically using activeX
    ; *Alignment codes*
    ; 0 - acAlignmentLeft
    ; 1 - acAlignmentCenter
    ; 2 - acAlignmentRight
    ; 3 - acAlignmentAligned
    ; 4 - acAlignmentMiddle
    ; 5 - acAlignmentFit
    ; 6 - acAlignmentTopLeft
    ; 7 - acAlignmentTopCenter
    ; 8 - acAlignmentTopRight
    ; 9 - acAlignmentMiddleLeft
    ; 10 - acAlignmentMiddleCenter
    ; 11 - acAlignmentMiddleRight
    ; 12 - acAlignmentBottomLeft
    ; 13 - acAlignmentBottomCenter
    ; 14 - acAlignmentBottomRight
    ;
    ; *Format*
    ; (vl-justifytext <object> <justificationcode>)
    ;
    ; with
    ; (setq OBJ (vlax-ename->vla-object (car (nentsel))))
    ;
    ; *Examples*
    ; (vl-justifytext OBJ 0)
    ; (vl-justifytext OBJ acAlignmentLeft)
    ;

  7. #7
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Hartford, Michigan
    Posts
    3,086

    Default Re: Rotate Text

    Here is my final program, it seems to work fine, or at least I haven't had any problems, thanks for your help.
    Code:
    (defun c:tre (/ ss counter Ent tempObj jp ins na)
      (vl-load-com)
      (setq	ss	(ssget (list (cons 0 "TEXT,attdef,MTEXT")))
    	counter	0
      );end of setq
      (repeat (sslength ss)
        (setq Ent (ssname ss counter)
              tempObj (vlax-ename->vla-object Ent)
    	  jp	  (vla-get-alignment tempObj)
        );end of setq
        (command "_.justifytext" Ent "" "mc")
        (setq ins (vlax-get tempObj 'TextAlignmentPoint))
        (command "rotate" Ent "" ins 180)
        (if	(= jp acAlignmentMiddleLeft)
          (setq na "mr")
          (setq na "ml")
        );end of if
        (command "_.justifytext" Ent "" na)
        (setq counter (1+ counter))
        );end of repeat
      (princ)
      (setq ss nil)
      (princ)
    );end of defun

Similar Threads

  1. Text Spreads Out on Rotate
    By Ohnoto in forum AutoCAD Fields
    Replies: 4
    Last Post: 2010-06-16, 01:45 PM
  2. Rotate Text
    By mjohns18 in forum AutoCAD General
    Replies: 6
    Last Post: 2009-02-26, 06:59 PM
  3. Rotate text
    By PeterJ in forum DWF Viewer - General
    Replies: 2
    Last Post: 2005-09-21, 05:38 PM
  4. How To: Rotate Text
    By Steve_Stafford in forum Revit Architecture - Tips & Tricks
    Replies: 1
    Last Post: 2005-06-15, 03:55 AM
  5. rotate text
    By windowsxp5 in forum AutoLISP
    Replies: 3
    Last Post: 2005-03-08, 03:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •