alanjt Posted July 11, 2013 Share Posted July 11, 2013 Do you have a similar routine that wors with attributes? I often have to change (blocks with attributes) parts of my drawing from proposed to existing. The blocks are the same except for color and font style. Thanks So, you want to replace one attribute block with another and transfer attribute values from the original block to the replacement? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 11, 2013 Share Posted July 11, 2013 Do you have a similar routine that wors with attributes? I often have to change (blocks with attributes) parts of my drawing from proposed to existing. The blocks are the same except for color and font style. Thanks Rename block references to use new block definition; ATTSYNC to synchronise attributes (assuming attribute tags are identical). Done! Quote Link to comment Share on other sites More sharing options...
alanjt Posted July 11, 2013 Share Posted July 11, 2013 Rename block references to use new block definition; ATTSYNC to synchronise attributes (assuming attribute tags are identical). Done! And you are wanting to replace all instances of said block. Quote Link to comment Share on other sites More sharing options...
Guest Posted December 1, 2013 Share Posted December 1, 2013 (defun c:BRE (/ *error* blk f ss temp) ;; Replace multiple instances of selected blocks (can be different) with selected block ;; Size and Rotation will be taken from original block and original will be deleted ;; Required subroutines: AT:GetSel ;; Alan J. Thompson, 02.09.10 (vl-load-com) (defun *error* (msg) (and f *AcadDoc* (vla-endundomark *AcadDoc*)) (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,"))) (princ (strcat "\nError: " msg)) ) ) (if (and (AT:GetSel entsel "\nSelect replacement block: " (lambda (x / e) (if (and (eq "INSERT" (cdr (assoc 0 (setq e (entget (car x)))))) (/= 4 (logand (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 e))))) 4)) (/= 4 (logand (cdr (assoc 70 (entget (tblobjname "LAYER" (cdr (assoc 8 e)))))) 4)) ) (setq blk (vlax-ename->vla-object (car x))) ) ) ) (princ "\nSelect blocks to be repalced: ") (setq ss (ssget "_:L" '((0 . "INSERT")))) ) (progn (setq f (not (vla-startundomark (cond (*AcadDoc*) ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) ) ) ) ) (vlax-for x (setq ss (vla-get-activeselectionset *AcadDoc*)) (setq temp (vla-copy blk)) (mapcar (function (lambda (p) (vl-catch-all-apply (function vlax-put-property) (list temp p (vlax-get-property x p)) ) ) ) '(Insertionpoint Rotation XEffectiveScaleFactor YEffectiveScaleFactor ZEffectiveScaleFactor ) ) (vla-delete x) ) (vla-delete ss) (*error* nil) ) ) (princ) ) (defun AT:GetSel (meth msg fnc / ent good) ;; meth - selection method (entsel, nentsel, nentselp) ;; msg - message to display (nil for default) ;; fnc - optional function to apply to selected object ;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC"))) ;; Alan J. Thompson, 05.25.10 (setvar 'errno 0) (while (not good) (setq ent (meth (cond (msg) ("\nSelect object: ") ) ) ) (cond ((vl-consp ent) (setq good (cond ((or (not fnc) (fnc ent)) ent) ((prompt "\nInvalid object!")) ) ) ) ((eq (type ent) 'STR) (setq good ent)) ((setq good (eq 52 (getvar 'errno))) nil) ((eq 7 (getvar 'errno)) (setq good (prompt "\nMissed, try again."))) ) ) ) Nice work alanjt . Can you update your code to replace selected instances of a block (or blocks) with another block, sync attributes. Quote Link to comment Share on other sites More sharing options...
VIGNESH Posted January 21, 2014 Share Posted January 21, 2014 i need to replace one block with another block with same coordinates. pls. somebody give LISP program. If i run that program, without opening any of drawings, in the drawing directory it should replace all blocks with what i have selected and should replace all blocks. it will be agreat help for me Quote Link to comment Share on other sites More sharing options...
allent392 Posted July 31, 2014 Share Posted July 31, 2014 Continue to read the thread and you will find a lisp routine that works great.. The command prompt is BRE... Quote Link to comment Share on other sites More sharing options...
allent392 Posted July 31, 2014 Share Posted July 31, 2014 The BRE routine has saved me hours of work!!! Thank You! Quote Link to comment Share on other sites More sharing options...
supaman Posted February 13, 2015 Share Posted February 13, 2015 "Error: no function definition: VLAX-ENAME->VLA-OBJECT" Hi, I got this error when use it like justtindm. Previous time it still work ok but I don't know today I got this error. Does it work correctly with att block? (defun c:BRE (/ *error* blk f ss temp) ;; Replace multiple instances of selected blocks (can be different) with selected block ;; Size and Rotation will be taken from original block and original will be deleted ;; Required subroutines: AT:GetSel ;; Alan J. Thompson, 02.09.10 (vl-load-com) (defun *error* (msg) (and f *AcadDoc* (vla-endundomark *AcadDoc*)) (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,"))) (princ (strcat "\nError: " msg)) ) ) (if (and (AT:GetSel entsel "\nSelect replacement block: " (lambda (x / e) (if (and (eq "INSERT" (cdr (assoc 0 (setq e (entget (car x)))))) (/= 4 (logand (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 e))))) 4)) (/= 4 (logand (cdr (assoc 70 (entget (tblobjname "LAYER" (cdr (assoc 8 e)))))) 4)) ) (setq blk (vlax-ename->vla-object (car x))) ) ) ) (princ "\nSelect blocks to be repalced: ") (setq ss (ssget "_:L" '((0 . "INSERT")))) ) (progn (setq f (not (vla-startundomark (cond (*AcadDoc*) ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) ) ) ) ) (vlax-for x (setq ss (vla-get-activeselectionset *AcadDoc*)) (setq temp (vla-copy blk)) (mapcar (function (lambda (p) (vl-catch-all-apply (function vlax-put-property) (list temp p (vlax-get-property x p)) ) ) ) '(Insertionpoint Rotation XEffectiveScaleFactor YEffectiveScaleFactor ZEffectiveScaleFactor ) ) (vla-delete x) ) (vla-delete ss) (*error* nil) ) ) (princ) ) (defun AT:GetSel (meth msg fnc / ent good) ;; meth - selection method (entsel, nentsel, nentselp) ;; msg - message to display (nil for default) ;; fnc - optional function to apply to selected object ;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC"))) ;; Alan J. Thompson, 05.25.10 (setvar 'errno 0) (while (not good) (setq ent (meth (cond (msg) ("\nSelect object: ") ) ) ) (cond ((vl-consp ent) (setq good (cond ((or (not fnc) (fnc ent)) ent) ((prompt "\nInvalid object!")) ) ) ) ((eq (type ent) 'STR) (setq good ent)) ((setq good (eq 52 (getvar 'errno))) nil) ((eq 7 (getvar 'errno)) (setq good (prompt "\nMissed, try again."))) ) ) ) Quote Link to comment Share on other sites More sharing options...
supaman Posted February 13, 2015 Share Posted February 13, 2015 Hi, I reset the computer then it work well again. thank you, it's very cool The problem may be cause when I load many lisp and it conflict with each other. Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 13, 2015 Share Posted February 13, 2015 If the code is already posted in the thread, please don't post it again. If I ever update the code, an older version will still reside in a post I cannot edit. Glad you got it working. Add (vl-load-com) before or after the code. I have that in my startup file, so I have a tendency to forget to add it to commands. Apologies. Quote Link to comment Share on other sites More sharing options...
mauione Posted March 23, 2015 Share Posted March 23, 2015 I have been looking and have not yet found what I am looking for. I have blocks that come from MicroStation into ACAD. When they come to ACAD, they have the same name, however they also have a sequential suffix. (I.E. MH1, MH2,...) I have found a lisp that will allow me to replace all "MH#" with MH, but only one type at a time. (MH#; then run the lisp again and do LP#, etc...). What I am getting at I would like to eventually have one lisp that will basically be, if (XXX## equal true, then replace with XXX) and do this for each type block type. I have no problem adding to a routine or building it. I really do not know where to get started. Thank you for your time and patience in this. rblk.lsp is what I have found for one by one- just a step above REPLACEBLOCK command. rblk.lsp Quote Link to comment Share on other sites More sharing options...
BlackBox Posted March 23, 2015 Share Posted March 23, 2015 I have been looking and have not yet found what I am looking for. I have blocks that come from MicroStation into ACAD. When they come to ACAD, they have the same name, however they also have a sequential suffix.(I.E. MH1, MH2,...) I have found a lisp that will allow me to replace all "MH#" with MH, but only one type at a time. (MH#; then run the lisp again and do LP#, etc...). What I am getting at I would like to eventually have one lisp that will basically be, if (XXX## equal true, then replace with XXX) and do this for each type block type. I have no problem adding to a routine or building it. I really do not know where to get started. Thank you for your time and patience in this. rblk.lsp is what I have found for one by one- just a step above REPLACEBLOCK command. Welcome to CADTutor. I don't have time to read the earlier pages of this thread, which may already have an answer for you, but this recent thread may be of use: http://forums.augi.com/showthread.php?160855-Change-a-Block-to-another-Block Cheers Quote Link to comment Share on other sites More sharing options...
cad tutor Posted August 19, 2015 Share Posted August 19, 2015 hi friend, How can i convert layer in multiple blocks to layer "0". Thanks! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 19, 2015 Share Posted August 19, 2015 hi friend,How can i convert layer in multiple blocks to layer "0". Thanks! Try the example program from my Apply to Block Objects function. Quote Link to comment Share on other sites More sharing options...
iconeo Posted October 9, 2015 Share Posted October 9, 2015 Thanks Alan. Quote Link to comment Share on other sites More sharing options...
bhOOVER84 Posted October 18, 2016 Share Posted October 18, 2016 Hey Guys, I'm very new to CAD but I am a really fast learner as I am sure many of you are. I have added this LSP into our cad and it has worked magically; however, I am having an issue for some unknown reason and I was hoping someone could point out to me what the issue may be. I am designing a lighting blueprint for an engineering firm. We have several blocks for 2x4 normal, emergency lights and all other various sizes. I have had the BRE command work perfectly for our 1/2x4 blocks which has saved me a lot of time of deleting and replacing the block. When I attempt to use the BRE command on the 2x4 blocks, the end result deletes the block "TO BE" replaced. Is there an issue with my blocks? Here are some of the troubleshooting I have already attempted. - I have created now blocks, saved with new names and replaced ALL blocks on the model with the new named block. Same result. - I have edited the blocks and changed the current layer for each item within the block. Same result. Any ideas? Also, not sure if this matters. I am currently working on AutoCad 2017 Thanks for any attempts to assist. Bryan Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted October 18, 2016 Share Posted October 18, 2016 Blocks are indeed deleted as part of the replacement process. Without an example dwg I can only guess that the blocks are mismatched in terms of scale or insertion point. Try zooming to extents after using the code. Quote Link to comment Share on other sites More sharing options...
mruu Posted October 9, 2019 Share Posted October 9, 2019 Is there a line in this code that can be changed ever so slightly so that each replaced block might be able to keep their old attributes?? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.