C#, how to obtain the coordinate data of all the control points on the surface of a block? Thank you!
I haven’t tested this. But this would work:
public Rhino.Geometry.Point3d[] BlockSurfaceControPointLocations(Rhino.DocObjects.InstanceObject iref)
{
var points = new List<Rhino.Geometry.Point3d>();
if (null != iref)
{
// transformation applied to an instance definition for this object
var xform = iref.InstanceXform;
// instance definition that this object uses
var idef = iref.InstanceDefinition;
if (null != idef)
{
// Get array with the objects that belong to this instance definition
var rh_objs = idef.GetObjects();
foreach (var rh_obj in rh_objs)
{
// Try getting surface geometry
var srf = rh_obj.Geometry as Surface;
if (null != srf)
{
// Convert surface to a NURBS surface
var ns = srf.ToNurbsSurface();
if (null != ns)
{
// Process each control point
foreach (var cp in ns.Points)
{
// Transform point using instance definition's transform
var pt = cp.Location;
pt.Transform(xform);
points.Add(pt);
}
}
}
}
}
}
if (points.Count > 0)
return points.ToArray();
return null;
}