Objects that is not Breps?

Hello friends! Im trying to read a .3dm file, however, not all the objects are classified as Breps. What other kind of objects does excist? Below is part of the code im using to read the .3dm file

ONX_Model model;

// open file containing opennurbs archive
FILE* archive_fp = ON::OpenFile( filename.c_str(), “rb”);
if ( !archive_fp )
std::cout << filename << “: Unable to open file.\n”;
else {

// create archive object from file pointer
ON_BinaryFile archive( ON::read3dm, archive_fp );

// read the contents of the file into "model"
bool rc = model.Read( archive);

// close the file
ON::CloseFile( archive_fp );

// print diagnostic
if ( rc )
  std::cout << "Successfully read.\n";
  std::cout << "Errors during reading.\n";

// see if everything is in good shape
if ( model.IsValid() )
  std::cout << "Model is valid.\n";
  std::cout << "Model is not valid.\n";

std::cout << "The count is " << model.m_object_table.Count() << std::endl;

for (int i = 0; i  < model.m_object_table.Count(); ++i) {
    extractBrep(model.m_object_table[i].m_object, brep);
  else if (ON_Geometry::Cast(model.m_object_table[i].m_object))
    const ON_Geometry* pGeometry = ON_Geometry::Cast(model.m_object_table[i].m_object);
        extractBrep(pGeometry, brep);
    else if ( pGeometry->HasBrepForm() )
      ON_Brep* brep2 = pGeometry->BrepForm();
      std::cout << "Got a thing that has a Brep form." << std::endl;
      extractBrep(brep2, brep);
      delete brep2;
    else if(ON_Surface::Cast(pGeometry))
      std::cout << "Found surface that was not brep 1" << std::endl;
    else std::cout << "Didnt have Brep form." << std::endl;
  else if(ON_Surface::Cast(model.m_object_table[i].m_object))
    std::cout << "Found surface that was not brep 2" << std::endl;
    std::cout << "neither surface nor brep" << std::endl;

std::cout << "Found " << brep.size() << " BREP objects of at least " << model.m_object_table.Count() << " possible." << std::endl;

Dunno… curves? points? Other objects like lights, dimensions, etc.?


i guess what my real question is, does anyone know an easy way to determine what kind of “objects” is in an .3dmfile appart from Breps?

What seems to happen is that i lack some geometries, and also some transformations of the geometries i actually manage to read. i would like to be able to access these.

I could be wrong, but isn’t there an example program in the openNurbs toolkit that will parse a .3dm file and list all the objects?

Hi Alexander,

Objects that derive from ON_Objec override ON_Object::ObjectType(), which returns an enum. This can be helpful when trying to classify geometry.

– Dale

Hello Dale, thnx for your answer! I have now investiaged my models, and what i notice is that the Enum gives me either a BREP (as expected) or:
instance_reference = 0x1000, // some type of ON_InstanceRef

Im guessing InstanceRef is reference to an excisting Brep with possible diffrent transformation etc. Is there an easy way to access all data of an InstanceRef, possibly make it a Brep of its own?

Also, i notice that the Breps i actually access often seem to have wrong transformation - is it the case actually that its the InstanceRef´s i should be looking at to start with?

Hi Alexander,

Here is a little background on instance references, or blocks:


Here is an example of reading instance references from 3dm files that might help you.

Dale, thankyou for fast replies! This works now :slight_smile:

@stevebaer Here’s an unintended consequence of the smiley system in Discourse. Particularly problematic in a programming topic.

just use backticks to enclose command-like phrases :smile:



Let’s see how that works…

Objects that derive from ON_Objec override ON_Object::ObjectType(), which returns…

Not perfect, but not too bad either for these rare cases. Thanks Mitch.