Find and Replace, Wildcards, Multiple Drawings

Find and Replace, Wildcards, Multiple Drawings

tstorzuk
Advocate Advocate
6,473 Views
21 Replies
Message 1 of 22

Find and Replace, Wildcards, Multiple Drawings

tstorzuk
Advocate
Advocate

A bit of help please, all you CAD Guru's;

 

I've got a couple hundred drawings that I need to replace some text that resides within various blocks. There are various possible combinations of what the text might be;

EL.###'-## ##/##"
EL.###'-## #/##"
EL.###'-## #/#"
EL.###'-##"
EL.###'-# ##/##"
EL.###'-# #/##"
EL.###'-# #/#"
EL.###'-#"
EL.##'-## ##/##"
EL.##'-## #/##"
EL.##'-## #/#"
EL.##'-##"
EL.##'-# ##/##"
EL.##'-# #/##"
EL.##'-# #/#"
EL.##'-#"

 

I need to replace any of these possibilities with nothing (make it completely blank).

 

I've read up on Lee Mac's Batch Find Replace, but it stipulates that it doesn't work with wildcards.

I've read up on JTB Batch Change that's available in the Autodesk store, but it's not worth $150USD to me. Plus it looks way too complicated for me to want to figure out how to use it.

 

Is there another possible option out there that any of you know about? Or some other solution that I'm overlooking?

 

Thanks in advance for your help!

0 Likes
Accepted solutions (1)
6,474 Views
21 Replies
Replies (21)
Message 2 of 22

pendean
Community Legend
Community Legend
If you just want blank entries, why the need for wildcards searches when you just want to remove all the attributes entries in only specific blocks?

Can you share a sample DWG file with these blocks in it for reference?

0 Likes
Message 3 of 22

tstorzuk
Advocate
Advocate

 

 

Pendean,

 

The blocks are automatically created by another program, and they are given random names (block1 through to block999). So it would be nearly impossible to just modify individual blocks.

 

Also, they aren't attributes. They are text entities within the blocks.

 

Attached is a sample file (various items have been removed for privacy). There are several elevations called out in each drawing. We're copying these drawings to another project. The elevations are changing, and the easiest way we've figured to deal with this is to delete them. Hence the desire to remove the text from the block.

Elevation Removal.png

0 Likes
Message 4 of 22

ronjonp
Mentor
Mentor

Try something like this in a script or even use Lee's ODBX wrapper:

(defun c:foo ( / d)
  (vlax-for a (vla-get-blocks (setq d (vla-get-activedocument (vlax-get-acad-object))))
    (if	(wcmatch (vla-get-name a) "block*")
      (vlax-for	b a
	(and (vlax-write-enabled-p b)
	     (vlax-property-available-p b 'textstring)
	     (wcmatch (vla-get-textstring b) "EL.*'-*\"")
	     (vla-put-color b 1)
	     ;; Uncomment one of the the lines below to remove the text .. line above is a
	     ;; visual check for you to make sure this is what you want
	     ;; (vla-delete b)
	)
      )
    )
  )
  (vla-regen d acActiveViewport)
  (princ)
)
(vl-load-com)

 

0 Likes
Message 5 of 22

maratovich
Advisor
Advisor

Use this:

https://www.kdmsoft.net/autoviewport.html

 

ReplaceAtr.png

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 6 of 22

tstorzuk
Advocate
Advocate

Maratovich,

 

Thanks for the suggestion, but that won't work. They aren't attributes. Just text within the blocks.

0 Likes
Message 7 of 22

tstorzuk
Advocate
Advocate

Rperez,

 

Just copying files to a new folder to test this out on. I'll let you know how it goes tomorrow.

0 Likes
Message 8 of 22

tstorzuk
Advocate
Advocate

Ugh, I don't know VLA!!!

 

I haven't been able to figure out how to hack this together to get it to work. And I don't know how to proceed. A push in the right direction would be appreciated.

0 Likes
Message 9 of 22

maratovich
Advisor
Advisor

I can modify the program
Give me an example of your file.
Specify what and what to replace. For check.

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 10 of 22

tstorzuk
Advocate
Advocate

Maratovich,

 

See my second post. It has a sample drawing and shows an image of what part needs to be removed.

0 Likes
Message 11 of 22

maratovich
Advisor
Advisor

Use this:

Replace Text in many files.png

 

 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 12 of 22

tstorzuk
Advocate
Advocate

Maratovich,

 

Your example shows that it requires exact text (EL.112'-3"). Will it work using Wildcards, like what I requested in my first post;

EL.###'-## ##/##"
EL.###'-## #/##"
EL.###'-## #/#"
EL.###'-##"
EL.###'-# ##/##"
EL.###'-# #/##"
EL.###'-# #/#"
EL.###'-#"
EL.##'-## ##/##"
EL.##'-## #/##"
EL.##'-## #/#"
EL.##'-##"
EL.##'-# ##/##"
EL.##'-# #/##"
EL.##'-# #/#"
EL.##'-#"

 

The actual numbers will vary from drawing to drawing. Hence the need for so many different iterations of possible combinations.

0 Likes
Message 13 of 22

ronjonp
Mentor
Mentor
Accepted solution

@tstorzuk wrote:

Ugh, I don't know VLA!!!

 

I haven't been able to figure out how to hack this together to get it to work. And I don't know how to proceed. A push in the right direction would be appreciated.


You should not need to hack anything together, just make sure the code is loaded and run it from within your script.

(defun deleteelevs (/ d)
  (vlax-for a (vla-get-blocks (setq d (vla-get-activedocument (vlax-get-acad-object))))
    (if	(wcmatch (vla-get-name a) "block*")
      (vlax-for	b a
	(and (vlax-write-enabled-p b)
	     (vlax-property-available-p b 'textstring)
	     (wcmatch (vla-get-textstring b) "EL.*'-*\"")
	     ;; (vla-put-color b 1)
	     (vla-delete b)
	)
      )
    )
  )
  (vla-regen d acactiveviewport)
  (princ)
)
(vl-load-com)
;; This line will run the code above .. please test first!
(deleteelevs)
0 Likes
Message 14 of 22

maratovich
Advisor
Advisor
What are wildcards? I do not understand what exactly you want. I wrote to you last time - give a real example. Do you want to guess on tarot cards? Give a real example.
---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 15 of 22

tstorzuk
Advocate
Advocate

Rperez,

 

You are correct. I don't need to hack anything together. This code does work amazingly well when testing on individual files. Thank you so much for putting this together for me. Smiley Very Happy

 

I misspoke. I'm having a problem to get Lee's ODBX Wrapper to function. That's a completely separate issue.

 

I've been going through the forums to try and figure out the coding for getting Lee's Wrapper to run with your code. I'm missing something (probably very obvious), and can't figure it out. I'll keep searching for an answer today. If I don't find it, I'll go the scripting route instead.

0 Likes
Message 16 of 22

ronjonp
Mentor
Mentor
Use the attached code along with Lee's ODBX code from his site ( link in my code ) .. this should batch what you want.
Message 17 of 22

tstorzuk
Advocate
Advocate
Trying to test your code using the Wrapper, inputting this for the function syntax; (LM:ODBX deleteelevs) AutoCAD keeps telling me that I have too few arguments. The syntax listed on Lee's site states; (LM:ODBX [lst] [sav]) Where both lst and sav are optional (AKA not required). However I'm unable to get it to run for a test run.
0 Likes
Message 18 of 22

tstorzuk
Advocate
Advocate
Ahh, I see the problem in the supplied LISP. I knew it had to be something simple that I was missing!! THANKS!!!! I'll test this ASAP!!!!
0 Likes
Message 19 of 22

tstorzuk
Advocate
Advocate

Rperez,

 

Would it be hard to change this a little bit? Instead of deleting the "El.*'-*\"" text string, replace it with "EL. FIELD"?

 

Like I mentioned, I don't know VLA at all. I can sort of understand what's going on when reading it, but know none of the commands.

0 Likes
Message 20 of 22

Sea-Haven
Mentor
Mentor

Something like this

 

(defun setelblank ( / ss x)
(setq ss (ssget "X" (list (cons 0 "Insert")))) (repeat (setq x (sslength ss)) (if (/= (setq atts (vlax-invoke (vlax-ename->vla-object (ssname SS (setq x (- x 1) ))) 'getattributes)) nil) (foreach att atts (if ( = (substr (strcase(vla-get-textstring att)) 1 2) "EL") (vla-put-textstring att "EL") ) ) ) )
)

 look at Lee's example 2 

0 Likes