public class SampleCsRectangleGrips : CustomObjectGrips
{
private readonly List<SampleCsRectangleGrip> m_sample_cs_rectangle_grips = new List<SampleCsRectangleGrip>();
public bool CreateGrips(LineCurve polylineCurve, Point3d? endPoint)
{
if (GripCount > 0)
return false;
m_sample_cs_rectangle_grips.Add(new SampleCsRectangleGrip()
{
OriginalLocation = polylineCurve.PointAt(polylineCurve.Domain.Mid)
});
if (endPoint != default)
{
m_sample_cs_rectangle_grips.Add(new SampleCsRectangleGrip()
{
OriginalLocation = endPoint.Value
});
}
foreach (var item in m_sample_cs_rectangle_grips)
{
AddGrip(item);
}
return true;
}
}
}
internal class SampleCsRectangleGripsEnabler
{
public static IDictionary<Guid, SampleCsRectangleGrips> map = new Dictionary<Guid, SampleCsRectangleGrips>();
/// <summary>
/// Delegate function used to turn custom grips on
/// </summary>
public void TurnOnGrips(RhinoObject rhObject, Point3d? point)
{
if (rhObject == null)
return;
var polyline_curve = rhObject.Geometry as LineCurve;
if (polyline_curve == null)
return;
//if (!SampleCsRectangleHelper.IsRectangle(polyline_curve))
// return;
var rectangle_grips = new SampleCsRectangleGrips();
if (!rectangle_grips.CreateGrips(polyline_curve, point))
return;
map.Add(rhObject.Id, rectangle_grips);
//rhObject.EnableCustomGrips(rectangle_grips);
}
}
RhinoDoc.SelectObjects += (x, y) =>
{
var curveObject = y.RhinoObjects.OfType<CurveObject>().FirstOrDefault();
if (curveObject != null)
{
curveObject.EnableCustomGrips(SampleCsRectangleGripsEnabler.map[curveObject.Id]);
}
}
RhinoDoc.DeselectAllObjects += (x, y) =>
{
// In order to hide grip objects
foreach (var item in RhinoDoc.Objects)
{
item.GripsOn = true;
item.GripsOn = false;
}
};
RhinoDoc.DeselectObjects += (x, e) =>
{
// In order to hide grip objects
foreach (var item in e.RhinoObjects)
{
item.GripsOn = true;
item.GripsOn = false;
}
};
Simply draw a few lines in Rhino, then select back and forth to switch between different lines, and Rhino crashes with no error message.
If I use RhinoObject.EnableCustomGrips(null), then use RhinoObject.EnableCustomGrips(something) again, it will prompt “Attempt to write to protected memory” and then crash