如何在 Rhino Python 中引用网格进行布尔差分运算?

问题描述 投票:0回答:1

我有 2 个网格,我可以在 GUI 中手动对这 2 个网格执行布尔差异,从而产生所需的结果。现在我喜欢在 Python 脚本中对完全相同的数据执行完全相同的操作:

def BooleanDifference():
    filter = Rhino.DocObjects.ObjectType.AnyObject

    rc, mesh1 = Rhino.Input.RhinoGet.GetOneObject("Select mesh to subtract from", False, filter)
    if rc != Rhino.Commands.Result.Success: return rc
    if not mesh1: return Rhino.Commands.Result.Failure

    rc, mesh2 = Rhino.Input.RhinoGet.GetOneObject("Select mesh to subtract", False, filter)
    if rc != Rhino.Commands.Result.Success: return rc
    if not mesh2: return Rhino.Commands.Result.Failure

    tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    rc, dub = Rhino.Geometry.Mesh.CreateBooleanDifference(mesh1, mesh2, tolerance)
    if rc != Rhino.Commands.Result.Success: return rc
    if not dub: return Rhino.Commands.Result.Failure

    scriptcontext.doc.Views.Redraw()
    return Rhino.Commands.Result.Success

函数

CreateBooleanDifference
拒绝执行,大概是因为在将网格对象引用传递给差异函数之前,我未能正确捕获网格对象引用或将其类型转换为 IEnumerables(注意:所选对象首先是有效的实体网格) .

错误信息是:

TypeError: Rhino.DocObjects.ObjRef value cannot be converted to System.Collections.Generic.IEnumerable`1[Rhino.Geometry.Mesh] in method Rhino.Geometry.Mesh[] CreateBooleanDifference(System.Collections.Generic.IEnumerable`1[Rhino.Geometry.Mesh], System.Collections.Generic.IEnumerable`1[Rhino.Geometry.Mesh], Rhino.Geometry.MeshBooleanOptions, Rhino.Commands.Result ByRef)

那么我该怎么做呢?

python rhino3d
1个回答
0
投票

要使用 Python 对 Rhino 中的两个网格对象执行布尔差异,您需要将

Rhino.DocObjects.ObjRef
类型的对象转换为
Rhino.Geometry.Mesh

© www.soinside.com 2019 - 2024. All rights reserved.