Hello @dale and all,
I’m coding a custom grips object carrying a piece of custom user data, in C++ for the Rhino 5 SDK. For my sample, I have just taken your SampleCustomGrips example and added an instance of SampleObjectUserData to the rectangle created by the user.
Now, inside CRhinoRectangleGrips
I have a pointer CSampleObjectUserData* m_user_data;
which is initialized when creating the grips as just a copy of the user data originally attached to the rectangle (a point and a string).
Though, I have an error when retrieving the new rectangle with custom user data, the method CRhinoRectangleGrips::NewObject()
. I attached my user data m_user_data
to the polyline curve this way:
CRhinoObject* CRhinoRectangleGrips::NewObject()
{
CRhinoRectangleUserDataObject* new_rectangle = 0;
UpdateRectangle();
if( m_bGripsMoved && m_bDrawRectangle )
{
CRhinoRectangleUserDataObject* pOwnerObject = RectangleObject();
if( pOwnerObject )
new_rectangle = new CRhinoRectangleUserDataObject( *pOwnerObject );
else
new_rectangle = new CRhinoRectangleUserDataObject();
ON_PolylineCurve pline( m_rectangle );
ON_wString wStr;
if ( 0 == pline.AttachUserData(m_user_data) )
{
wStr.Format( L"Could NOT attach user data in CRhinoRectangleGrips::NewObject()\n" );
RhinoApp().Print( wStr );
}
new_rectangle->SetCurve( pline );
}
return new_rectangle;
}
However, it doesn’t work. Could you please take a look? What would be a better way to attach the custom data?
The full project is here: SampleCustomGripsUserData.zip (25.0 KB)
Many thanks,
Pablo