Replace an array of point objects [C++]



Hello all,

In my plugin I add a set of point objects like this

CRhinoPointObject** point_object_array = new CRhinoPointObject*[4];

for (int i = 0; i < 4; i++) {
	point_object_array[i] = new CRhinoPointObject();
	point_object_array[i]->SetPoint( array[i] );

Note that array is an ON_3dPointArray of size 4. After some changes (of array, and attributes) I need to replace it, trying this

CRhinoPointObject** new_point_object_array = new CRhinoPointObject*[4];

for (int i = 0; i < 4; i++) {
	new_point_object_array[i] = new CRhinoPointObject();
	new_point_object_array[i]->SetPoint( array[i] );
	context.m_doc.ReplaceObject(point_object_array[i], new_point_object_array[i]);

but it doesn’t work… Maybe because of the **pointer? Is there a workaround for this?

Many thanks!


(Dale Fugier) #2

Hi Pablo,

Tracking runtime objects by their pointer is never a good idea. Better to track runtime objects by their model id (UUID).

See if the attached sample code gives you any ideas.

cmdTestPablo.cpp (2.0 KB)

– Dale


Hi Dale,

This example is great! Just one question: when you assign the model id

for (int i = 0; i < 4; i++)
	m_points[i] = ON_3dPoint((double)i, (double)i, 0.0);
	m_object_ids[i] = ON_nil_uuid;

You are assigning the same id to all the points, right? The number ON_nil_uuid. Isn’t there a conflict here?

Is this topic of the UUID explained somewhere in the guides?

Thanks again,

(Dale Fugier) #4

Hi Pablo,


ON_nil_uuid is a null (e.g. empty or zero) UUID. Rhino objects do not have null UUIDs. Thus, ON_nil_uuid is used to indicate that the object does not exist, in this context.

This is why the sample checks for null UUID and, if so, adds a new object. If the UUID is not null, then is assumed that the object already exists. Thus, the code replaced the geometry.

Make sense?

– Dale


Ajá! Got it :smiley: This ModelObjectId() method is great!

Thanks for the sample,