How can I get B-rep data from block instance

Hi,
I draw a big box and a small box by another CAD software.
The big box contained the small box. These two boxes are not intersect each other.
I combined these two boxes into a solid model and saved as step file.

When I import this step file into Rhino I got a block instance ,and I want to know how can I get B-rep data from block instance?

When I get a block instance, I used to explode and join the model then I can use GetObjects() to get CRhinoObject.
CRhinoObject convert to ON_Brep.
but this model will become two boxes after explode, then I can not join them .

This is because normally Rhino has no concept of a hollow inside a solid. See also the posts linked below. As a user you can use NonManifoldMerge followed by CreateRegions (see comments by @chuck in the posts).
As a developer, I think you should be able to use ON_MergeBreps - the comment suggests that you can get a non-manifold result. The code equivalent of CreateRegions I don’t know, maybe @chuck can help here.

/*
Description:
  Merges two breps into a single brep.  The
  result may be non-manifold or have multiple
  connected components.
Parameters:
  brep0 - [in]
  brep1 - [in]
  tolerance - [in]
Returns:
  Merged brep or NULL if calculation failed.
*/
ON_DECL
ON_Brep* ON_MergeBreps(
          const ON_Brep& brep0,
          const ON_Brep& brep1,
          double tolerance
          );


The ON_Brep class can represent the hollow box. We just try not to allow it in Rhino. If brep1 is the inner box, you could just call brep1.Flip(); then brep0.Append(brep1);

2 Likes

A block reference object is represented by a CRhinoInstanceObject. If you have a CRhinoObject, you can try to cast it as a CRhinoInstanceObject like this:

const CRhinoObject* obj = ...
const CRhinoInstanceObject* iref = CRhinoInstanceObject::Cast(obj);
if (0 != iref)
{
  // todo...
}

To the the number of elements in the block, use CRhinoInstanceObject::ObjectCount(). To the an element by index, use CRhinoInstanceObject::Object().

1 Like