How do I use opennurbs to implement explodeblock

I am currently doing data conversion. The current 3dm file has a block instance, and I want to convert the location of the block instance in space into a specific object (similar in function to explodeblock).

Hi @JJerry,

You might start here:

— Dale

Now I know how to get the instance definition, but I’m still not sure how to get its geometry or replace it with block instance

Hi @JJerry,

Well, you need to iterate the model looking for instance references to explode.

ONX_Model model = ...

ONX_ModelComponentIterator it(model, ON_ModelComponent::Type::ModelGeometry);
const ON_ModelComponent* model_component = nullptr;
for (model_component = it.FirstComponent(); nullptr != model_component; model_component = it.NextComponent())
{
  const ON_ModelGeometryComponent* model_geometry = ON_ModelGeometryComponent::Cast(model_component);
  if (nullptr != model_geometry)
  {
    // Test for instance reference
    const ON_InstanceRef* iref = ON_InstanceRef::Cast(model_geometry->Geometry(nullptr));
    if (nullptr != iref)
    {
      // TODO: explode the instance reference...
      continue;
    }
  }
}

– Dale

Hello, the basic problem of transformation has been solved. Thank you very much for your guidance and help. Another problem is that my transformed models are all at the origin, which does not match the actual position. It feels like an offset matrix is missing, but the transformations in Rhino’s obeject Description are IdentityTransformations. However, the xform in the latter description has some problems in use

The problem has been solved, thank you very much

For those following this thread:

Instance definition geometry is oriented about the world origin.

Instance references maintain the transformation from the world origin to the location the user chooses to insert at. (ON_InstanceRef::m_xform).

– Dale

If I target a complex scene, there are a large number of tile instances. There is a many-to-many relationship between the block instance and the underlying brepobject, so how do I determine how many block instances and which objects I really need to insert

There is no block instance traversal, I can not determine the number of block instances

As shown in the figure

@JJerry - there is no function on ONX_Model to count the number of instance references. If you need this value, you’ll need to use a ONX_ModelComponentIterator to iterate the model looking for ON_ModelGeometryComponent objects that cast ast ON_InstanceRef and count them up.

– Dale


Does this actually happen or is it regulated? The non-top-level instance define is made as a block instance

just like 9812(B2)

Is this legal? Multiple top-level instance define are derived from the same instance define. This feels right.

How do I know if the instance define is top-level and ParemtIdIsNil () can’t do it

Hi @JJerry,

I am not sure I understand any of your diagrams or questions.

An ON_InstanceDefinition defines the geometry used by instance references. This geometry can include instance references, or ON_InstanceRef, to create “nested blocks”.

All instance definitions are “top level” in that they can be referenced by ON_InstanceRef objects.

Hope this helps.

– Dale

I’m with Dale on having trouble understanding some of the questions.

On this: you can traverse block structure, including nested blocks. An instance definition (type of Rhino Object) can be part of another instance definition. It’s definitely possible to walk this structure. I do it to handle the nested transformations when displaying nested pieces.