如何从Rhino NURB文件中提取曲线控制点

时间:2014-09-13 05:25:36

标签: plugins

我想实现一个Rhino插件来提取NURB曲线控制点的位置属性。 如果你绘制曲线或像球体一样的实心形状。你有一些要点,你也有一些控制点。

要了解有关NURB广告控制点的更多信息,请阅读此link

2 个答案:

答案 0 :(得分:1)

此Python代码提取所选曲线的控制点,并将曲线名称与提取的控制点相关联。

import rhinoscriptsyntax as rs
from System.Drawing import Color
import Rhino as Rh
#Collecting the curves
obj = rs.GetObjects("Select curves",4)
#adding a Layer as a parent layer
rs.AddLayer("Knots")
for curve in obj:
    if rs.IsCurve(curve):
#Creating new layers from objects name
            LayerName = rs.ObjectName(curve)
            rs.AddLayer(LayerName,Color.Aqua,True,False,"Knots")
            points = rs.CurvePoints(curve)
            if points:
                for pt in points:
                    CtrlPoint = rs.AddPoint(pt)
                    rs.ObjectLayer(CtrlPoint,LayerName)
                    rs.ObjectName(CtrlPoint,rs.ObjectName(curve))

答案 1 :(得分:0)

在VS 2012中您应该安装新的Rhino组件。那么您可以像这样检索NURBS属性:

Surface sr = obj_ref.Surface();
if (null == sr)
    return Result.Failure;

NurbsSurface ns = sr.ToNurbsSurface();
if (null == ns)
    return Result.Failure;


foreach (var point in ns.Points)
{
    doc.Objects.AddPoint(point.Location);
}

foreach (var knot in ns.KnotsU)
{
  // do anything by KnotsU
}


foreach (var knot in ns.KnotsV)
{
    // do anything by KnotsV
}

doc.Views.Redraw();