Jump to content

Edit Mtext via LISP


jmerch

Recommended Posts

Please note jmerch that if your intended to use any of my routines that I have already posted for you, you should modify the first line of

routines to ...... which is .

 

([color=red][b]/=[/b][/color] (setq new (getstring T "Enter New Text: ")) [b][color=red]""[/color][/b])

 

Because if a user used the routines and pressed enter instead of supporting a string , the routine would replace the found Mtexts to nil string (invisible).

 

Tharwat

 

so the /= forces the user to enter something?

Link to comment
Share on other sites

  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

  • jmerch

    17

  • alanjt

    10

  • Tharwat

    10

  • Lee Mac

    8

Top Posters In This Topic

so the /= forces the user to enter something?
No. /= means not equal to. If you look at my example, I have it comparing the getstring return to make sure it isn't equal to "" (what's returned if nothing is typed).

(/= "" (getstring T "\nEnter something: "))

Try it for yourself.

Link to comment
Share on other sites

so the /= forces the user to enter something?

 

No. but if the user hit enter instead of adding a string the routine won't change any of selection set to avoid the changes to nil texts.

Link to comment
Share on other sites

OK, I see what the /= is doing now. I haven't seen it used like that...only mainly in conditional statements...my mind doesn't think outside the box on that right now :)

 

Now I'm thinking of changing directions based on your guys' warnings. My MTEXT was theoretically going to always say the same thing until the user changed it which should only be once. The MTEXT is on the border for the sheet title. But I think I want to make it flexible if they have to change it in the future (I'm doing it this way b/c I'm using the setq value to enter the same data elsewhere). So, I probably shouldn't do the selection set based on MTEXT and the text value. So then I started thinking about ssget "_W" and give it points but I want this to be used on all my border sizes so the window area would never be the same...trying to think of what else I can use to filter it. I don't want it to be an attribute b/c I'd rather have it be MTEXT in case the user has to modify the layout of it or something.

Link to comment
Share on other sites

1. b/c the data stored from the user entering the text string will be used in naming my layout tab as well as other items on the drawing.

2. I was trying to cut out the extra step of the user having to type in the initial text to replace. So if I can have a LISP find this MTEXT that will always be in the same place, and ask the user to enter the new text, it'd be done.

Link to comment
Share on other sites

1. b/c the data stored from the user entering the text string will be used in naming my layout tab as well as other items on the drawing.

2. I was trying to cut out the extra step of the user having to type in the initial text to replace. So if I can have a LISP find this MTEXT that will always be in the same place, and ask the user to enter the new text, it'd be done.

Right on. Just like to suggest core commands, even if I'm a little late at suggesting them.
Link to comment
Share on other sites

Not a problem, I'm very open to suggestions even if they're the basic commands...sometimes I get zoned in on my ideas and try to over-think it when simple commands do the same thing.

 

The only other thing I can think of is to put it on it's own layer which I'd rather not do, but it could be easily filtered.

Link to comment
Share on other sites

If having it on its own layer is undesirable, how about adding some xData to it on creation, then it could be filtered just by filtering for the xData App name.

 

Something simple like:

 

  (-3
     (
        "LMAC_MTEXT"
        (1002 . "{")
        (1000 . "Titleblock-Text")
        (1002 . "}")
     )
  )

With a unique App Name (don't use anything prefixed with ACAD)

 

Then selection would be:

 

(ssget "_X" '((0 . "MTEXT")(-3 ("LMAC_MTEXT"))))

/idea

Link to comment
Share on other sites

If you decide to go down this route, you could use a function like this to add the xData:

 

(defun c:AddMTextXData ( / ss i )

 (if (setq ss (ssget "_:L" '((0 . "MTEXT") (-4 . "<NOT") (-3 ("LMAC_MTEXT")) (-4 . "NOT>"))))
   (repeat (setq i (sslength ss))
     (entmod
       (list
         (cons -1 (ssname ss (setq i (1- i))))
        '(-3 ("LMAC_MTEXT" (1002 . "{") (1000 . "Titleblock-Text") (1002 . "}")))
       )
     )
   )
 )

 (princ)
)

And this will edit the MText with the above xData:

 

(defun c:EditXDataMText ( / ss str ) (vl-load-com)

 (if
   (and
     (ssget "_X" '((0 . "MTEXT") (-3 ("LMAC_MTEXT"))))
     (not (eq "" (setq str (getstring t "\nSpecify Text Value: "))))
   )
   (progn 
     (vlax-for obj
       (setq ss
         (vla-get-ActiveSelectionSet
           (vla-get-ActiveDocument (vlax-get-acad-object))
         )
       )
       (vla-put-TextString obj str)
     )
     (vla-delete ss)
   )
 )
 
 (princ)
)

 

And to remove the XData:

 

(defun c:RemoveMTextXData ( / ss i )

 (if (setq ss (ssget "_:L" '((0 . "MTEXT") (-3 ("LMAC_MTEXT")))))
   (repeat (setq i (sslength ss))
     (entmod (list (cons -1 (ssname ss (setq i (1- i)))) '(-3 ("LMAC_MTEXT"))))
   )
 )

 (princ)
)

Edited by Lee Mac
Link to comment
Share on other sites

I will have to play around with Xdata and your samples...I've never used Xdata before (let alone heard of it) :D....learn something new every day...I mean hour... :shock:

 

Thanks you guys!

Link to comment
Share on other sites

I will have to play around with Xdata and your samples...I've never used Xdata before (let alone heard of it) :D....learn something new every day...I mean hour... :shock:

 

I've added a complementary function to my above post to demonstrate how to edit only those MText objects with the xData as assigned by my first function.

 

To view the structure of the assigned xData, use the above function to assign some xData, then query the object with this. Try it also with a Dimension object created with Dimension Style overrides.

 

Lee

Link to comment
Share on other sites

Why don't you post an example drawing/titleblock. I'm not saying XData isn't a viable option, but this might can be accomplished with a little less legwork.

Link to comment
Share on other sites

When you add the vla-delete ss, shouldn't that only be deleting that selection set? Is it deleting my "str" value also? b/c this is the data I would like to keep and use elsewhere.

Link to comment
Share on other sites

When you add the vla-delete ss, shouldn't that only be deleting that selection set? Is it deleting my "str" value also? b/c this is the data I would like to keep and use elsewhere.

 

(vla-delete ss)

 

Deletes the SelectionSet object from the Document SelectionSets Collection since we are finished with it at that point. When iterating through SelectionSets with Vanilla as opposed to Visual, AutoCAD takes care of the SelectionSet handling when the variable pointing to the SelectionSet is localised in the routine, so we don't have to worry.

 

By 'deleting' your 'str' value, I'm guessing you mean that the 'str' value is nil after the routine has completed - this is a result of the 'str' variable being localised in the routine. Have a read of this to understand why this is.

 

Regards,

 

Lee

Link to comment
Share on other sites

when the user enters the sheet name, it may contain a slash "/" in it. is there a way in the lisp to convert that to a different symbol (&) to be used elsewhere? What I mean is in the stored data, not actually on the sheet. I still want the "/" to display, but want to be able to change the "/" to a "&" just within LISP not to be displayed anywhere yet.

Edited by jmerch
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...