Persistent GUID of ON_Brep objects

Hi all,

I’m beginning in the coding with Rhino Plugins.

Could you explain me how to get a persistent GUID of ON_Brep objects (ON_BrepFace, ON_BrepLoop, ON_BrepTrim, etc) ?

Running the following code on a Box shape, the result is:

Command: BRepAdjacencyGraph
Face id = 0 (GUID=00000000-0000-0000-0000-000000000000)
Loop id = 0
Trim id = 0
Edge id = 0 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 0 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 1 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 1
Edge id = 1 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 1 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 2 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 2
Edge id = 2 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 3 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 2 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 3
Edge id = 3 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 0 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 3 (GUID=00000000-0000-0000-0000-000000000000)
Face id = 1 (GUID=00000000-0000-0000-0000-000000000000)
Loop id = 0
Trim id = 4
Edge id = 4 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 1 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 4 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 5
Edge id = 5 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 4 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 5 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 6
Edge id = 6 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 2 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 5 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 7
Edge id = 1 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 1 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 2 (GUID=00000000-0000-0000-0000-000000000000)
Face id = 2 (GUID=00000000-0000-0000-0000-000000000000)
Loop id = 0
Trim id = 8
Edge id = 7 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 4 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 6 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 9
Edge id = 8 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 6 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 7 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 10
Edge id = 9 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 5 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 7 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 11
Edge id = 5 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 4 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 5 (GUID=00000000-0000-0000-0000-000000000000)
Face id = 3 (GUID=00000000-0000-0000-0000-000000000000)
Loop id = 0
Trim id = 12
Edge id = 10 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 6 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 0 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 13
Edge id = 3 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 0 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 3 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 14
Edge id = 11 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 7 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 3 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 15
Edge id = 8 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 6 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 7 (GUID=00000000-0000-0000-0000-000000000000)
Face id = 4 (GUID=00000000-0000-0000-0000-000000000000)
Loop id = 0
Trim id = 16
Edge id = 0 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 0 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 1 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 17
Edge id = 4 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 1 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 4 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 18
Edge id = 7 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 4 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 6 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 19
Edge id = 10 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 6 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 0 (GUID=00000000-0000-0000-0000-000000000000)
Face id = 5 (GUID=00000000-0000-0000-0000-000000000000)
Loop id = 0
Trim id = 20
Edge id = 2 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 3 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 2 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 21
Edge id = 6 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 2 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 5 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 22
Edge id = 9 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 5 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 7 (GUID=00000000-0000-0000-0000-000000000000)
Trim id = 23
Edge id = 11 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 7 (GUID=00000000-0000-0000-0000-000000000000)
Vertex id = 3 (GUID=00000000-0000-0000-0000-000000000000)
Selecting solid #db99d4a3-3eb7-4523-a6d8-5b8d05f91682
Current document has “1” Solid shapes.
1 solid(s) selected.

ON_UUID GetGUID(const CRhinoObject* pObj)
{
	ON_UUID uuid= pObj->ModelObjectId();
	if (uuid == ON_nil_uuid) uuid = pObj->Id();
	if (uuid == ON_nil_uuid) uuid = pObj->Attributes().m_uuid;;
	return uuid;
}

bool ProcessBrepFaceLoops(const ON_Brep* brep)
{
	ON_SimpleArray<int> faces_indices_list; //face indices list
	ON_SimpleArray<int> loops_indices_list; //loops indices list
	ON_SimpleArray<int> trims_indices_list; //trims indices list
	ON_SimpleArray<int> edges_indices_list; //edges indices list
	ON_SimpleArray<int> vertices_indices_list; //vertices indices list

	// For each BrepFace
	for (int bfi = 0; (brep->Face(bfi) != nullptr); bfi++)
	{
		//Get the BrepFace of the given index
		const ON_BrepFace* face = brep->Face(bfi);
		if (0 == face)
			break;

		faces_indices_list.Append(face->m_face_index);

		ON_wString str;
		ON_UuidToString(face->m_face_uuid, str);
		::RhinoApp().Print(L"Face id = %d (GUID=%ls)\n", bfi, static_cast<const wchar_t*>(str));

		//Get the loop of the face
		for (int fli = 0; fli < face->LoopCount(); fli++)
		{
			const ON_BrepLoop* loop = face->Loop(fli);
			if (0 == loop)
				continue;
			loops_indices_list.Append(loop->m_loop_index);

			::RhinoApp().Print(L"Loop id = %d\n", fli);

			for (int lti = 0; lti < loop->TrimCount(); lti++)
			{
				//Find the trim
				const ON_BrepTrim* trim = loop->Trim(lti);
				if (0 == trim)
					continue;
				trims_indices_list.Append(trim->m_trim_index);
				::RhinoApp().Print(L"Trim id = %d\n", trim->m_trim_index);

				//Find the edge of that trim
				//Each trim has exactly one edge attached to it
				const ON_BrepEdge* edge = trim->Edge();
				if (0 == edge)
					continue;
				edges_indices_list.Append(edge->m_edge_index);
				ON_UuidToString(edge->ModelObjectId(), str);
				::RhinoApp().Print(L"Edge id = %d (GUID=%ls)\n", edge->m_edge_index, static_cast<const wchar_t*>(str));

				for (int evi = 0; evi < 2; evi++)
				{
					const ON_BrepVertex * vertex0 = edge->Vertex(evi);
					if (0 == vertex0)
						continue;
					vertices_indices_list.Append(vertex0->m_vertex_index);;
					ON_UuidToString(vertex0->ModelObjectId(), str);
					::RhinoApp().Print(L"Vertex id = %d (GUID=%ls)\n", vertex0->m_vertex_index, static_cast<const wchar_t*>(str));
				}
			}
		}

	}
	return false;
}

CRhinoCommand::result CCommandBRepAdjacencyGraph::RunCommand(const CRhinoCommandContext& context)
{
	// CCommandBRepAdjacencyGraph::RunCommand() is called when the user
	// runs the "BRepAdjacencyGraph".

	// https://discourse.mcneel.com/t/get-all-objects-in-c/99737
	unsigned int rhino_doc_sn = context.m_doc.RuntimeSerialNumber();
	CRhinoObjectIterator it(
		rhino_doc_sn,
		CRhinoObjectIterator::undeleted_objects,
		CRhinoObjectIterator::active_and_reference_objects
	);

	int nbSolids = 0;
	CRhinoObject* rhino_obj = nullptr;
	for (rhino_obj = it.First(); nullptr != rhino_obj; rhino_obj = it.Next())
	{
		if (rhino_obj->IsSolid())
		{
			nbSolids++;

			const ON_Geometry* geometry = rhino_obj->Geometry();
			if (geometry && geometry->HasBrepForm()) {

				ON_Brep* brep = ON_Brep::New();
				geometry->BrepForm(brep);
				ProcessBrepFaceLoops(brep);
				delete brep; // don't leak... 
			}
			else
			{
				::RhinoApp().Print(L"Error : can't get geometry of solid #%d\n", nbSolids);
			}
			ON_wString str;
			ON_UuidToString(GetGUID(rhino_obj), str);
			::RhinoApp().Print(L"Selecting solid #%ls\n", static_cast<const wchar_t*>(str));
			rhino_obj->Select();
		}
	}
	::RhinoApp().Print(L"Current document has \"%d\" Solid shapes.\n", nbSolids);

	context.m_doc.Redraw();

	::RhinoApp().Print(L"%d solid(s) selected.\n", nbSolids);
	return CRhinoCommand::success;
}

You should probably move this to a NEW TOPIC.

Hi @Gilles_FOUCAULT,

The default value of ON_BrepFace::m_face_uuid is ON_nil_uuid.

Rhino does not set this property - it is available for use as a way of tracking Brep faces.

This is exposed in RhnoCommon as BrepFace.Id.

– Dale

2 Likes

Thanks for your quick answer.

I would like to have an identifier for Brep entities to index them in a map data-structure and find them with the identifier as a key.

Can I set manually m_uuid attribute (pObj->Attributes().m_uuid) and select them ?

Something like UUID missing in (some?) older files? ?

Hi @Gilles_FOUCAULT,

Rhino automatically assigns object ids.

For example, given some Brep:

ON_3dPoint box_corners[8]{};
box_corners[0].x = 0.0; box_corners[0].y = 0.0; box_corners[0].z = 0.0;
box_corners[1].x = 5.0; box_corners[1].y = 0.0; box_corners[1].z = 0.0;
box_corners[2].x = 5.0; box_corners[2].y = 5.0; box_corners[2].z = 0.0;
box_corners[3].x = 0.0; box_corners[3].y = 5.0; box_corners[3].z = 0.0;
box_corners[4].x = 0.0; box_corners[4].y = 0.0; box_corners[4].z = 5.0;
box_corners[5].x = 5.0; box_corners[5].y = 0.0; box_corners[5].z = 5.0;
box_corners[6].x = 5.0; box_corners[6].y = 5.0; box_corners[6].z = 5.0;
box_corners[7].x = 0.0; box_corners[7].y = 5.0; box_corners[7].z = 5.0;
ON_Brep* pBrep = ON_BrepBox(box_corners);

You can do this:

CRhinoBrepObject* pBrepObj = new CRhinoBrepObject();
pBrepObj->SetBrep(pBrep); // pBrepObj now owns pBrep
if (context.m_doc.AddObject(pBrepObj))
{
  ON_UUID uuid = pBrepObj->ModelObjectId(); // uuid to track
  ON_wString str;
  ON_UuidToString(uuid, str);
  RhinoApp().Print(L"CRhinoObject::ModelObjectId: %ls\n", static_cast<const wchar_t*>(str));
}
else
{
  delete pBrepObj; // Don't leak...
}

If, for some reason, you want to assign your own GUID, you can do this:

ON_3dmObjectAttributes attributes;
context.m_doc.GetDefaultObjectAttributes(attributes);
attributes.m_uuid = ON_CreateId();
ON_UuidToString(attributes.m_uuid, str);
RhinoApp().Print(L"ON_3dmObjectAttributes::m_uuid: %ls\n", static_cast<const wchar_t*>(str));

CRhinoBrepObject* pBrepObj = new CRhinoBrepObject(attributes);
pBrepObj->SetBrep(pBrep); // pBrepObj now owns pBrep
if (context.m_doc.AddObject(pBrepObj))
{
  ON_UUID uuid = pBrepObj->ModelObjectId(); // uuid to track
  ON_UuidToString(uuid, str);
  RhinoApp().Print(L"CRhinoObject::ModelObjectId: %ls\n", static_cast<const wchar_t*>(str));
}
else
{
  delete pBrepObj; // Don't leak...
}

– Dale

1 Like

Thank you very much for this !

How can I apply this method to ON_BrepVertex objects ?

This works on Faces, Loops, Trims, Edges, but not on vertices…

Command: BRepAdjacencyGraph
Face id = 0
CRhinoObject::ModelObjectId: 09c02bfb-bfa3-4508-a80f-2801e04f5700
Loop id = 0
CRhinoObject::ModelObjectId: 7a034b03-efe4-4273-a4fe-4e5b579576b0
Trim id = 0
CRhinoObject::ModelObjectId: bddd2545-0510-46a0-8f61-f67dc0cd9475
Edge id = 0
CRhinoObject::ModelObjectId: 6d5ad1ad-3fc3-4294-8ef8-ca5fdcc909c4
Vertex id = 0
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 1
CRhinoObject::ModelObjectId: FAILURE
Trim id = 1
CRhinoObject::ModelObjectId: 9ab88d8c-7445-4f1e-8250-47356df35d2f
Edge id = 9
CRhinoObject::ModelObjectId: 3e10ec2b-78c9-4e74-a6c2-173b21dcd685
Vertex id = 1
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 5
CRhinoObject::ModelObjectId: FAILURE
Trim id = 2
CRhinoObject::ModelObjectId: 473de116-ea1c-463e-a628-2e3ddb448864
Edge id = 4
CRhinoObject::ModelObjectId: 8fd739b1-eccb-4370-90b6-24c7abec3808
Vertex id = 4
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 5
CRhinoObject::ModelObjectId: FAILURE
Trim id = 3
CRhinoObject::ModelObjectId: 84c15954-55c8-439f-9822-bc0f7b88a92e
Edge id = 8
CRhinoObject::ModelObjectId: d67a9535-773c-4bfa-8a4d-844c1b4f0368
Vertex id = 0
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 4
CRhinoObject::ModelObjectId: FAILURE
Face id = 1
CRhinoObject::ModelObjectId: 9d27862a-3133-4be9-904f-68c0864e91fc
Loop id = 0
CRhinoObject::ModelObjectId: bfc45d1e-753b-4238-b9aa-56065f9e201d
Trim id = 4
CRhinoObject::ModelObjectId: 9dea38e8-1374-4b52-ab62-a9db20ea8cc5
Edge id = 1
CRhinoObject::ModelObjectId: 5552ef29-e4c3-42c8-a34d-12c82c5fe959
Vertex id = 1
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 2
CRhinoObject::ModelObjectId: FAILURE
Trim id = 5
CRhinoObject::ModelObjectId: 0f266980-acc9-4c67-966a-91c32cd82fd8
Edge id = 10
CRhinoObject::ModelObjectId: e154c030-1b5d-4f91-b0c2-964fc0ae9d7c
Vertex id = 2
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 6
CRhinoObject::ModelObjectId: FAILURE
Trim id = 6
CRhinoObject::ModelObjectId: 7dbc6e12-b089-4734-a1bb-95403e02bf51
Edge id = 5
CRhinoObject::ModelObjectId: 527380a5-fb00-46c6-8220-44e0d4f8132e
Vertex id = 5
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 6
CRhinoObject::ModelObjectId: FAILURE
Trim id = 7
CRhinoObject::ModelObjectId: 7d32f93d-ec4b-4644-9bcc-8ed1bf3a79d9
Edge id = 9
CRhinoObject::ModelObjectId: 60bf3864-1efb-4bb4-b3e4-63431a6567fe
Vertex id = 1
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 5
CRhinoObject::ModelObjectId: FAILURE
Face id = 2
CRhinoObject::ModelObjectId: b8605215-cb70-4f76-93a6-10d417633e8f
Loop id = 0
CRhinoObject::ModelObjectId: d27903dc-3f8a-472e-bf2e-d7153e9b38a7
Trim id = 8
CRhinoObject::ModelObjectId: 4cb5f77b-d851-4cf8-b5f4-1b4dfd0bf495
Edge id = 2
CRhinoObject::ModelObjectId: 457cbaa2-97b9-45b9-bac4-40f78d41a3ce
Vertex id = 2
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 3
CRhinoObject::ModelObjectId: FAILURE
Trim id = 9
CRhinoObject::ModelObjectId: dd18376d-8bf0-4135-8930-3782cccd9de2
Edge id = 11
CRhinoObject::ModelObjectId: 205cf012-9ec4-45a9-a96e-8f4d7ced0aa2
Vertex id = 3
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 7
CRhinoObject::ModelObjectId: FAILURE
Trim id = 10
CRhinoObject::ModelObjectId: 381dd44c-812b-46a5-a40d-58ab85888046
Edge id = 6
CRhinoObject::ModelObjectId: ee896e9e-5093-41a6-8c89-14b6b7ade49c
Vertex id = 6
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 7
CRhinoObject::ModelObjectId: FAILURE
Trim id = 11
CRhinoObject::ModelObjectId: 2b67be5a-e51a-4910-81da-6fb2c71a01fc
Edge id = 10
CRhinoObject::ModelObjectId: 098591dc-5a5e-4bf5-bcc5-2a9d05ef7fe7
Vertex id = 2
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 6
CRhinoObject::ModelObjectId: FAILURE
Face id = 3
CRhinoObject::ModelObjectId: 2dd4656e-d8da-4894-bab5-cd8d74e0881f
Loop id = 0
CRhinoObject::ModelObjectId: d6b8e2b6-3562-4a76-851d-cd9da7116e47
Trim id = 12
CRhinoObject::ModelObjectId: 08a1a052-13a1-400d-96d8-d9403bb71ccb
Edge id = 3
CRhinoObject::ModelObjectId: dc352b1c-b158-4407-b669-50a90622f182
Vertex id = 3
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 0
CRhinoObject::ModelObjectId: FAILURE
Trim id = 13
CRhinoObject::ModelObjectId: 1af40ccc-ad62-48aa-9f97-dd9d6dc8cb77
Edge id = 8
CRhinoObject::ModelObjectId: 6b1a6c5a-e614-45d1-8733-4b8bbeb2069e
Vertex id = 0
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 4
CRhinoObject::ModelObjectId: FAILURE
Trim id = 14
CRhinoObject::ModelObjectId: 479de35f-0d38-48fe-a7bf-4e30d3abd9d8
Edge id = 7
CRhinoObject::ModelObjectId: d79d13cd-c312-4451-a94a-3fe92237258d
Vertex id = 7
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 4
CRhinoObject::ModelObjectId: FAILURE
Trim id = 15
CRhinoObject::ModelObjectId: d0db1d2c-9f31-46aa-82e8-25648778d36c
Edge id = 11
CRhinoObject::ModelObjectId: b979317b-8c86-4e34-930a-ed67519499dd
Vertex id = 3
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 7
CRhinoObject::ModelObjectId: FAILURE
Face id = 4
CRhinoObject::ModelObjectId: c4990ff9-93e2-4d30-8ae6-9412bd01e9f8
Loop id = 0
CRhinoObject::ModelObjectId: cd11bdb6-4aea-43ac-8e54-3a800634a66a
Trim id = 16
CRhinoObject::ModelObjectId: 4518616e-3a5c-4618-a13a-bebb1ca6cbd1
Edge id = 3
CRhinoObject::ModelObjectId: 0c6beb23-bd20-433a-a5c6-0942b6c2dca9
Vertex id = 3
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 0
CRhinoObject::ModelObjectId: FAILURE
Trim id = 17
CRhinoObject::ModelObjectId: f28b33d3-6167-428c-8dfc-007d3a7725b1
Edge id = 2
CRhinoObject::ModelObjectId: de6411d1-274b-42da-b83f-16f18512fd4f
Vertex id = 2
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 3
CRhinoObject::ModelObjectId: FAILURE
Trim id = 18
CRhinoObject::ModelObjectId: 9ae84fb5-b0ba-49fb-b426-47e563ebc499
Edge id = 1
CRhinoObject::ModelObjectId: d46e7c5a-6d02-494b-85f1-031abee7c8b0
Vertex id = 1
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 2
CRhinoObject::ModelObjectId: FAILURE
Trim id = 19
CRhinoObject::ModelObjectId: a39200b0-732b-4e81-8256-d5ff6c394d12
Edge id = 0
CRhinoObject::ModelObjectId: a266bf44-a0ae-49d7-a479-ba8292fae3f1
Vertex id = 0
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 1
CRhinoObject::ModelObjectId: FAILURE
Face id = 5
CRhinoObject::ModelObjectId: e3a18722-2593-4c87-a28b-84109e6fb3f6
Loop id = 0
CRhinoObject::ModelObjectId: eb2c9d4d-7123-45c8-bd81-708f85219033
Trim id = 20
CRhinoObject::ModelObjectId: e11bbcc2-8a61-485a-bc9b-a4e8696c5694
Edge id = 4
CRhinoObject::ModelObjectId: 1997d0e9-00a9-418c-bd11-0a29dc5c0e14
Vertex id = 4
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 5
CRhinoObject::ModelObjectId: FAILURE
Trim id = 21
CRhinoObject::ModelObjectId: 62e25d77-f68a-4f17-9405-a88922b48df6
Edge id = 5
CRhinoObject::ModelObjectId: 0b349cb7-6f4e-4fc1-8472-cf01def1f2d2
Vertex id = 5
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 6
CRhinoObject::ModelObjectId: FAILURE
Trim id = 22
CRhinoObject::ModelObjectId: 75c35568-b49b-4447-8ca1-4883204ea1cb
Edge id = 6
CRhinoObject::ModelObjectId: 6908c26b-00ad-4ef0-9717-a4fd1df4742d
Vertex id = 6
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 7
CRhinoObject::ModelObjectId: FAILURE
Trim id = 23
CRhinoObject::ModelObjectId: e370097f-d963-41e0-be9e-85dc0fe41030
Edge id = 7
CRhinoObject::ModelObjectId: 820718c9-3689-4ac3-a088-aa44e95a8130
Vertex id = 7
CRhinoObject::ModelObjectId: FAILURE
Vertex id = 4
CRhinoObject::ModelObjectId: FAILURE

Here is my code :



ON_Brep* MakeBox05()
{
	ON_3dPoint box_corners[8]{};
	box_corners[0].x = 0.0; box_corners[0].y = 0.0; box_corners[0].z = 0.0;
	box_corners[1].x = 5.0; box_corners[1].y = 0.0; box_corners[1].z = 0.0;
	box_corners[2].x = 5.0; box_corners[2].y = 5.0; box_corners[2].z = 0.0;
	box_corners[3].x = 0.0; box_corners[3].y = 5.0; box_corners[3].z = 0.0;
	box_corners[4].x = 0.0; box_corners[4].y = 0.0; box_corners[4].z = 5.0;
	box_corners[5].x = 5.0; box_corners[5].y = 0.0; box_corners[5].z = 5.0;
	box_corners[6].x = 5.0; box_corners[6].y = 5.0; box_corners[6].z = 5.0;
	box_corners[7].x = 0.0; box_corners[7].y = 5.0; box_corners[7].z = 5.0;
	return ON_BrepBox(box_corners);
}


CRhinoBrepObject* CreateRhinoBrepObject(const CRhinoCommandContext& context, ON_Brep * pBrep, bool bDisplayUUID = true)
{
	CRhinoBrepObject* pBrepObj = new CRhinoBrepObject();
	pBrepObj->SetBrep(pBrep); // pBrepObj now owns pBrep
	if (context.m_doc.AddObject(pBrepObj))
	{
		ON_UUID uuid = pBrepObj->ModelObjectId(); // uuid to track
		ON_wString str;
		ON_UuidToString(uuid, str);
		RhinoApp().Print(L"CRhinoObject::ModelObjectId: %ls\n", static_cast<const wchar_t*>(str));
	}
	else
	{
		RhinoApp().Print(L"CRhinoObject::ModelObjectId: FAILURE\n");
		delete pBrepObj; // Don't leak...
		return nullptr;
	}
	return pBrepObj;
}


bool ProcessBrepFaceLoops(const CRhinoCommandContext& context, const ON_Brep* brep)
{
	ON_SimpleArray<int> faces_indices_list; //face indices list
	ON_SimpleArray<int> loops_indices_list; //loops indices list
	ON_SimpleArray<int> trims_indices_list; //trims indices list
	ON_SimpleArray<int> edges_indices_list; //edges indices list
	ON_SimpleArray<int> vertices_indices_list; //vertices indices list

	// For each BrepFace
	for (int bfi = 0; (brep->Face(bfi) != nullptr); bfi++)
	{
		//Get the BrepFace of the given index
		ON_BrepFace* face = brep->Face(bfi);
		::RhinoApp().Print(L"Face id = %d\n", bfi);
		if (0 == face)
			break;

		faces_indices_list.Append(face->m_face_index);
		CreateRhinoBrepObject(context, face->Brep());

		//Get the loop of the face
		for (int fli = 0; fli < face->LoopCount(); fli++)
		{
			const ON_BrepLoop* loop = face->Loop(fli);
			if (0 == loop)
				continue;
			loops_indices_list.Append(loop->m_loop_index);

			::RhinoApp().Print(L"Loop id = %d\n", fli);
			CreateRhinoBrepObject(context, loop->Brep());

			for (int lti = 0; lti < loop->TrimCount(); lti++)
			{
				//Find the trim
				const ON_BrepTrim* trim = loop->Trim(lti);
				if (0 == trim)
					continue;
				trims_indices_list.Append(trim->m_trim_index);
				::RhinoApp().Print(L"Trim id = %d\n", trim->m_trim_index);
				CreateRhinoBrepObject(context, trim->Brep());

				//Find the edge of that trim
				//Each trim has exactly one edge attached to it
				const ON_BrepEdge* edge = trim->Edge();
				if (0 == edge)
					continue;
				edges_indices_list.Append(edge->m_edge_index);
				::RhinoApp().Print(L"Edge id = %d\n", edge->m_edge_index);
				CreateRhinoBrepObject(context, edge->Brep());

				for (int evi = 0; evi < 2; evi++)
				{
					const ON_BrepVertex * vertex0 = edge->Vertex(evi);
					if (0 == vertex0)
						continue;
					vertices_indices_list.Append(vertex0->m_vertex_index);;
					::RhinoApp().Print(L"Vertex id = %d\n", vertex0->m_vertex_index);
					CreateRhinoBrepObject(context, vertex0->BrepForm ());
				}
			}
		}

	}
	return false;
}

CRhinoCommand::result CCommandBRepAdjacencyGraph::RunCommand(const CRhinoCommandContext& context)
{
	// CCommandBRepAdjacencyGraph::RunCommand() is called when the user
	// runs the "BRepAdjacencyGraph".

		ProcessBrepFaceLoops(context, MakeBox05());
		return CRhinoCommand::success;
}

Thanks in advance !

Best regards

Gilles