我正在将 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
哪里translation
是 Vector3d
对象。
然后查看 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;
哪里vec
是 Rhino.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/