Jump to content

Replace all old blocks with prefixed "modified_" new blocks


shailujp

Recommended Posts

Hello,

 

I ran into a unique issue today with mass renamed blocks done by RENBLKS (a great lisp created by Tharwat) and existing old blocks and I spent few hours to replace old blocks with new ones using BLOCKREPLACE command.

 

So, here is what happened. When I want to create a new version of the same concept, I copy blocks (which has a huge nested tree) in a new drawing, add prefix "modified_" using RENBLKS to rename all blocks, bring it back into original drawing, now I have two versions OLD & NEW.

 

Somewhere, I mixed-up old blocks and new blocks and want to get rid old ones using BLOCKREPLACE express tool utility. My layout is huge around 90MB and takes about 3 to 4 minutes to replace one block at a time and about 15 to 20 blocks to replace. Also, to be able to use BLOCKREPLACE, I had to explode all nested blocks to be able to pick just the desired block.

 

Here is my question, is there a lisp which can replace a complete list of blocks which has a same name as old but with "modified_" as prefix at once?

ex.

door1

modified_door1

door 2

modified_door2

 

Thanks

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • shailujp

    13

  • MSasu

    3

  • Tharwat

    3

  • steven-g

    2

Top Posters In This Topic

Posted Images

Since nobody replied to this, I'm trying this again hoping that someone might have answer to this. Is it possible to replace a list of old blocks with the same name new blocks but with prefix as "Modified_"?

Link to comment
Share on other sites

MSasu,

 

Thanks for your reply.

 

Just looking at this code, it seems like it requires selection of old block and then the new block. This is where I need help of a whole list of blocks replaced with the new list.

 

Is this possible?

Link to comment
Share on other sites

Maybe posting an example of the old and the modified blocks showing the nesting, would give someone an idea about how to approach this.

Link to comment
Share on other sites

I will post the example tomorrow. In the mean time I have copied a snap from Lee Mac website to explain it better.

 

There are 3 nested entities on this snap and have copied all of them with a new name with prefix "Modify_". Now when the design is finalized, not all new items go on the final version. So, if all my "modified nested 3" versions need to replace the "nested 3" I will have to explode all blocks to expose nested 3 & modified nested 3 to be able to pick & replace. And there are so many of this and my file size troubles me the most.

 

Does this explanation work for now?

Capture 1.JPG

Link to comment
Share on other sites

Without seeing the actual blocks, it's hard to give a definite answer but I just ran a simple test, I created a drawing with a nested block (3 levels) and made multiple copies of it. I then created a new drawing again with a nested block with the same names for the blocks but drawn completely differently, so the first drawing the blocks contained only squares, and in the second drawing they contained only circles. The second drawing only needs the one block this is the new style block (but keeps the old names). I then copied everything out of the first drawing into the second one, and all the blocks changed to the same style as the new block, you could then rename the blocks if you need too, and now use the new drawing which contains all the updated blocks.

I can imagine there may be other issues to deal with, so an example of your drawing would help. But it works and only takes seconds to update all the blocks.

Link to comment
Share on other sites

I hope someone sees this before I give up on this. Getting impatient but consider its only human.

Please don't miss that this isn't a develop-on-demand establishment!

May want to adjust the parts in blue to suit your case; just make sure that all layers were un-locked.

;;; Replace Blocks By List (20-III-2014)
(defun c:RBBL( / blockOld blockNew ssetBlocks entBlock assocBlock )
(foreach blockOld '("[color=blue]B1[/color]" "[color=blue]B2[/color]" "[color=blue]B3[/color]")   ;;;list of blocks to replace
 (if (and (tblsearch "BLOCK" blockOld)
          (tblsearch "BLOCK" (setq blockNew (strcat "modified_" blockOld))))
  (if (setq ssetBlocks (ssget "_X" (list '(0 . "INSERT") (cons 2 blockOld))))
   (while (> (sslength ssetBlocks) 0)
    (entmod (subst (cons 2 blockNew)
                   (assoc 2 (setq assocBlock (entget (setq entBlock (ssname ssetBlocks 0)))))
                   assocBlock))
    (ssdel entBlock ssetBlocks)
   )
  )
 )
)
(princ)
)

 

By the way, this doen't consider the nested blocks.

Link to comment
Share on other sites

Hi MSasu

Please don't miss that this isn't a develop-on-demand establishment!

 

Just politely asking for help and I know that most people like you are willing to help.

 

I tried your lisp and works well. But then there is this nested block issue is indeed the main culprit and thats the main reason for posting this thread. Could this be resolved?

 

Here is how I have tested it. Before and after snaps.

Before.jpg

After.jpg

Link to comment
Share on other sites

Hi ,

 

A few explanations before firing up Vlisp :lol:

 

You do want to replace a list of blocks with new list of new block names that have the same block name but with a prefix Modified_ word ?

Then you have nested blocks within the old block ( to be replaced ) to re-include them within the new replaced block name Which is Modified_ ?

 

If you can upload a sample drawing with one example before and after it would great .

Link to comment
Share on other sites

Please pay extreme attention that replacement of nested blocks may go very wrong if the order of block names in list isn't the appropriate one! Should start with lowest level blocks (that it, the deeper nested ones) and continue to the main level.

Link to comment
Share on other sites

Please pay extreme attention that replacement of nested blocks may go very wrong if the order of block names in list isn't the appropriate one! Should start with lowest level blocks (that it, the deeper nested ones) and continue to the main level.

 

I see what you are refering to...I think that I wont need to replace all the levels of blocks. It will be either the top level (which will cover all internals) or the bottom one which will be individual. The worst case is when I have to replace the bottom level ones which are difficult to access unless its exploded to brought to flat level.

 

Edit: Currently I'm looking for a way to extract (or manually copy pase) block names from the drawing. I saw Jeffery Sanders BLKTREE.lsp but it wont let me copy any text from the dialogue box. Still exploring on this.

Link to comment
Share on other sites

Why did you upload before and after and modified ?

What do you mean by modified ?

Are we talking about one nested block ?

 

Modifed_ shown in red is actually my source block and I want to replace some blocks from it to my target lower block. So, I showed what before and after in separate files so that you can make out the difference. Did I confuse this way? Yes one big nested block with a huge tree in it.

Link to comment
Share on other sites

You have so many blocks inside each other and that looks complicated , and it is not a matter of replacing one block with another with one nested block as I alluded to . sorry

Link to comment
Share on other sites

You have so many blocks inside each other and that looks complicated , and it is not a matter of replacing one block with another with one nested block as I alluded to . sorry

 

Yes so many blocks but this isnt the full block. I had to create a smaller version of the one huge block to be able to share it here. You can imagine my master file that is about 90 to 100 MB and number of such huge blocks and their difference versions on it.

 

No problem. Thanks for looking into this though.

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...