cbriana Posted March 31, 2009 Posted March 31, 2009 Some of the drawings that my company receives from others often have blocks that all should be defined the same, but they instead have a number at the end of the block name. For example we got a drawing that had 93 dimension arrows, all of them defines as their own block; AHT1, AHT2, AHT3, ... AHT93 We want them all to be just "AHT" The "blockreplace" command only lets you change one at a time. The "rblock" lisp that i found lets you pick multiple except you have to actually pick them in the drawing. (the rblock lisp isn't ideal because there are usually many blocks all on the same layer, some arrow heads, some symbols, etc.) I was hopping to find a way to select many blocks from the list of defined blocks and replace them all at once. Thanks in advance, Chris Quote
Lee Mac Posted March 31, 2009 Posted March 31, 2009 Perhaps this? (defun c:brep (/ ss doc spc i j) (vl-load-com) (if (or (tblsearch "BLOCK" "AHT") (findfile "AHT.dwg")) (progn (if (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 "AHT*") (if (getvar "CTAB")(cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE"))))))) (progn (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc)) i 0 j 0) (vla-EndUndoMark doc) (vla-StartUndoMark doc) (foreach ent (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))) (vla-insertblock spc (vla-get-InsertionPoint ent) "AHT" (vla-get-xscalefactor ent) (vla-get-yscalefactor ent) (vla-get-zscalefactor ent) (vla-get-rotation ent)) (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-delete (list ent))) (setq i (1+ i)) (setq j (1+ j)))) (princ (strcat "\n" (itoa j) " Blocks Replaced" (if (zerop i) "." (strcat (itoa i) " were on a Locked Layer!")))) (vla-EndUndoMark doc)) (princ "\n<!> No Blocks Found <!>"))) (princ "\n<!> Replacement Block not Found <!>")) (princ)) Quote
AQucsaiJr Posted January 19, 2010 Posted January 19, 2010 I am having this same problem. I tried your program Lee but I guess I don't understand how it works. Do I need to change the "AHT" throughout the program to the block name I want to replace? Quote
AQucsaiJr Posted January 19, 2010 Posted January 19, 2010 I have a drawing that has ARROW1-ARROW###. Originally, in microstations, it was just ARROW, and was rotated and copied to fit the needs of the drawing, however AutoCAD assumed it was individual blocks and renamed each instance by adding a number on the suffix. There are quite a few of them in the drawing so using the Block Replace tool in the express menu is out of the question. Quote
AQucsaiJr Posted January 19, 2010 Posted January 19, 2010 I dont think I really answered your question fully... I want there to end up being just one block, ARROW. But I don't want to change the orientation or color of the other instances, just want them all named ARROW. Quote
David Bethel Posted January 20, 2010 Posted January 20, 2010 This should do the trick: [b][color=BLACK]([/color][/b]defun c:rblk [b][color=FUCHSIA]([/color][/b]/ pre nb ss i en ed[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]or [b][color=MAROON]([/color][/b]not pre[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]snvalid pre[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq pre [b][color=MAROON]([/color][/b]getstring [color=#2f4f4f]"\nExisting BLOCKs Name Prefix: "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not nb[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq nb [b][color=MAROON]([/color][/b]getstring [color=#2f4f4f]"\nNew BLOCK Name: "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]cond [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]snvalid nb[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq nb nil[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]tblsearch [color=#2f4f4f]"BLOCK"[/color] nb[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]findfile [b][color=BLUE]([/color][/b]strcat nb [color=#2f4f4f]".DWG"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]command [color=#2f4f4f]"_.INSERT"[/color] nb[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]command[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]T [b][color=GREEN]([/color][/b]setq nb nil[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons 2 [b][color=RED]([/color][/b]strcat pre [color=#2f4f4f]"*"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq i [b][color=MAROON]([/color][/b]sslength ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]minusp [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1- i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss i[b][color=GREEN])[/color][/b] ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]entmod [b][color=GREEN]([/color][/b]subst [b][color=BLUE]([/color][/b]cons 2 nb[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]assoc 2 ed[b][color=BLUE])[/color][/b] ed[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]entupd en[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David Quote
AQucsaiJr Posted January 20, 2010 Posted January 20, 2010 This should do the trick: [b][color=BLACK]([/color][/b]defun c:rblk [b][color=FUCHSIA]([/color][/b]/ pre nb ss i en ed[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]or [b][color=MAROON]([/color][/b]not pre[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]snvalid pre[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq pre [b][color=MAROON]([/color][/b]getstring [color=#2f4f4f]"\nExisting BLOCKs Name Prefix: "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not nb[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq nb [b][color=MAROON]([/color][/b]getstring [color=#2f4f4f]"\nNew BLOCK Name: "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]cond [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]snvalid nb[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq nb nil[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]tblsearch [color=#2f4f4f]"BLOCK"[/color] nb[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]findfile [b][color=BLUE]([/color][/b]strcat nb [color=#2f4f4f]".DWG"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]command [color=#2f4f4f]"_.INSERT"[/color] nb[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]command[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]T [b][color=GREEN]([/color][/b]setq nb nil[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons 2 [b][color=RED]([/color][/b]strcat pre [color=#2f4f4f]"*"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq i [b][color=MAROON]([/color][/b]sslength ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]minusp [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1- i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss i[b][color=GREEN])[/color][/b] ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]entmod [b][color=GREEN]([/color][/b]subst [b][color=BLUE]([/color][/b]cons 2 nb[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]assoc 2 ed[b][color=BLUE])[/color][/b] ed[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]entupd en[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David I think this is going in the right direction but I am unsure how to get it to run... I loaded the program, initiated the program, gave it the existing prefix, but then it just keeps asking for the new block name. Am I missing something? is this how it is supposed to work? It seems like it gets stuck on the new name because it wont stop asking for it and there does not seem to be any errors. Quote
Lee Mac Posted January 20, 2010 Posted January 20, 2010 The Block Name needs to be valid, and the New block definition must be present in the drawing/in the support path. Quote
AQucsaiJr Posted January 20, 2010 Posted January 20, 2010 The Block Name needs to be valid, and the New block definition must be present in the drawing/in the support path. ok so the block that I am trying fix has the prefix ARROW... it starts at ARROW1 and goes up from there... So if I am reading this correctly I can replace blocks ARROW2-ARROW### with ARROW1 since it exists in the drawing? Quote
David Bethel Posted January 20, 2010 Posted January 20, 2010 The Block Name needs to be valid, and the New block definition must be present in the drawing/in the support path. Exactly, or the replacement BLOCK must at least exist in the current drawing. -David Quote
AQucsaiJr Posted January 20, 2010 Posted January 20, 2010 Exactly, or the replacement BLOCK must at least exist in the current drawing. -David Got it to work... I do have a question though... Is there a way to get them to replace and keep the same orientation? I replaced all the ARROW blocks to ARROW1, but now all of them took on the orientation and color of ARROW1. I understand if this can not be done. This tool will help me out greatly in its current form. Just thought I would ask. Quote
David Bethel Posted January 20, 2010 Posted January 20, 2010 With the exception of the BLOCK name, the INSERT will retain all of the data contained in the original INSERT. We are basically just changing the BLOCK names. INSERT rotation, scale, layer, point, scales, UCS, color, linetype etc are not affected. Now if the BLOCK definitions have different orientations, then that's a different story. And quite hard to reconcile. Nested entity characteristics are in the same boat. -David Quote
AQucsaiJr Posted January 20, 2010 Posted January 20, 2010 This is part of the file I am working on... I am not sure how to explain what is going on without an example. exapmle.dwg Quote
David Bethel Posted January 20, 2010 Posted January 20, 2010 The arrow BLOCKs vary quite a bit. -David ARROW-EX.DWG Quote
AQucsaiJr Posted January 20, 2010 Posted January 20, 2010 I see... So then yes... Your program works perfect... I see how it would be quite a bit of work to keep all the orientations the same, but I just need one common block and that's what you have given me... I can team up with someone here in the office to fix the aesthetics... Thank you very much David. Quote
Lee Mac Posted January 20, 2010 Posted January 20, 2010 You could create a new block using contents of the Arrow block, at an orientation that suits, then use Davids code to replace. Quote
AQucsaiJr Posted January 20, 2010 Posted January 20, 2010 I guess ill have to tinker around with that suggestion and see what I can do. Quote
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.