Getting shapes of layer with references

Hi,

 

I am trying to get all the shapes for a particular layer for a stp file, by using the LayerTool's GetShapesOfLayer() function. This seems to work fairly well, but not with shapes that are instances.

Some more information:

I have a test file, which was exported to .stp from Rhino. In Rhino, some of the objects are instanced. Exporting this to .stp and importing in my regular way works fine. Unfortunately, Rhino doesn't seem to care much about creating an assembly. Therefore, I am creating an assembly myself from the layers available. After I create the hierarchy structure from the available layers, I go through every layer and simply use the LayerTool's GetShapesOfLayer() function.

However... When the layer contains instances of a shape, GetShapesOfLayer() seems to return the single original shape itself, instead of all the references on that layer.

 

For example, I created a tiny file for testing. It has one layer, and 3 instanced objects on that layer. When I use GetShapesOfLayer(), it gets a single Solid, which is not a reference. I checked, and the data does contain a Compound, which has 3 reference Solids. These are the ones I want. But they are not what I receive from this function. I get the referenced Solid itself, and only once.

 

My question is, is there a way already available in OpenCascade to get all the shapes (including instances) for a layer?

Or is there maybe a way to find out if the shape I get is used for instancing? And in that case I need to be able to get all the references that use that shape, is that even possible though?

I could manually go through all shapes and check their layer one by one, but I was hoping there was something simpler, just like the GetShapesOfLayer() function :)

 

Thanks!

Nathaniel Essenberg's picture

Hmm okay, I found the function of ShapeTool::GetUsers(), which seems to give me exactly the references that use the instanced shape (if any). Then I can iterate over those and see which of them is on the Layer I want.

So I think that solves it... Unless anyone can tell me that this is not a reliable way to get precisely all the instanced shapes for a specific Layer?

Nathaniel Essenberg's picture

Actually it doesn't always seem to work :(. For some block instances GetUsers returns only 1, and for some even 0. Need to dig deeper I guess...