Jump to content

Replace selected blocks, rememer attribute value


Ruli

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 8)

Edited by bababarghi
Typos
Link to comment
Share on other sites

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 by David Bethel
Link to comment
Share on other sites

David, don't you think following highlighted lines are in contradict? :huh:

 

(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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...