I add some entity into a block,and add reference into viewport. I coded "new blockReference(blockName).boxmin" , and it will catch exception "NullReferenceException". what else code i need to add? Or it have another way to get group entity boxsize.
Doing a new blockReference(blockName).BoxMin
wont have the block regenerated.
Get the block that is already inserted in the viewport and check that object bounding box.
Let's say the blockname is "Block1" you could do :
var br = viewportLayout1.Entities.OfType<BlockReference>()
.FirstOrDefault(b => b.BlockName == "Block1");
if(br != null)
{
var boxMin = br.BoxMin;
var boxMax = br.BoxMax;
}
The reason behind why you need the block in the ViewportLayout
is that BoxMin
and BoxMax
are align to world axis so position in the world is necessary to know in order to compute the box. If you rotate or translate the BlockReference
the BoxMin
and BoxMax
will be different.