Hi there,
I've found a .lsp that does nearly what I require. I don't suppose anyone could give me a hand adapting it?
The lisp that I've got allows you to identify a block, and have another block replace it.
Is it possible to adapt this lisp to allow you to select multiple target blocks to be overwritten?
(defun c:rblk (/ pre nb ss i en ed) (while (or (not pre) (not (snvalid pre))) (setq pre (getstring "\nExisting BLOCKs Name Prefix: "))) (while (not nb) (setq nb (getstring "\nNew BLOCK Name: ")) (cond ((not (snvalid nb)) (setq nb nil)) ((tblsearch "BLOCK" nb)) ((findfile (strcat nb ".DWG")) (command "_.INSERT" nb) (command)) (T (setq nb nil)))) (and (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 (strcat pre "*"))))) (setq i (sslength ss)) (while (not (minusp (setq i (1- i)))) (setq en (ssname ss i) ed (entget en)) (entmod (subst (cons 2 nb) (assoc 2 ed) ed)) (entupd en))) (prin1))
In this particular instance, I'm trying to have multiple different door symbols in a 2D plan overwritten with a uniform marker. If that helps at all.
Many thanks in advance!
Hi there, thanks for the reply.
What I'd ideally like to do, is replace many different blocks over numerous insertions.
For instance,
I'd like to replace all instances of block "Door1.dwg.", "Door2.dwg" and "Door3.dwg" with instances of "Door4.dwg"
Turning a variety of shapes into one shape. Does that make sense?
If you'll excuse this childlike example...
Assuming each different shape is a different block loaded into my current drawing.
unfortunately, owing to what I assume is purchased library blocks by the op that drew the file, all of these blocks have seemingly random strings for names.
But for future reference, could I type something like: *door*
to include all blocks that have door contained in the block name?
Finally, I can't seem to enter any block names that contain a space. Foolishly, perhaps, I've assigned one of my blocks a space in it's name...
Ideally what I'd like is something akin to REPLACEBLOCK, where I could select as many blocks to be replaced and give them all the same block to be inserted.
@Anonymous wrote:
...
But for future reference, could I type something like: *door*to include all blocks that have door contained in the block name?
...
Yes, you can but only as prefix - that means that block names could be "door123", but not "123door"
@Anonymous wrote:
...
Finally, I can't seem to enter any block names that contain a space. Foolishly, perhaps, I've assigned one of my blocks a space in it's name...
....
You need to add T to second GETSTRING, then you will be able to include spaces in new block name, you just have to end name input with Enter key (not Spacebar):
(defun c:rblk (/ pre nb ss i en ed) (while (or (not pre) (not (snvalid pre))) (setq pre (getstring "\nExisting BLOCKs Name Prefix: "))) (while (not nb) (setq nb (getstring T "\nNew BLOCK Name: ")) (cond ((not (snvalid nb)) (setq nb nil)) ((tblsearch "BLOCK" nb)) ((findfile (strcat nb ".DWG")) (command "_.INSERT" nb) (command)) (T (setq nb nil)))) (and (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 (strcat pre "*"))))) (setq i (sslength ss)) (while (not (minusp (setq i (1- i)))) (setq en (ssname ss i) ed (entget en)) (entmod (subst (cons 2 nb) (assoc 2 ed) ed)) (entupd en))) (prin1))
And, of course it is possible to adopt existing Lisp to allow user to select which blocks to replace, but this is another, little bit more complex task.
Maxim
Also, upon reading around. My lisp performs this function already.
Ideally what I need is the ability to target multiple blocks, each with different names.
for example, I have a dwg with 4 door blocks in it. These are called:
The prefixing method here just won't work, because as you can see, they're all vastly different.