c# - Rhinoscript 将 Python 对象移动到 C#

标签 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")

最佳答案

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

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

哪里translationVector3d对象。

然后查看 TransformObjects 电话归结为

scriptcontext.doc.Objects.Transform(id, xf, True)

PointCoordinates() function采用 GUID MoveObject()返回并再次找到该对象,然后为您提供该对象的几何位置(通过 coercegeometry() 并提供 .Geometry Point 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对象引用。

另请参阅 Rhino.Geometry.Transform.Translation() documentation ,其中包括一个 C# 示例,以及 ObjectTable.Transform methods .

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

关于c# - Rhinoscript 将 Python 对象移动到 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53174304/

相关文章:

python - Matplotlib - 将图形导出到内存缓冲区中的 png

html - 将旋转文本锚定到父元素的上限

css - Chrome 中的字体像素化问题 (HTML5/CSS3)

c# - 以编程方式立即窗口输出

c# - 如何拆分通用数组

python - Pandas - 更改因子类型对象的级别顺序

从欧盟网页读取内容的python不一致行为

html - 向右平移一个 div 并让它消失在一条看不见的线后面

c# - 按钮的 WPF 样式

c# - 这个 try-catch block 有效吗?