Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Block merge/rename script

4 REPLIES 4
Reply
Message 1 of 5
dglenn9000
865 Views, 4 Replies

Block merge/rename script

When I export from Revit I end up with a lot of the same blocks

 

Linear Supply Diffuser - 4ft length - V223-M101

Linear Supply Diffuser - 4ft length - V421-M101

Linear Supply Diffuser - 4ft length - V151-M101

Linear Supply Diffuser - 4ft length - V631-M101

Round Duct Takeoff - Conical - Standard-V250-M101

Round Duct Takeoff - Conical - Standard-V60-M101

 

 

Is there a routine/script that will do a block search for *Linear Supply* , if that block exist, then take the first instance and replace all remaining blocks that contain *Linear Supply* with the first block instance it found.  I would end up with 1 block called "Round Duct Takeoff - Conical".

 

I know it seems like a bit much but I cant figure out another way to tackle this. The real problem is after export there are hundreds of Blocks all mostly the same. The client does not want 30 instances of the same block in a drawing.

 

Thanks

4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: dglenn9000


@dglenn9000 wrote:
....

Is there a routine/script that will do a block search for *Linear Supply* , if that block exist, then take the first instance and replace all remaining blocks that contain *Linear Supply* with the first block instance it found. ....



There may not be one, but there certainly could be....  I would add the renaming of that first-found Block name to whatever the common name content is alone, omitting all the part number stuff or whatever the rest of it is, so that all such Blocks in your example would end up named "Linear Supply" rather than something like "Linear Supply Diffuser - 4ft length - V223-M101" even though much of that won't be appropriate to many of them.  Try something like [untested]:

 

(vl-load-com)

(setq

  name (getstring "\nPartial Block name to become name of all Blocks whose names contain it: ")

  ss (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "*" name "*")))); all such Blocks/Minserts

); setq

(if ss ; found some?

  (progn ; then

    (command

      "_.rename" "_block"

      (vla-get-Name (vlax-ename->vla-object (ssname ss 0))); name of first such Block

      name ; reduce to common content only

    ); command

    (foreach blk (mapcar 'cadr (ssnamex ss)); convert to list of entity names

      (vla-put-Name (vlax-ename->vla-object blk) name)

    ); foreach

  ); progn

  (prompt "\nNo such Blocks found."); else

); if

 

That assumes that all such Blocks have their drawn content in the same positional and rotational and size relationship to their insertion points.  If not, some of the insertions will move or rotate or scale differently when the new Block name is assigned to them.

 

Doesn't yet account for locked Layer(s), have error handling, disallow Xrefs [if any might have such names], etc., etc., but that can all be added easily enough, if the concept works for you.

Kent Cooper, AIA
Message 3 of 5
3wood
in reply to: Kent1Cooper

And nested blocks...

Message 4 of 5
Kent1Cooper
in reply to: 3wood


@3wood wrote:

And nested blocks...


True....  If there might be any, it could be accomplished, but I think only by stepping through the contents of all Block definitions to see whether any of their elements are among the right kind(s) of Blocks.

Kent Cooper, AIA
Message 5 of 5
stevor
in reply to: dglenn9000

1. Should you check whether they are identical before making all such INSERTs of one BLOCK name? 2. If they are identical, they may be serialized, ie, accounted for, by the V part, ie V223, V421; and if so, Attributes could retain that info.
S

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost