Rhinoscript MoveObject Python至C#

时间:2018-11-06 14:50:50

标签: c# python transform grasshopper rhino3d

我正在将Python脚本转换为C#,并且在此过程中偶然遇到问题。这次是将一个点从一个位置重新定位到另一个位置。在python脚本中,这是我不知道如何转换的方法的第二行。我已经查看了Rhino文档,但仍然感到困惑。

def move(self):
    self.trailPts.append(self.pos)
    self.pos = rs.PointCoordinates(rs.MoveObject(self.id, self.vec))

这是我到目前为止的位置:

Transform trans = new Transform(Transform.Translation(Vec));
Pos = PointID.Transform(Pos, trans, true);

但这是不正确的。我在第2行遇到了Transform的过载错误。任何帮助都将是非常好的。谢谢!

这也是我的C#构造函数:

public Agent(Point3d pos, Vector3d vec, Point3d pointID, List<Point3d> listOfAgents, List<Point3d> navPoints, List<Circle> pipeProfiles)
        {
            Pos = pos;
            Vec = vec;
            PointID = pointID;
            ListOfAgents = listOfAgents;
            NavPoints = navPoints;
            PipeProfiles = pipeProfiles;

            TrailPoints.Add(new Point3d(Pos));
        }

还有原始的python构造函数:

 def __init__(self, POS, VEC, POINTID, LISTOFAGENTS, NAVPOINTS, PIPEPROFILES):
        self.pos = POS
        self.vec = VEC
        self.id = POINTID
        self.list = LISTOFAGENTS
        self.nav = NAVPOINTS
        self.trailPts = []
        self.trailPts.append(self.pos)
        self.trailID = "empty"
        self.pipeProfiles = PIPEPROFILES
        print("made an agent")

1 个答案:

答案 0 :(得分:0)

<field name="responsible_partner" required="True" domain="[('id','=',responsible_foyer_partner_id)]" /> MoveObject()的包装,其中返回第一个结果值而不是列表。看着RhinoScript implementation for MoveObjects,我们看到:

MoveObjects

其中xf = Rhino.Geometry.Transform.Translation(translation) rc = TransformObjects(object_ids, xf) return rc translation对象。

然后看着TransformObjects,呼叫结束了

Vector3d

PointCoordinates() function使用scriptcontext.doc.Objects.Transform(id, xf, True) 返回的GUID并再次找到您的对象,然后为您提供该对象的几何位置(通过coercegeometry()并提供了{{1} }是Point instance);跳过测试和函数以将可能的其他可接受类型转换为:

MoveObject()

将这些对象转换为RhinoCommon对象将是:

.Geometry

其中scriptcontext.doc.Objects.Find(id).Geometry.Location using Rhino.Geometry; using System; Transform xf = Transform.Translation(vec); id = doc.Objects.Transform(id, xf, true); Point pos = doc.Objects.Find(id).Geometry as Point Point3d pos3d = pos.Location; 实例,vec是对象引用。

另请参见Rhino.Geometry.Transform.Translation() documentation(其中包括C#示例)和ObjectTable.Transform methods

请注意,Rhino.Geometry.Vector3d静态方法已经返回了id实例,在这里无需使用Rhino.Geometry.Transform.Translation()。而且没有Transform类型;也许您在寻找Rhino.Geometry.Point3Dnew Transform()方法将在该点上运行,但是不能在具有给定PointID的对象上运行。