Rhinoscript将对象Python移动到C#

2024-09-29 22:25:07 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

这就是我目前所处的位置:

^{pr2}$

但这是不对的。我在第2行得到一个转换的重载错误。任何帮助都会很好。谢谢!在

下面是我的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")

Tags: posself脚本iddeflistrsappend
1条回答
网友
1楼 · 发布于 2024-09-29 22:25:07

MoveObject()MoveObjects的包装器,其中返回第一个结果值而不是列表。看看RhinoScript implementation for ^{}我们看到:

xf = Rhino.Geometry.Transform.Translation(translation)
rc = TransformObjects(object_ids, xf)
return rc

其中translationVector3d对象。在

然后看一下^{}调用的结果是

^{pr2}$

^{} function获取MoveObject()返回的GUID并再次找到该对象,然后为您提供该对象的几何体位置(通过^{}),并提供{}是^{} instance);跳过测试和函数来转换其他可接受的类型这归结为:

scriptcontext.doc.Objects.Find(id).Geometry.Location

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

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;

其中vecRhino.Geometry.Vector3d实例,id是对象引用。在

另请参见^{} documentation,其中包括一个C#示例和^{} methods。在

注意,Rhino.Geometry.Transform.Translation()静态方法已经返回了一个Transform实例,这里不需要使用new Transform()。而且没有PointID类型;也许您正在寻找^{}?但是,Point3D.Transform()方法将在该点上操作,而不是对具有给定id的对象进行操作。在

相关问题 更多 >

    热门问题