Barclay
10-08-2006, 09:51 PM
My situation, is that I am writing a VBA program for acad that inserts 3D blocks into a drawing in set positions. There are two problems.
1) One block type may have several block references tailing from it, and the requirement is that not all the references will be the same color. For example, there's a block of a wall panel. Some panels will be blue, some red etc. Currently, the block is created in layer 0, and the reference is inserted onto a certain layer that is the correct color, with the block color set to 'bylayer'. Is there a better way to do this?
2) Some of the blocks are actually a collection of 2 or 3 block references, signifying different parts (for example a nut and a bolt being put together in a single block). The different parts will have different colors, and again as with part 1, not every first level reference will have the same color. Currently, using the following code, I can change the required components in the block to different colors, but of course all the block references that follow change with it, instead of just changing the block reference in question.
Sub BlockReferencing()
'Declare the Variables
Dim MyBlock As AcadEntity
Dim LayerCount As Double
LayerCount = 0
'Loop through all entities in block definition
For Each MyBlock In ThisDrawing.Blocks("hdpe.fence_3d")
'Change layer of each reference in block
If TypeOf MyBlock Is AcadBlockReference Then
LayerCount = LayerCount + 1
MyBlock.Layer = "layer" & CStr(LayerCount)
End If
Next myblock
End Sub
As you can see, the above code gets the block definition, searches through every entity in the definition, and if it is a block reference, changes the layer.
What I want it to do, is instead of searching through the block definition itself, I want to search through the block reference for its external references (the block references in the block itself), and change their layers. This way i can have one wall assembly that has a blue frame and a green window, another that has a purple frame and a blue window etc...
I have a direct access to the reference at the moment as i inserted the block is inserted using:
Dim InsertedBlock as AcadBlockReference
Set InsertedBlock as ThisDrawing.Modelspace.InsertBlock(Blockname,1,1,1,0)
so InsertedBlock is a handle for the block in question
Has anyone had any experience with this sort of thing, or have any ideas? Any help is very appreciated before my brain implodes.
1) One block type may have several block references tailing from it, and the requirement is that not all the references will be the same color. For example, there's a block of a wall panel. Some panels will be blue, some red etc. Currently, the block is created in layer 0, and the reference is inserted onto a certain layer that is the correct color, with the block color set to 'bylayer'. Is there a better way to do this?
2) Some of the blocks are actually a collection of 2 or 3 block references, signifying different parts (for example a nut and a bolt being put together in a single block). The different parts will have different colors, and again as with part 1, not every first level reference will have the same color. Currently, using the following code, I can change the required components in the block to different colors, but of course all the block references that follow change with it, instead of just changing the block reference in question.
Sub BlockReferencing()
'Declare the Variables
Dim MyBlock As AcadEntity
Dim LayerCount As Double
LayerCount = 0
'Loop through all entities in block definition
For Each MyBlock In ThisDrawing.Blocks("hdpe.fence_3d")
'Change layer of each reference in block
If TypeOf MyBlock Is AcadBlockReference Then
LayerCount = LayerCount + 1
MyBlock.Layer = "layer" & CStr(LayerCount)
End If
Next myblock
End Sub
As you can see, the above code gets the block definition, searches through every entity in the definition, and if it is a block reference, changes the layer.
What I want it to do, is instead of searching through the block definition itself, I want to search through the block reference for its external references (the block references in the block itself), and change their layers. This way i can have one wall assembly that has a blue frame and a green window, another that has a purple frame and a blue window etc...
I have a direct access to the reference at the moment as i inserted the block is inserted using:
Dim InsertedBlock as AcadBlockReference
Set InsertedBlock as ThisDrawing.Modelspace.InsertBlock(Blockname,1,1,1,0)
so InsertedBlock is a handle for the block in question
Has anyone had any experience with this sort of thing, or have any ideas? Any help is very appreciated before my brain implodes.