You can use the ISketchBlockDefinition.GetSketch and set the sketch to a feature and get the bounding box that way. It should look something like this:
Dim swFeature As Feature Dim swSketch As Sketch Dim BBox As Variant Dim bRet as Boolean Code where you create your block Set swSketch = swSketchBlockDef.GetSketch Set swFeature = swSketch bRet = swFeature.GetBox(BBox) Debug.Print BBox(0) Debug.Print BBox(1) Debug.Print BBox(2)
yes, now i can get the bounding box size. thanks.
I just tried this and it didn't work for me. It only works on the sketch block instance, not the definition. That might be because my block has properties in it that are determined by the view it is linked to, so the block instance size can vary while the definition is the same. I'm testing this is SW2017.
I like the creativity on getting to the bounding box by the way, I just wish SolidWorks would have a more consistent way of getting the size of objects. For notes you have to use note.GetExtent(), how do you find that out?
- Getting the instance size: swBlockInstance > GetSketch() > as Feature > GetBox() indeed only work on smart blocks, that is blocks with text that is linked to the view. This makes sense, because each block's size can be different.
- If the block is dumb, get the definition as Matt proposed: swBlockInstance > Definition > GetSketch() > as Feature > GetBox()
- If you have multiple blocks within a single view swBlockInstance.GetSketch returns the single sketch that contains all blocks. The size of the sketch feature is therefore the bounding box around all blocks. This is not what you need, not what I needed at least.
I have still found no way to get the size of each smart block when a view has multiple blocks. And I could really use that. Anybody has any idea how to get the size of the block instance?
I tried casting it to an Annotation, to a Note, I tried getting all arcs and text from the block. Still no dice. I have created such a nice piece of software for adding blocks and notes, only to find out that it only works when you add a single block