Nested Blocks

Are nested blocks supported in vba

Comments

  • You can do something like thisFor Each ENT in Activedocument.Modelspace If ENT.EntityName = "AcDbBlockreference" (?).. Set BLK = ENT For Each SubENT in Activedocument.Blocks (BLK.Name) do something here? ...If you have a block reference you can get the block definition and then all the objects inside that block. Modelspace and Paperspace are also block definitions.

  • Easyest way is to use a recursive function (although with loads of levels of nested blocks, this can use a lot of memory).Here is an example I've made to change the color and layer off all entities in a block and the nested blocks in that block to the color of the active layer and set the layer to the active layer.Be aware that "nested blocks" are actualy block references used in the creation of a block. You can not change a block reference. You need to change the block. Meaning that if the nested block is used elsewhere in the drawing as a blockreference (insert) then this will change also.Good luck.Private Function BlockToLayer(MyBlock As IAcadBlock)Dim MyEmbededBlock As IAcadBlockFor Each MyItem In MyBlock 'Check if item is not a block, then set properties If MyItem.EntityName <> "AcDbBlockReference" Then MyItem.Layer = ActiveDocument.ActiveLayer.Name MyItem.Color = acByLayer Else 'Item is a nested blockreference, set properties of blockreference, ' then call this function again to handel items ' in the nested blocks MyItem.Color = acByBlock blocknaam = MyItem.Name For Each embededblock In ActiveDocument.Blocks If embededblock.Name = blocknaam Then Set MyEmbededBlock = embededblock temp = BlockToLayer(MyEmbededBlock) End If Next embededblock End IfNext MyItemEnd Function

This discussion has been closed.