Ruli Posted February 6, 2014 Posted February 6, 2014 Hei. Im looking for a routine that replaces selected blocks. In addition i want the replaced blocks to have the same attributevalue as the old blocks. The blocks have the same attributes. I have found many routines that replaces selected blocks, but they all overwrites the original attribute values. Quote
resullins Posted February 6, 2014 Posted February 6, 2014 Why wouldn't you just reimport and redefine the block? Quote
Ruli Posted February 6, 2014 Author Posted February 6, 2014 The blocks are a part of a schematic. I only want to change selected instanses of blocks and the attributes should not be overwritten. I have made a video to better illustrate what i mean: https://dl.dropboxusercontent.com/u/18606927/Replace.wmv I want the blocks to remenber its attributes, so I dont have to change it back. Quote
steven-g Posted February 6, 2014 Posted February 6, 2014 Can you post an example of the block to be replaced (with the attributes you want to keep) and the block that will replace it. There is too much info in that video to see what is going on. Quote
bababarghi Posted February 6, 2014 Posted February 6, 2014 (edited) Hei.Im looking for a routine that replaces selected blocks. In addition i want the replaced blocks to have the same attributevalue as the old blocks. The blocks have the same attributes. I have found many routines that replaces selected blocks, but they all overwrites the original attribute values. I am achieving the same goal you are persuing simply by following these steps: - Select all your desired blocks to be replaced; - Type ATTOUT ('export attributes' feature of Express Tools) to export selected blocks' attributes only; - Try to load this LISP (credit goes to alanjt) and replace your selected blocks. The attributes may disappear (don't panic) FYI. As mentioned by alanjt, you need this function as well. - [optional:] if you feel any difference in attribute order or prompt, you can simply edit the text file containing previously exported attributes. - Type ATTIN ('import attributes' feature of Express Tools) and bring your attributes back. It works fine for me Edited February 6, 2014 by bababarghi Typos Quote
David Bethel Posted February 7, 2014 Posted February 7, 2014 (edited) Although I have nothing to test this with, it should work: [b][color=BLACK]([/color][/b]defun c:rpb [b][color=FUCHSIA]([/color][/b]/ rb 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 rb[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]snvalid rb[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]or [b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]tblsearch [color=#2f4f4f]"BLOCK"[/color] rb[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]findfile [b][color=RED]([/color][/b]strcat rb [color=#2f4f4f]".DWG"[/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 rb [b][color=MAROON]([/color][/b]strcase [b][color=GREEN]([/color][/b]getstring [color=#2f4f4f]"\nReplacement BLOCK Name: "[/color][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]if [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]tblsearch [color=#2f4f4f]"BLOCK"[/color] rb[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]command [color=#2f4f4f]"_.INSERT"[/color] rb[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]command[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]/= [b][color=MAROON]([/color][/b]logand [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 70 [b][color=RED]([/color][/b]tblsearch [color=#2f4f4f]"BLOCK"[/color] rb[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] 2[b][color=MAROON])[/color][/b] 2[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]alert [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"Replacement BLOCK "[/color] rb [color=#2f4f4f]" Must Have Attributes"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]princ [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"\nSelect INSERTs To Replace With "[/color] rb[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]setq ss [b][color=BLUE]([/color][/b]ssget [b][color=RED]([/color][/b]list [b][color=PURPLE]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=PURPLE])[/color][/b][b][color=PURPLE]([/color][/b]cons 66 1[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]cons 2 [b][color=TEAL]([/color][/b]strcat [color=#2f4f4f]"~"[/color] rb[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq i 0[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]while [b][color=BLUE]([/color][/b]setq en [b][color=RED]([/color][/b]ssname ss i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]setq ed [b][color=RED]([/color][/b]entget en[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]entmod [b][color=RED]([/color][/b]subst [b][color=PURPLE]([/color][/b]cons 2 rb[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]assoc 2 ed[b][color=PURPLE])[/color][/b] ed[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [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=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 Edited February 7, 2014 by David Bethel Quote
bababarghi Posted February 9, 2014 Posted February 9, 2014 David, don't you think following highlighted lines are in contradict? (while (or (not rb) (not (snvalid rb)) (or ([color="red"]not (tblsearch "BLOCK" rb[/color])) (not (findfile (strcat rb ".DWG"))))) (setq rb (strcase (getstring "\nReplacement BLOCK Name: ")))) [color="red"](if (not (tblsearch "BLOCK" rb)) (progn (command "_.INSERT" rb) (command) ) )[/color] Although I have nothing to test this with, it should work: [b][color=BLACK]([/color][/b]defun c:rpb [b][color=FUCHSIA]([/color][/b]/ rb 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 rb[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]snvalid rb[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]or [b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]tblsearch [color=#2f4f4f]"BLOCK"[/color] rb[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]findfile [b][color=RED]([/color][/b]strcat rb [color=#2f4f4f]".DWG"[/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 rb [b][color=MAROON]([/color][/b]strcase [b][color=GREEN]([/color][/b]getstring [color=#2f4f4f]"\nReplacement BLOCK Name: "[/color][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]if [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]tblsearch [color=#2f4f4f]"BLOCK"[/color] rb[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]command [color=#2f4f4f]"_.INSERT"[/color] rb[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]command[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]/= [b][color=MAROON]([/color][/b]logand [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 70 [b][color=RED]([/color][/b]tblsearch [color=#2f4f4f]"BLOCK"[/color] rb[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] 2[b][color=MAROON])[/color][/b] 2[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]alert [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"Replacement BLOCK "[/color] rb [color=#2f4f4f]" Must Have Attributes"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]princ [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"\nSelect INSERTs To Replace With "[/color] rb[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]setq ss [b][color=BLUE]([/color][/b]ssget [b][color=RED]([/color][/b]list [b][color=PURPLE]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=PURPLE])[/color][/b][b][color=PURPLE]([/color][/b]cons 66 1[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]cons 2 [b][color=TEAL]([/color][/b]strcat [color=#2f4f4f]"~"[/color] rb[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq i 0[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]while [b][color=BLUE]([/color][/b]setq en [b][color=RED]([/color][/b]ssname ss i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]setq ed [b][color=RED]([/color][/b]entget en[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]entmod [b][color=RED]([/color][/b]subst [b][color=PURPLE]([/color][/b]cons 2 rb[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]assoc 2 ed[b][color=PURPLE])[/color][/b] ed[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [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=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
David Bethel Posted February 10, 2014 Posted February 10, 2014 If the replacement block is an external dwg reference, then it must be INSERTed into the current drawing to record the definition into the BLOCK table. Otherwise, the (entmod) call will fail. -David 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.