+ Reply to Thread
Page 1 of 5 1 2 3 ... LastLast
Results 1 to 10 of 45
  1. #1
    Senior Member jmerch's Avatar
    Using
    MEP 2010
    Join Date
    Sep 2010
    Posts
    153

    Default Edit Mtext via LISP

    Registered forum members do not see this ad.

    I've searched high and low for a LISP to edit Mtext via LISP and have only found one (thanks Mike Weaver) that is almost what I want. It is posted below but I want it to autoselect a piece of MTEXT that I designate (via ssget). I have modified this code but don't understand Visual LISP enough to know why it's erroring...any help?

    Original:
    Code:
    (defun c:mtval( / ent objmtext stroldval 
    strnewval)
      (setq
     ent (car (entsel))
     objMText 
    (vlax-ename->vla-object ent)
     strOldval (vlax-get-property objMText 
    "TEXTSTRING")
     strnewval (getstring T (strcat "\nNew text value<" 
    stroldval ">: "))
     )
      (if 
    strnewval
     (vlax-put-property objmtext "TEXTSTRING" 
    strnewval)
     )
      (vlax-release-object objmtext)
      
    )
    My modified code:
    Code:
    (defun c:mtval( / getmtext objMText strnewval)
      (setq getmtext (ssget "_X" '((0 . "MTEXT")(1 . "TEST")))
            objMText (vlax-ename->vla-object (entlast))
            strnewval (getstring T "Enter New Text: ")
      )
      (if strnewval (vlax-put-property objmtext "TEXTSTRING" strnewval)
    )
      (vlax-release-object objmtext)
     
    )

  2. #2
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,616

    Default

    Be careful that the text string is case sensitive .

    So here it goes buddy.
    Code:
    (defun c:test (/ new ss)
      ; Tharwat 24.02. 2010
      (if (and (setq new (getstring T "Enter New Text: "))
               (setq ss (ssget "_X" '((0 . "MTEXT") (1 . "test"))))
          )
        ((lambda (i / ss1 e)
           (while
             (setq ss1 (ssname ss (setq i (1+ i))))
              (entupd
                (cdr
                  (assoc
                    -1
                    (entmod
                      (subst (cons 1 new) (assoc 1 (setq e (entget ss1))) e)
                    )
                  )
                )
              )
           )
         )
          -1
        )
        (Alert
          "\n Your replaced text is not found in the drawing....."
        )
      )
      (princ)
    )
    Tharwat

  3. #3
    Senior Member jmerch's Avatar
    Using
    MEP 2010
    Join Date
    Sep 2010
    Posts
    153

    Default

    that doesn't work... it asks me to select an object then just isolates it....

  4. #4
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2011
    Join Date
    Apr 2008
    Posts
    5,988

    Default

    Code:
      (setq getmtext (ssget "_X" '((0 . "MTEXT")(1 . "TEST"))) <-Select all MText with "TEST" value
            objMText (vlax-ename->vla-object (entlast)) <- converts the last created object to a vla-object (not what you want to do here)
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  5. #5
    Senior Member jmerch's Avatar
    Using
    MEP 2010
    Join Date
    Sep 2010
    Posts
    153

    Default

    Quote Originally Posted by alanjt View Post
    Code:
      (setq getmtext (ssget "_X" '((0 . "MTEXT")(1 . "TEST"))) <-Select all MText with "TEST" value
            objMText (vlax-ename->vla-object (entlast)) <- converts the last created object to a vla-object (not what you want to do here)
    I know I'm selecting all Mtext with "Test" value, I understand the ssget function. But on the entlast, i thought that just grabbed the entity data from the last object, I didn't realize it converts the last created object.

    In order to edit the Mtext, from what I can tell it has to be a vla-object which is why it's getting converted, right?

  6. #6
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2011
    Join Date
    Apr 2008
    Posts
    5,988

    Default

    Quote Originally Posted by jmerch View Post
    I know I'm selecting all Mtext with "Test" value, I understand the ssget function. But on the entlast, i thought that just grabbed the entity data from the last object, I didn't realize it converts the last created object.

    In order to edit the Mtext, from what I can tell it has to be a vla-object which is why it's getting converted, right?
    Your selection with ssget has no bearing on (entlast). You need to step through the selectionset with repeat/while or vla-get-activeselectinset.
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  7. #7
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,616

    Default

    Check this out in VL .

    Code:
    (defun c:test (/ new ss)(vl-load-com)
      ; Tharwat 24.02. 2010
      (if (and (setq new (getstring T "Enter New Text: "))
               (setq ss (ssget "_X" '((0 . "MTEXT") (1 . "test"))))
          )
        ((lambda (i / ss1)
           (while
             (setq ss1 (ssname ss (setq i (1+ i))))
              (vla-put-textstring (vlax-ename->vla-object ss1) new)
           )
         )
          -1
        )
        (Alert
          "\n Your replaced text is not found in the drawing....."
        )
      )
      (princ)
    )
    Tharwat

  8. #8
    Senior Member jmerch's Avatar
    Using
    MEP 2010
    Join Date
    Sep 2010
    Posts
    153

    Default

    @alan: Maybe I'm not understanding you. I was doing the ssget to "grab" the mtext on my drawing, and thought I needed to convert this to vla-obect. What contains the properties (text string) of mtext? vla-get-activeselectionset isn't a function.

    @Tharwat: Same result, it asks 'Select Objects in Current Drawing or Xref'...then isolates it. Why is it doing that? it's not asking me to enter any text or anything...

    I appreciate the help from both of you.

  9. #9
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,616

    Default

    The two routines that I already posted for you are working normally in Arch. Autocad , but I do not have MEP cad to check these codes for it .

    Anyway , can you please copy your command line after fails of the routine with your version ?

    Tharwat

  10. #10
    Senior Member jmerch's Avatar
    Using
    MEP 2010
    Join Date
    Sep 2010
    Posts
    153

    Default

    Registered forum members do not see this ad.

    it's not really "failing", just not doing what I want...I wonder what in your code has dependency on the ACAD version...

    Command: test
    Select Objects in Current Drawing or Xref:
    Select Objects in Current Drawing or Xref:
    Regenerating model.

Similar Threads

  1. Edit Field using MText
    By matt89brooks in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 28th Dec 2010, 01:42 pm
  2. mtext edit is too light
    By fle in forum AutoCAD General
    Replies: 2
    Last Post: 6th Aug 2010, 04:47 pm
  3. Edit Text In Mtext
    By naghshe in forum AutoCAD Beginners' Area
    Replies: 3
    Last Post: 4th Oct 2008, 06:56 pm
  4. Edit Multiple Pieces of Mtext
    By CAD-e-Corner in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 5th Mar 2008, 03:50 am
  5. Can Lisp use mtext to make multi string mtext editor?
    By muck in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 18th Dec 2006, 03:22 am

Bookmarks

Posting Permissions

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