Visual LISP, AutoLISP and General Customization
cancel
Showing results forĀ 
ShowĀ Ā onlyĀ  | Search instead forĀ 
Did you mean:Ā 

Pre-defined find & replace lisp

54 REPLIES 54
Reply
Message 1 of 55
cadee
22546 Views, 54 Replies

Pre-defined find & replace lisp

Hi

 

Is there a lisp or script program that will find and replace pre-defined text/mtext value of eg " issued for tender " for

" issued for consctruction " without having to select anything.

 

Thanks in advance

54 REPLIES 54
Message 21 of 55
Kent1Cooper
in reply to: rwydesk500


@rwydesk500 wrote:

.... 

"Command: TRC ; error: bad argument type: lselsetp nil"

....


It works for me, in minimal testing.  That message should mean that it's not finding any qualifying objects [the tss variable is nil, so it can't figure out how many objects are in it to apply to the (repeat) function].  The (ssget) filter for text content is case-sensitive -- might you have any case differences in Text/Mtext you're expecting it to find?  If that's the issue, it can be accounted for.

Kent Cooper, AIA
Message 22 of 55
BlackBox_
in reply to: Kent1Cooper

Have you considered using a simple Field reference which points to a Sheet Set Custom Property?

 

We use this methodology for all of our projects, our titleblocks, etc.... You can update the one Custom Property value, and done... The entire plan set can be immediately re-Published, etc..

 

No opening each drawing, no manipulating entities, no iterating a directory of drawings via ObjectDBX, no custom code... Using all built-in functionality. Lemon squeezy.



"How we think determines what we do, and what we do determines what we get."

Message 23 of 55
Kent1Cooper
in reply to: BlackBox_


@BlackBoxCAD wrote:

Have you considered using a simple Field reference which points to a Sheet Set Custom Property?

....


Something like that, or Rtext or an Xref could accomplish the same.  Those approaches can certainly make life easier if you are setting up a new situation, and I would recommend that to anyone in that situation.  But this thread was started in the context of already-existing Text elements that needed to be changed, and I can only assume rwydesk500 who found and revived it after over a year has the same situation to deal with.

Kent Cooper, AIA
Message 24 of 55
rwydesk500
in reply to: BlackBox_

Yes, custom fields work great for Title Block information. But, my goal here is to replace one word with another word, in a string of Notes which are Mtext. I must replace this word across about 600 drawings.

 

I just used the Lee-Mac solution, mentioned by Greg above, and it worked beautifully. Thanks for everyones help!

Regards,

Rick Yoerger

AutoCAD Electrical 2016
Message 25 of 55
BlackBox_
in reply to: rwydesk500


@Kent1Cooper wrote:

@BlackBoxCAD wrote:

Have you considered using a simple Field reference which points to a Sheet Set Custom Property?

....


Something like that, or Rtext or an Xref could accomplish the same.  


No... They cannot, as each of those you mention require opening the drawing in the Editor, or custom code (DBX?) in order to manipulate said entity, whereas SSM can be modified without opening a drawing.

 

Regardless, the prerequisite is that this Field, and Custom Property be already setup... Which is obviously not the case here, no matter how advantageous.

 


@Kent1Cooper wrote:
But this thread was started in the context of already-existing Text elements that needed to be changed, and I can only assume rwydesk500 who found and revived it after over a year has the same situation to deal with.

That's the context that I overlooked when skimming the prior, multiple pages... Thanks for clarifying. :beer:

 

 


@rwydesk500 wrote:

Yes, custom fields work great for Title Block information. But, my goal here is to replace one word with another word, in a string of Notes which are Mtext. I must replace this word across about 600 drawings.

 

I just used the Lee-Mac solution, mentioned by Greg above, and it worked beautifully. Thanks for everyones help!


No worries; glad you got it sorted... Lee's BFIND is one of my favorite routines from him for several years.

 

 



"How we think determines what we do, and what we do determines what we get."

Message 26 of 55
Kent1Cooper
in reply to: BlackBox_


@BlackBoxCAD wrote:

@Kent1Cooper wrote:
....

Something like that, or Rtext or an Xref could accomplish the same.  


No... They cannot, as each of those you mention require opening the drawing in the Editor, or custom code (DBX?) in order to manipulate said entity, whereas SSM can be modified without opening a drawing.

....


You're wrong about Rtext, and even with an Xref there's nothing custom about it.  With an Xref, yes, it would mean getting into a drawing, but just the Xref-referenced one [which presumably in this kind of usage would consist of only a piece of Text] rather than any drawing in the set, and by changing that one you'd be done for the whole set.  Maybe you've never used Rtext [I have almost never used it], but doing it that way is kind of like an Xref for text content only, and it would in fact be updatable without opening any drawing at all, but just updating the Rtext-referenced text file, and you'd be done for all drawings with Rtext that references that file.  I don't have a new-enough version here to have Sheet Sets, but I can only imagine you need to get into something to update a Custom Property value -- is that different in any meaningful way from editing a little text file?

Kent Cooper, AIA
Message 27 of 55
BlackBox_
in reply to: Kent1Cooper

*Sigh*

 

RText is a custom Express Tool Entity (specifically, ObjectName=RText, which inherits from ImpEntity, an internal, sealed ObjectARX Entity Type), and came out long before the myriad enhacements to MText, and D[B]Text Entities support for Fields, let alone SSM functionality... Hence my logical classification of this entity type as being 'custom'.

 

One would have to manually edit a Drawing (in the Editor), or perhaps use custom code using ObjectDBX to add/manipulate (if the RText Express Tool is not Command dependent)... I've already gone over the setup of SSM Properties were not already setup, so in this aspect, no difference... Setup is setup.

 

RText, as a result of being a legacy carry over, has inferior support for different expressions than that of a standard Field (who still uses Diesel!?)... That said, a Field is a Field, with regard to regeneration, updating behavior, etc..

 

Your example of RText updating automatically is dependent on a static expression where the read property value information changes as a byproduct of actions, rather than directly changing the value ad-hoc (i.e., File Name, Save Date, etc.), and not a dynamic value (i.e., Project Name, Client Name, Phase of Constrcution, Revisions Number, etc.) which SSM is vastly superiror... Once setup accordingly... And can be manipulated without any drawing being opened at all.

 

 

 

... Now, since none of this applies to the thread, I do hope that you do not persist with further meaningless banter.



"How we think determines what we do, and what we do determines what we get."

Message 28 of 55
Kent1Cooper
in reply to: BlackBox_


@BlackBoxCAD wrote:

.... 

One would have to manually edit a Drawing (in the Editor), or perhaps use custom code using ObjectDBX to add/manipulate (if the RText Express Tool is not Command dependent)....

   

.... Now, since none of this applies to the thread, I do hope that you do not persist with further meaningless banter.


*Sigh* back at ya....

 

I reserve the right to persist if you persist in your earlier factually incorrect [that has meaning for me, because I don't want others who see this thread to be misled] claim, expressed again similarly above, that Rtext "...require(s) opening the drawing in the Editor, or custom code (DBX?) in order to manipulate said entity...."

 

Fields and SSM are surely better in several ways, but however preferable they may be, the fact remains that modifying Rtext content requires neither opening any drawing nor any kind of custom code.  Adding Rtext would require being in the drawing, but if the OP's already-existing Text elements were Rtext instead, they could in fact change the wording in all drawings without getting into any of them -- it wouldn't even require having AutoCAD running at all.

Kent Cooper, AIA
Message 29 of 55
BlackBox_
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@BlackBoxCAD wrote:

.... 

One would have to manually edit a Drawing (in the Editor), or perhaps use custom code using ObjectDBX to add/manipulate (if the RText Express Tool is not Command dependent)....

   

.... Now, since none of this applies to the thread, I do hope that you do not persist with further meaningless banter.


*Sigh* back at ya....

 

I reserve the right to persist if you persist in your earlier factually incorrect [that has meaning for me, because I don't want others who see this thread to be misled] claim, expressed again similarly above, that Rtext "...require(s) opening the drawing in the Editor, or custom code (DBX?) in order to manipulate said entity...."

 

Fields and SSM are surely better in several ways, but however preferable they may be, the fact remains that modifying Rtext content requires neither opening any drawing nor any kind of custom code.  Adding Rtext would require being in the drawing, but if the OP's already-existing Text elements were Rtext instead, they could in fact change the wording in all drawings without getting into any of them -- it wouldn't even require having AutoCAD running at all.


Very well.

 

Given the already-existing [RText] elements you speculate, kindly educate me as to how you'd change an RText Field from it's diesel expression's calculated value, to "Mickey Mouse," without the use of opening the drawing in the editor, nor custom code, within AutoCAD and no other application.



"How we think determines what we do, and what we do determines what we get."

Message 30 of 55
BlackBox_
in reply to: Kent1Cooper


@Kent1Cooper wrote:

I reserve the right to persist if you persist in your earlier factually incorrect [that has meaning for me, because I don't want others who see this thread to be misled] claim, expressed again similarly above, that Rtext "...require(s) opening the drawing in the Editor, or custom code (DBX?) in order to manipulate said entity...."

 


Becuase you and I share a passion for both correctness, and completeness... You use them so often, that I thought you might enjoy using them correctly even more:

 

Grammar Girl: Parentheses, Brackets, and Braces

 

 

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 31 of 55
Kent1Cooper
in reply to: BlackBox_


@BlackBoxCAD wrote:
....
Becuase you and I share a passion for both correctness, and completeness... You use them so often, that I thought you might enjoy using them correctly even more:

Grammar Girl: Parentheses, Brackets, and Braces


I always use brackets for "parenthetical" remarks, quite intentionally in this AutoCAD Customization context even though they may not be proper in a literary context, in order to keep the distinction between them and the parentheses used with AutoLISP functions.  The latter I always refer to in parentheses, such as to say "look into the (vlax-curve-isClosed) function."  Since in that usage they don't indicate a "parenthetical," I use brackets when that's what I mean.  [Besides, you don't need to use the Shift key for brackets, as you do for parentheses.]

Kent Cooper, AIA
Message 32 of 55
Kent1Cooper
in reply to: BlackBox_


@BlackBoxCAD wrote:
.... 

Given the already-existing [RText] elements you speculate, kindly educate me as to how you'd change an RText Field from it's diesel expression's calculated value, to "Mickey Mouse," without the use of opening the drawing in the editor, nor custom code, within AutoCAD and no other application.


Where is this Diesel angle coming from?  There's no Diesel involved, there's no calculated value, there's just text-character content.  I'm talking about just plain Rtext, and not an Rtext Field, if that's something different.  [Bear in mind that not everyone has the capability of Fields, nor Sheet Sets.  There are many who participate here who use older versions of AutoCAD without those features or various others -- Tables, dynamic Blocks, etc.  And I'm not even the only Expert Elite member who uses 2004 at work, not by our choice.]

 

The "...within AutoCAD and no other application..." was not part of your original statement, which was incorrect as stated, but apparently didn't reflect what you intended.  If you add that requirement, then no, you can't do it without getting into Notepad or equivalent, but you still don't have to open any drawing at all, nor use any custom code at all.  Since I can't try it, tell me: can you modify the content of a Field without even having AutoCAD running, as you can with Rtext?

 

[And if you're going to get picky about punctuation, I'll join you:  that should be its.  It's one of the most common such errors, but there's an easy way to remember: no possessive pronoun contains an apostrophe.  Just as mine and your and our and his and her and their don't have them, neither do its or hers or yours or ours or theirs.  "It's" with an apostrophe is only the contraction of "it is."]

Kent Cooper, AIA
Message 33 of 55
BlackBox_
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@BlackBoxCAD wrote:
.... 

Given the already-existing [RText] elements you speculate, kindly educate me as to how you'd change an RText Field from it's diesel expression's calculated value, to "Mickey Mouse," without the use of opening the drawing in the editor, nor custom code, within AutoCAD and no other application.


Where is this Diesel angle coming from?  There's no Diesel involved, there's no calculated value, there's just text-character content.  I'm talking about just plain Rtext, and not an Rtext Field, if that's something different.  [Bear in mind that not everyone has the capability of Fields, nor Sheet Sets.  There are many who participate here who use older versions of AutoCAD without those features or various others -- Tables, dynamic Blocks, etc.  And I'm not even the only Expert Elite member who uses 2004 at work, not by our choice.]

 

The "...within AutoCAD and no other application..." was not part of your original statement, which was incorrect as stated, but apparently didn't reflect what you intended.  If you add that requirement, then no, you can't do it without getting into Notepad or equivalent, but you still don't have to open any drawing at all, nor use any custom code at all.  Since I can't try it, tell me: can you modify the content of a Field without even having AutoCAD running, as you can with Rtext?

 

[And if you're going to get picky about punctuation, I'll join you:  that should be its.  It's one of the most common such errors, but there's an easy way to remember: no possessive pronoun contains an apostrophe.  Just as mine and your and our and his and her and their don't have them, neither do its or hers or yours or ours or theirs.  "It's" with an apostrophe is only the contraction of "it is."]


"no, you can't do it"

Thanks for confirming... I appreciate your honesty, Kent.

 

More on the text file option below.

 

 

 

"Where is this Diesel angle coming from?"

From my multiple prior statements referencing the limitations of Diesel expressions in RText, which you never once addressed to instead discuss an external text file dependency prior to my challenging you to educate me... Instances where I even referenced items such as file path, file name, saved date, etc.

 

"The "...within AutoCAD and no other application..." was not part of your original statement, which was incorrect as stated, but apparently didn't reflect what you intended."

If it was your intention to work on an external text file, that's fine... You just never made the time to include that little morsel of information in your responses, which is why I purposefully included it to mimic the SSM criteria... One could say that you failed to reflect what you intended, so-to-speak (until now, that is), but I'll give you the benefit of the doubt, my friend.

 

"Since I can't try it, tell me: can you modify the content of a Field without even having AutoCAD running, as you can with Rtext?"

Yes.

 

From Visual Studio (a glorified text editor), one can access the Sheet Set Manager API via ActiveX COM, or .NET (never tried this for myself), and programmatically modify the content source a Field read's from (similar to an RText external file dependency, just encrypted in lieu of plain text)... This, however, requires custom code which is why I chose to remain consistent in my challenge to you, by maintaining the "within AutoCAD" criteria which most users are relegated to when accessing SSM. 

 

Now that stage one thinking is out of the way (we now have modified RText, Field, etc.), stage two warrants the question... And then what?

 

Plotting said change(s) (as I clearly included previously)... Since one cannot plot modified RText from one's external text editor, one would still require AutoCAD**... So the ability to modify RText, or SSM outside of AutoCAD is irrelevent for a typical production task (as a generalization)... Something that I'd like to believe you'd agree is a fair statement.

 

** Core Console (AcCoreMgd.dll) is part of AutoCAD, as it consumes the same license required. The use of another application such as TrueView falls under the AutoCAD umbrella, despite being a stand alone application.

 

"There are many who participate here who use older versions of AutoCAD without those features or various others -- Tables, dynamic Blocks, etc.  And I'm not even the only Expert Elite member who uses 2004 at work, not by our choice.]"

Of course not everyone is on the same version, but I did not realize you approach your argument(s) from a 2004 point of view... If you mentioned it previously, then I mistakenly overlooked that pertinent information. I honestly cannot remember the limitations of 2004 as compared to the multiple versions installed here (2009-2014).

 

That must be frustrating for you, especially when someone like me comes along making the case for new fangled things... SSM is quite old as I understand it, but still.

 

It's hard enough for me to just keep straight the myriad distinctions between Land Desktop, Civil 3D, Map 3D, Plant 3D, and AMEP (we don't use vanilla AutoCAD).

 

"And if you're going to get picky about punctuation, I'll join you:"

Silly me, thanks, Kent... I appreciate the constructive criticism.

 

For what it's worth, I truly was not nitpicking you; you repeat the use of brackets, etc. very frequently... If it were, say, a misplaced apostrophe once in a while, I never would have mentioned it, my friend.

 

 

 

May I be so bold to assume we agree that we've more than sufficiently covered both the limitations, and benefits of both SSM, and RText to conclude this tangential discussion?

 

Always a pleasure... Unfortunately, I'm beginning to like you, Kent.

 

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 34 of 55
armando1903
in reply to: cadee

Hi wanted to know how to make the lisp pre-defined find and replace you created but for only the selected text and not every occurrence, or how replace pre-defined text with existing text for  text ,mtext, and attributes . I have to do this manually every day.

Message 35 of 55
DJPiper
in reply to: cadee

Guys i tried Kent Cooper code and it works. But it has a limitation. If my text String to be replaced has an " symbol on it (Ex. 12"), the code doesn't work.

Im trying to change
PIPE 12" SCH STD. to. PIPE 4" SCH XS

Any fix for this? Thanks!
Message 36 of 55
BlackBox_
in reply to: cadee

Firstly, goodness I was a miserable cuss back then. I don't know how Kent put up with me, but thank goodness I'm no longer working for that toxic employer anymore - it brought out the absolute worst in me. Thank God for my new employer!

As to your question, DJPiper; not sure which code exactly you tried to use, so in posting from my iPhone perhaps the in-built FIND Command would be able to satisfy this text swap if the drawing is open in the editor?

Cheers


"How we think determines what we do, and what we do determines what we get."

Message 37 of 55
DJPiper
in reply to: BlackBox_

HI BlackBox, im trying to use this lsp from Kent Cooper.

 

(defun C:TRC ; = Text Replace for Complete text/mtext strings, pre-defined content
  (/ tss tdata)
  (setq tss (ssget "X" (list (cons 1 "issued for tender"))))
  (repeat (sslength tss)
    (setq
      tdata (entget (ssname tss 0))
      tdata (subst (cons 1 "issued for construction") (assoc 1 tdata) tdata)
    ); end setq
    (entmod tdata)
    (ssdel (ssname tss 0) tss)
  ); end repeat
); end defun

 

 

i have replace "issued for tender" to "Pipe 12" Sch Std", which will not work since i have now 3 quote symbol. i dont have any idea how to fix this.

Lisp is greek for me.

 

Message 38 of 55
Kent1Cooper
in reply to: DJPiper


@DJPiper wrote:

....

  ... (cons 1 "issued for construction") ...

....

i have replace "issued for tender" to "Pipe 12" Sch Std", which will not work since i have now 3 quote symbol. i dont have any idea how to fix this.

.... 


Put a backslash before the inch mark:

... (cons 1 "Pipe 12\" Sch Std") ...

 

If you make a piece of Text/Mtext with

Pipe 12" Sch Std

[typed in that way] as its content, and then look at the way AutoCAD "stores" the text content of that, using

(cdr (assoc 1 (entget (entlast))))

you will see the backslash in there -- it will return

"Pipe 12\" Sch Std"

Kent Cooper, AIA
Message 39 of 55
BlackBox_
in reply to: Kent1Cooper


@Kent1Cooper wrote:

Put a backslash before the inch mark:

... (cons 1 "Pipe 12\" Sch Std") ...


1+

 

This is correct.

 

 

 



"How we think determines what we do, and what we do determines what we get."

Message 40 of 55
DJPiper
in reply to: cadee

thanks Kent! One more thing, i hope im not asking too much. Is it possible to make the lsp accept a partial portion of the text string? Currently i have to enter the whole string. It would be much better if the lsp is accepting a partial portion of the string. THANKS!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

ā€Boost