Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Vl commands to convert text to Mtext

  1. #1
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Vl commands to convert text to Mtext

    I want to be able to take a piece of text that is blue, convert it to mtext, and add a string that is red to the text that is already there.

    Here is what I have so far:

    Code:
    (defun c:cC (/ ss ename obj)
    (vl-load-com)
    (setq ss (ssget (list (cons 0 "TEXT,attdef,mtext"))))
    	 ; removed mtext, %%u won't work on mtext
    (and ss	; must test for nil
    	 (setq i -1)
    	 (while (setq ename (ssname ss (setq i (1+ i))))
    	(setq obj (vlax-ename->vla-object ename))
    (vla-put-textstring
    	obj
    	(strcat (vla-get-textstring obj) " ({C1;ABANDON})")
    )
    (vlax-release-object obj)
    	 )
    )
    (princ)
    )

  2. #2
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Vl commands to convert text to Mtext

    Try this.
    Code:
    (defun c:Test (/ ss Ent obj TxtObj)
    (vl-load-com)
    (if (setq ss (ssget (list (cons 0 "TEXT,attdef,mtext"))))
    	 ; removed mtext, %%u won't work on mtext
     (while (setq Ent (ssname ss 0))
      (setq obj (vlax-ename->vla-object Ent))
      (if
       (or
        (= (vla-get-ObjectName obj) "AcDbText")
        (= (vla-get-ObjectName obj) "AcDbAttributeDefinition")
       )
       (progn
        (setq TxtObj
         (vla-AddMtext
          (vlax-get
           (vla-get-ActiveDocument (vlax-get-Acad-Object))
           (if (equal (getvar "cvport") 1)
            'PaperSpace
            'ModelSpace
           )
          )
          (if (= (vla-get-Alignment obj) 0)
           (vla-get-InsertionPoint obj)
           (vla-get-TextAlignmentPoint obj)
          )
          0
          (if (= (vla-get-ObjectName obj) "AcDbText")
           (vla-get-TextString obj)
           (vla-get-TagString obj)
          )
         )
        )
        (foreach x '(Layer Height Rotation)
         (vlax-put TxtObj x (vlax-get obj x))
        )
        (vla-Delete obj)
        (setq obj TxtObj)
       )
      )
      (ssdel Ent ss)
      (vla-put-textstring
       obj
       (strcat (vla-get-textstring obj) " ({\\C1;ABANDON})")
      )
      (vlax-release-object obj)
     )
    )
    (princ)
    )

  3. #3
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Vl commands to convert text to Mtext

    That gives me a great start, I will mess around with it and see if I can get it to keep the current justification and insertion, If I cant figure it out, I'll post another question.

    Thanks,

  4. #4
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Vl commands to convert text to Mtext

    It should put the mtext in at the correct insertion point, but the insertion point is referenced different for the mtext. You will have to make a cond statement to test for all the justification, and then match them to the mtext equivalence.

    You're welcome.

  5. #5
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Vl commands to convert text to Mtext

    Code:
    (setq TxtObj
    	 (vla-AddMtext
    	  (vlax-get
    	   (vla-get-ActiveDocument (vlax-get-Acad-Object))
    	   (if (equal (getvar "cvport") 1)
    		'PaperSpace
    		'ModelSpace
    	   )
    	  )
    	  (if (= (vla-get-Alignment obj) 0)
    	   (vla-get-InsertionPoint obj)
    	   (vla-get-TextAlignmentPoint obj)
    	  )
    0 <- What is this zero for?
    	  (if (= (vla-get-ObjectName obj) "AcDbText")
    	   (vla-get-TextString obj)
    	   (vla-get-TagString obj)
    	  )
    	 )
    	)
    How and where would I set up the conditional statements. I suppose I would use and if statement to match the two alignment points up

    would It look somehting like this:

    Code:
    	(setq jp   (vla-get-alignment txtObj)
    	);end of setq
    	(if (= jp acAlignmentMiddleLeft)
    	  (setq na "ml")
       (command "_.justifytext" Obj "" na)

  6. #6
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Vl commands to convert text to Mtext

    The 0 is for the mtext width, so that it all fits on one line.

    I would set up the cond statement after the new text object get created. The old text object is still around, so you can still get the info from it, but the alignment (justification) is different for text and mtext objects. I haven't done all the research on them, so that is something you will have to do, but you don't need a command to change the alignment of the object, just change the alignment property.

    You cond should looks something like
    (cond
    ((equal (vla-get-Alignment obj) 0)
    (vla-put-Alignment TxtObj 1)
    )
    ... and so on....
    )

    On a side note, you might have to set the text alignment point of the mtext object once you change the alignment, I know you have to with the text objects, but I'm not sure about mtext object since I hate mtext, and try not to use whenever I can.

  7. #7
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Vl commands to convert text to Mtext

    I am having trouble converting insertions from text to mtext. I can get the insertion point to change, but I cant get it to place the text where I want, it moves the insertionpoint instead of moving the mtext

  8. #8
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Vl commands to convert text to Mtext

    I will look into this when I have some time. Maybe someone who uses mtext will chime in, and maybe they will have some code to help.

  9. #9
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Vl commands to convert text to Mtext

    This seems to work for me.
    Code:
    (defun c:Test (/ ss Ent obj TxtObj InsPt)
    (vl-load-com)
    ;-----------------------------------------------
    (defun MtMatchDtAlignment (DtObj / DtAli)
    
    (setq DtAli (vla-get-Alignment DtObj))
    (cond
     ((or
      (equal DtAli 0)
      (equal DtAli 3)
      (equal DtAli 5)
      (equal DtAli 12)
     )
      7
     )
     ((or
      (equal DtAli 1)
      (equal DtAli 13)
     )
      8
     )
     ((or
      (equal DtAli 2)
      (equal DtAli 14)
     )
      9
     )
     ((or
      (equal DtAli 4)
      (equal DtAli 10)
     )
      5
     )
     ((equal DtAli 6)
      1
     )
     ((equal DtAli 7)
      2
     )
     ((equal DtAli 8)
      3
     )
     ((equal DtAli 9)
      4
     )
     ((equal DtAli 11)
      6
     )
    )
    )
    ;----------------------------------------------------------------------
    (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (if (setq ss (ssget (list (cons 0 "TEXT,attdef,mtext"))))
    	 ; removed mtext, %%u won't work on mtext
     (while (setq Ent (ssname ss 0))
      (setq obj (vlax-ename->vla-object Ent))
      (if
       (or
        (= (vla-get-ObjectName obj) "AcDbText")
        (= (vla-get-ObjectName obj) "AcDbAttributeDefinition")
       )
       (progn
        (setq TxtObj
         (vla-AddMtext
          (vlax-get
           (vla-get-ActiveDocument (vlax-get-Acad-Object))
           (if (equal (getvar "cvport") 1)
            'PaperSpace
            'ModelSpace
           )
          )
          (setq InsPt
           (if (= (vla-get-Alignment obj) 0)
            (vla-get-InsertionPoint obj)
            (vla-get-TextAlignmentPoint obj)
           )
          )
          0
          (if (= (vla-get-ObjectName obj) "AcDbText")
           (vla-get-TextString obj)
           (vla-get-TagString obj)
          )
         )
        )
        (foreach x '(Layer Height Rotation)
         (vlax-put TxtObj x (vlax-get obj x))
        )
        (vla-put-AttachmentPoint TxtObj (MtMatchDtAlignment obj))
        (vla-put-InsertionPoint TxtObj InsPt)
        (vla-Delete obj)
        (setq obj TxtObj)
       )
      )
      (ssdel Ent ss)
      (vla-put-textstring
       obj
       (strcat (vla-get-textstring obj) " ({\\C1;ABANDON})")
      )
      (vlax-release-object obj)
     )
    )
    (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (princ)
    )

  10. #10
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Vl commands to convert text to Mtext

    That works great, thanks Tim for all your help.

Page 1 of 2 12 LastLast

Similar Threads

  1. Bring "Convert Text to MText" to AutoCAD LT
    By Wish List System in forum AutoCAD Wish List
    Replies: 3
    Last Post: 2013-11-16, 12:10 PM
  2. Convert Mtext to Text
    By MikeJarosz in forum VBA/COM Interop
    Replies: 4
    Last Post: 2007-08-30, 09:13 PM
  3. Globally convert text to mtext
    By Stephen.Walz in forum AutoLISP
    Replies: 11
    Last Post: 2006-12-08, 08:45 PM
  4. convert all text to mtext
    By c_rado in forum AutoCAD General
    Replies: 6
    Last Post: 2006-12-03, 11:15 PM
  5. AutoCAD LT 2006 - Convert Text to MText?
    By flansburg in forum AutoCAD LT - General
    Replies: 3
    Last Post: 2006-03-07, 07:59 AM

Posting Permissions

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