protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var go = new GetObject();
go.SetCommandPrompt("Select grip");
go.GeometryFilter = ObjectType.Grip;
go.Get();
if (go.CommandResult() != Result.Success)
return go.CommandResult();
var obj = go.Object(0);
if (null == obj)
return Result.Failure;
var grip_obj = obj.Object() as GripObject;
if (null == grip_obj)
return Result.Failure;
var grip_owner = doc.Objects.Find(grip_obj.OwnerId);
if (null == grip_owner)
return Result.Failure;
if (grip_owner.ObjectType == ObjectType.Curve)
{
var curve = grip_owner.Geometry as Curve;
if (null != curve)
{
// TODO...
}
}
else if (grip_owner.ObjectType == ObjectType.Brep)
{
var brep = grip_owner.Geometry as Brep;
if (null != brep)
{
// Surface grips only available on Breps with a single face
var srf = brep.Surfaces[0];
if (null != srf)
{
// TODO...
}
}
}
return Result.Success;
}
var go = new Rhino.Input.Custom.GetObject();
go.SetCommandPrompt("Select grip");
go.GeometryFilter = ObjectType.Grip;
go.GetMultiple(1, 0);
if (go.CommandResult() != Result.Success)
return go.CommandResult();
var obj = go.Object(0);
Rhino.DocObjects.GripObject g = (GripObject)obj.Object();
Guid gu = g.OwnerId;
RhinoObject ro = Rhino.RhinoDoc.ActiveDoc.Objects.Find(gu);
GripObject[] grl = ro.GetGrips();//It is grips total, how to get count U and count V
Yes I know .but, if the surface is closed.
RhinoObject.GetGrips() not duplicate items.
NurbsSurface.Points.CountU contains duplicate items.how remove duplicate items?
I haven’t tested this. But this should be what you are looking for:
/// <summary>
/// Returns the control points of a surface.
/// </summary>
/// <param name="srf">The surface.</param>
/// <param name="returnAll">
/// If true, all control points are returned.
/// If false, control points are returned based
/// on whether or not the surface is closed or
/// periodic.
/// </param>
/// <returns>The control points</returns>
public ControlPoint[] SurfaceControlPoints(Surface srf, bool returnAll)
{
var cvs = new List<ControlPoint>();
if (null != srf)
{
var ns = srf as NurbsSurface ?? srf.ToNurbsSurface();
if (null != ns)
{
int ufirst, ulast, vfirst, vlast;
if (returnAll)
{
ufirst = 0;
ulast = ns.Points.CountU;
vfirst = 0;
vlast = ns.Points.CountV;
}
else
{
if (ns.IsPeriodic(0))
{
var degree = ns.Degree(1);
ufirst = degree / 2;
ulast = ns.Points.CountU - degree + ufirst;
}
else
{
ufirst = 0;
ulast = ns.IsClosed(0) ? ns.Points.CountU - 1 : ns.Points.CountU;
}
if (ns.IsPeriodic(1))
{
var degree = ns.Degree(1);
vfirst = degree / 2;
vlast = ns.Points.CountV - degree + vfirst;
}
else
{
vfirst = 0;
vlast = ns.IsClosed(1) ? ns.Points.CountV - 1 : ns.Points.CountV;
}
}
for (var v = vfirst; v < vlast; v++)
for (var u = ufirst; u < ulast; u++)
cvs.Add(ns.Points.GetControlPoint(u, v));
}
}
return (0 == cvs.Count) ? new ControlPoint[0] : cvs.ToArray();
}