I have a class A which is extends CustomMeshObject
and another class B extends CustomObjectGrips
, and I want recreate new A object when grips moved.
So I override method NewGeometry
of class CustomObjectGrips
to recreate a new instance of class B
which is a custom mesh object, like this:
public class B: CustomObjectGrips
{
protected override GeometryBase NewGeometry()
{
if (GripsMoved && OwnerObject is A old)
{
// making a new object
var obj= new A();
var doc = RhinoDoc.ActiveDoc;
doc.Objects.Replace(new ObjRef(old), obj); // this line crash rhino without throw exception
}
return null;
}
}
I guess old object failed to delete, so I try to Hide old object, and everything looks great, but I can’t do that.
public class B: CustomObjectGrips
{
protected override GeometryBase NewGeometry()
{
if (GripsMoved && OwnerObject is A old)
{
var doc = RhinoDoc.ActiveDoc;
if (doc.Objects.Hide(old, true))
{
// making a new object
var obj= new A();
doc.Objects.AddRhinoObject(obj);
}
}
return null;
}
}
My questions is:
- Is this right way to do ?
- how can I make this right ?