CRhinoObjRef creation

Hi everybody,
I am currently using CRhinoObjRef to store information of objects, subobjects and grips.
My problem is that I still do not have clear how to build correctly a CRhinoObjRef instance.

I have noticed that, for example, when I create a CRhinoObjRef from of an extrusion object it behaves in a different way than a CRhinoObjRef created from the copy of such object.
For instance, the CRhinoObjRef created from the original returns a brep when I use the Brep() method.
The CRhinoObjRef created from the copy of the object do not return anything.
Here a short example:

CRhinoGetObject go;
go.SetCommandPrompt( L"Select comp" );
go.SetGeometryFilter(CRhinoGetObject::surface_object);
go.GetObjects( 1, 1 );
if( go.CommandResult() != CRhinoCommand::success )
	return go.CommandResult();

CRhinoObjRef& objref1 = go.Object(0);
CRhinoObject * objDup = objref1.Object()->Duplicate();
CRhinoObjRef newObj (objDup);

RhinoApp().Print( L"objref1:: (brep? %d) - (type ? %d) \n", 0!=objref1.Brep(), objref1.m_component_index.m_type);
RhinoApp().Print( L"objDup:: (brep? %d) - (type ? %d) \n", 0!=newObj.Brep(), newObj.m_component_index.m_type);

that returns (when I select a face)

objref1:: (brep? 1) - (type ? 3) 
objDup:: (brep? 0) - (type ? 0) 

It means, I guess, that CRhinoObjRef has to be built in a proper way ( can one thing be the proxy? )
Thanks in advance!

I think that will only work properly after your duplicate has been added to the document.

I guess it is not possible to access completely to the object CRhinoObjRef . Nevertheless I am wondering if it is possible to reproduce even only partly the object created in the database…

Hi @gennaro,

CRhinoObjRef returns information on what the user picked and how they picked it. Because this class creates proxy objects as needed, it is not a class you want to use to store information (at least not very long).

Perhaps more details on what you are trying to do and why would be helpful?

– Dale

Dale,
we just need the reference to the selected object. Our issue is that we sometimes select objects depending on some conditions with our functions. With the Pickobjects or the CRhinoGetObject functions is possible to get this reference but I cannot understand how to have a CRhinoObjRef in other ways.
A step forward, for example, would be to know how to set up the proxy…

Tracking an object’s GUID is a good way of doing this.

– Dale

Dale,
it surely works for objects in the document, but what if I want to instantiate a CRhinoObjRef for a temporary object?

CRhinoObjRef has a constructor that takes a Guid.

– Dale

Dale,

still if I try to build the CRhinoRef I cannot reproduce the CRhinoRef we get when we use the CRhinoGetObject.
For example:

CRhinoObjRef& objref = go.Object(0);                                                                                                          RhinoApp().Print( L"objref:: (brep? %d) - (type ? %d) \n", 0!=objref.Brep(), objref.m_component_index.m_type);
const ON_Brep* brepDup = objref.Brep()->Duplicate();
CRhinoObjRef newObjRef (brepDup->ModelObjectId());
RhinoApp().Print( L"brepdup:: (face? %d) - (type ? %d) \n", 0!=newObjRef.Brep(), newObjRef.m_component_index.m_type);

RhinoApp().Print( L"objref1:: (face? %d) - (type ? %d) \n", 0!=objref.Face(), objref.m_component_index.m_type);
const ON_BrepFace* bfDup = objref.Face()->Duplicate();
CRhinoObjRef newObjRef2 (bfDup->m_face_uuid);
RhinoApp().Print( L"bfDup:: (face? %d) - (type ? %d) \n", 0!=newObjRef2.Face(), newObjRef2.m_component_index.m_type);

returns

objref:: (brep? 1) - (type ? 3) 
brepdup:: (brep? 0) - (type ? 0) 
objref1:: (face? 1) - (type ? 3) 
bfDup:: (face? 0) - (type ? 0)

Hi @gennaro,

Creating a new CRhinoObjRef object just based on a object id is not always sufficient. Keep in mind that when you sub-object select (pick a face from a multi-faced Brep for example, the component index is critical as it indicates what you really picked. CRhinoObjRef has some setters for setting up these types of picking operations.

– Dale

Dale,

I understand… I think I will try to create my own struct instead of using the CRhinoObjRef
Thanks!!

Gennaro