Jump to content

Struggle Replacing text in MText object with string in a variable, no prompt ideally


Kreaten_vhar

Recommended Posts

Good morning, afternoon, evening everyone.

I've hit yet another snag in my efforts to code some useful lisp programs.

 

The functionality of the code is to rip a big ol' string from an mtext object, compare it against another string that exists in a variable, then edit the big ol' string to remove any lines of text that doesn't have a equivalent. Once the big ol' string has been edited I want to replace all the original text in the mtext object with our new string.

As is I have managed to do all the comparisons and edit the big ol' string in memory, but replacing the old text in the mtext object with my new string confounds me 🥴

I've searched around to see if there were any functions the generous peeps of this community, and found some promising code from Lee Mac, his batch find function, As well as other functions, but they all seem to involve popping up a dialog box and selecting objects.

I also figure the FIND command could do it, but it also prompts the user to select an object and type a string but all that information is sitting in memory already, seems like a waste of user time. I don't want a dialog box 😫

 

Any recommendations?

Edited by Kreaten_vhar
D'oh title was scuffed
Link to comment
Share on other sites

If you have selected Big Ol String then that should be accessible to replace later as an entity

 

After that you might look at ent update to replace the text with its new text. Should be that you update dxf code '1'

 

How big is the Big Ol String by the way? If it is very big ol string or massive ol string you might find that the text is split between a couple of dxf codes, you'll have to delete these before you put your new text into dxf 1.

 

If I get chance I have this somewhere and can dig it out later, and if not might give you a clue where to look

  • Like 1
Link to comment
Share on other sites

I can't be sure if I understand correctly because there is no example code or drawing, 

 

Selecting text from the entire drawing without user selection (ssget "X" '((0 . "*TEXT))) ends with this one line. 

 

Changing text is sometimes convenient with (vl-string-translate ~~)

 

To execute a command without a dialog box, add - in front of the command.

 

 

  • Like 1
Link to comment
Share on other sites

@Steven P

Thanks for taking the time respond,

I seem to be on the right track now with entupd and similar functions, thank you so much!

@exceed
Thank you as well!

Right now the issue is taking the text we've already edited and dumping it back on the drawing. Also I didn't want to post any code because it's loaded with propriety info as is, sorry about that  >.<
Thank you for the tip about running commands without the dialog box, those commandline tricks always evade me lol 😅


As always, y'all on here are legends!

Link to comment
Share on other sites

Some times i tend to over think things playing devil's advocate here asking a stupid question.

But why are you comparing it against another string that exists in a variable and not just overwrite it with the variable string cutting out the middle man?

 

like exceed said a example drawing or code would help narrow down what you want to do.

  • Like 1
Link to comment
Share on other sites

Just now, Kreaten_vhar said:

@Steven P

Thanks for taking the time respond,

I seem to be on the right track now with entupd and similar functions, thank you so much!

 

 

Love it when a small hint sets you on your way again, if you need anything more just shout out.

  • Thanks 1
Link to comment
Share on other sites

Just now, mhupp said:

But why are you comparing it against another string that exists in a variable and not just overwrite it with the variable string cutting out the middle man?

Howdy @mhupp, thanks for taking some time to respond.

 

I'm essentially taking a file index template and comparing it against a project folder which can have anywhere from ~6-17 drawings.
So I'm iterating through the dwg files in the folder to check what files are actually present or not. Then for what's not there, I want to delete the portions of the text contained within the mtext object that mention the drawings that are not present. Though all that is "done" (at least in memory) I've just been struggling getting the new stuff into the mtext object.

 

I feel like I'm probably diving a bit too deep into all this for having around a month of LISP programming (and dare I say only a month of coding experience in general xD) Sink or swim time baby!

And yeah, I do apologize about not posting code, but there's semi-sensitive info there 🙈
 

Link to comment
Share on other sites

  • Kreaten_vhar changed the title to Struggle Replacing text in MText object with string in a variable, no prompt ideally

If you just want to put something in text or mtext,

case1. your text is object 

(vla-put-textstring your_text_obj your_text_string)

case2. your text is ename

(vla-put-textstring (vlax-ename->vla-object your_text_ename) your_text_string)

 

The link is the code I recently used vla-put-textstring. 

This is the code to paste the text copied to the clipboard into the existed text in drawing.

maybe this code has little relevance, but there is how to put something in the text

  • Like 2
Link to comment
Share on other sites

Thank you very much!

I'm making some headway into this problem now. Couldn't find vla-put-textstring in my reference material, and that's very much useful here!

Going to keep reading into entmod and things of that nature to try and get more comfortable with messing with the DB to go along with Steven P's suggestion.

You all never disappoint 😃

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...