I added an Object to RhinoDoc via:
meshObject = doc.AddMeshObject(ON_Mesh, &attribute, nullptr, 1);
later I want to delete it using:
bool result = doc.DeleteObject(meshObject );
result is true, but the object itself is not deleted.
what am I missing?
Why are you trying to add an object as a reference object?
This is probably a better approach:
ON_UUID object_id = ON_nil_uuid;
CRhinoObject* object = context.m_doc.AddMeshObject(mesh, &attribute);
if (nullptr != object)
object_id = object->ModelObjectId();
// TODO...
if (ON_UuidIsNotNil(object_id))
{
CRhinoObjRef object_ref(object_id);
bool rc = context.m_doc.DeleteObject(object_ref);
}
Does this help?
– Dale
The object is only derived from other data for visualization, so it is owned by the plugin and is not an ‘independent’ model object, and it should not be saved in the archive.
Why are you using CRhinoObjRef? according to the docs CRhinoObjRef should be used to access objects selected in get operations.
Either way whats the difference? ModelObjectId() and CRhinoObject they are accessing the same object within RhinoDoc?
Thank you for the clarification.
While you mostly see CRhinoObjRef
objects as the result of some kind of picking operation, you can create them to by just passing an existing object’s uuid.
Some of the object table operations work on CRhinoObjRef
objects. So it can be useful to create one, as needed, using this object’s uuid. This way, you don’t need to hold on to an object’s pointer, which can become invalid.
Not necessarily. An object pointer points
to a specific instance of that object, keeping in mind that Rhino allows object modifications to be un-done.
When you create a CRhinoObjRef
object, you will always get the active one in the model, not one of many that might be potentially on the undo stack.
If you want to track Rhino objects, it is always best to do so by using the object’s uuid, not it’s pointer.
Hope this helps.
– Dale
Thx, your proposal to use ModelObjectId and RefObjects solved the Delete issue.