PDA

View Full Version : Block Replacement


jmctamney
2005-10-25, 03:02 PM
I'm looking for a good way to replace a user defined number of blocks with another block. Example. changing column sizes in plan. Everything I have and can find replaces all instances instead of just ones the user defines. Any ideas? Thanks.

Opie
2005-10-25, 03:14 PM
Try this.
(defun C:REPLACEBLOCK ()
(setq OLDBLOCK (entget (car (entsel "\nPick block to replace: ")))
NEWBLOCK (getstring "\nSpecify replacement block: ")
)
(command "-insert" NEWBLOCK NIL)
(setq
OLDBLOCK (subst (cons 2 NEWBLOCK) (assoc 2 OLDBLOCK) OLDBLOCK)
)
(entmod OLDBLOCK)
(entupd (cdr (assoc -1 OLDBLOCK)))
)

This is untested. The newblock must be located within the drawing or within the AutoCAD support paths. This can be modified to provide the dialog box.

Edit: remind me to test first ;)

ccowgill
2005-10-25, 03:18 PM
If you have Express tools, you can always use the replace block command, It will allow you to select a block, and replace all occurances of that block with a new block that you select, whether the names are the same or not.

Opie
2005-10-25, 03:21 PM
If you have Express tools, you can always use the replace block command, It will allow you to select a block, and replace all occurances of that block with a new block that you select, whether the names are the same or not.
He already stated that he was able to replace all instances of a block with a different block. He was wanting to replace one instance with another block.

jmctamney
2005-10-25, 03:27 PM
Ok, I've tried it and this is what I get when I pick the block I want replaced

Pick block to replace: ; error: bad argument type: stringp <Entity name:
7efd8270>

Any ideas? I'm at a total loss when it comes to visual lisp.

ccowgill
2005-10-25, 03:31 PM
He already stated that he was able to replace all instances of a block with a different block. He was wanting to replace one instance with another block.

sorry about that, I didnt quite understand his question.

Opie
2005-10-25, 03:43 PM
See my revised code above.

jmctamney
2005-10-25, 04:01 PM
SWEET!!!!! Thanks, this will be a big time saver