Trouble Reading Rhino .3dm


I have a piece of C++ code that’s being stubborn. The code is supposed to open a Rhino .3dm and read all mesh, curve, and point data. It worked last month when I compiled and ran it last, but now it’s not working. I’m not sure what changed.

When I run it now, I’m unable to cast the ON_ModelComponent objects to ON_ModelGeometryComponent. Digging deeper, it looks like Cast calls IsKindOf to see if the cast is allowed. It looks like the call to IsDerivedFrom from IsKindOf is returning false.

Here’s the code I’m using to try to read the geometry:

		FILE *pRhinoFile = ON::OpenFile("<path to file>", "rb");
		ON_BinaryFile onArchive(ON::archive_mode::read3dm, pRhinoFile);

		ON_TextLog errorLog;
		ONX_Model onxModel;
		model.Read(onArchive, &errorLog);


		ONX_ModelComponentIterator onComponentIterator(onxModel, ON_ModelComponent::Type::ModelGeometry);

		const ON_ModelComponent* pModelComponent = nullptr;
		const ON_Point* pPoint = nullptr;
		const ON_Curve* pCurve = nullptr;
		const ON_Mesh* pMesh = nullptr;
		for (pModelComponent = onComponentIterator.FirstComponent(); nullptr != pModelComponent; pModelComponent = onComponentIterator.NextComponent())
			const ON_ModelGeometryComponent* pModelGeometry = ON_ModelGeometryComponent::Cast(pModelComponent);
			if (nullptr != pModelGeometry)
				// Get the object attributes
				const ON_3dmObjectAttributes *pAttribs = pModelGeometry->Attributes(nullptr);

				pPoint = ON_Point::Cast(pModelGeometry->Geometry(nullptr));
				if (nullptr != pPoint)
					// Do stuff...

				// try reading curves and points

Attached is a screenshot of the debugger examining the pModelComponent and pModelGeometry variables just after attempting the cast. The structure looks correct. I’m also attaching the results on ONX_Model::Dump and the Rhino .3dm that I’m trying to process.

Any ideas what may be failing here?

This is a standalone application that’s linking with opennurbs-7.11.21285.13001 compiled as a static library.



ONX_Model Dump.txt (100.7 KB)

9b16d623-b3a5-49d8-ac4a-9997265f190c.3dm (350.4 KB)

Hi @lukeniwranski,

Are you able to use the example_read project, included with openNURBS, to read the file?

— Dale

Hi @dale,

I just tried example_read and it spits out all the correct info. I’ll check my project settings to make sure I’m including linking with the correct library and compare my code to example_read to make sure I’m reading everything the same way.



Hi @dale,

Hmm I just had a look at example_read and it looks like it’s just calling ONX_Model::Dump to produce it’s output. I’m doing this in my code too and both example_read and my code produce the same output when calling Dump.

I’ll double check everything anyways, it’s gotta be something small or subtle that changed on my end because it did work last month.



Figured it out. It looks like ONX_Model references dont like being passed between DLLs. Now I’m making sure I’m iterating over all the model geometry in the same DLL that’s constructing the ONX_Model and everything works like a charm!