# Trouble Reading Rhino .3dm

**URL:** <https://discourse.mcneel.com/t/trouble-reading-rhino-3dm/135042>\
**Category:** openNURBS\
**Tags:** windows\
**Created:** [December 15, 2021, 4:10pm UTC](https://discourse.mcneel.com/t/trouble-reading-rhino-3dm/135042 "2021-12-15T16:10:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukeniwranski](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/lukeniwranski/32/732763_2.png) [@lukeniwranski](https://discourse.mcneel.com/u/lukeniwranski)\
**Post date:** [December 15, 2021, 4:10pm UTC](https://discourse.mcneel.com/t/trouble-reading-rhino-3dm/135042/1 "2021-12-15T16:10:15Z")

</div>

Hello,

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:

```auto
		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);

		ON::CloseFile(pRhinoFile);

		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.

Thanks,

-Luke

[ONX\_Model Dump.txt](https://discourse.mcneel.com/uploads/short-url/2ymxfh3JCNVEX54mJCuRspB2DJM.txt) (100.7 KB)

 ![Watch List](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/f/9/8/f98a9f1d98988557a8c7d80b03af8a811f208964.png)

[9b16d623-b3a5-49d8-ac4a-9997265f190c.3dm](https://discourse.mcneel.com/uploads/short-url/d7zuJIaJzLnmdtHp84r83BhPv8u.3dm) (350.4 KB)

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [December 16, 2021, 4:09am UTC](https://discourse.mcneel.com/t/trouble-reading-rhino-3dm/135042/2 "2021-12-16T04:09:22Z")

</div>

Hi @lukeniwranski,

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

— Dale

---

<div class="post-metadata">

**Author:** ![lukeniwranski](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/lukeniwranski/32/732763_2.png) [@lukeniwranski](https://discourse.mcneel.com/u/lukeniwranski)\
**Post date:** [December 16, 2021, 8:03pm UTC](https://discourse.mcneel.com/t/trouble-reading-rhino-3dm/135042/3 "2021-12-16T20:03:11Z")

</div>

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.

Thanks,

-Luke

---

<div class="post-metadata">

**Author:** ![lukeniwranski](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/lukeniwranski/32/732763_2.png) [@lukeniwranski](https://discourse.mcneel.com/u/lukeniwranski)\
**Post date:** [December 16, 2021, 8:09pm UTC](https://discourse.mcneel.com/t/trouble-reading-rhino-3dm/135042/4 "2021-12-16T20:09:51Z")

</div>

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.

Thanks!

-Luke

---

<div class="post-metadata">

**Author:** ![lukeniwranski](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/lukeniwranski/32/732763_2.png) [@lukeniwranski](https://discourse.mcneel.com/u/lukeniwranski)\
**Post date:** [December 18, 2021, 2:13am UTC](https://discourse.mcneel.com/t/trouble-reading-rhino-3dm/135042/5 "2021-12-18T02:13:46Z")

</div>

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!

-Luke
