grasshopper SplitBrep with multiple Breps | 对grasshopper中 Rhino | scriptcontext | rhinoscriptsyntax 包的分析(python)

通过grasshopper的python代码切分面的代码:

x 为item类型 brep;y为list类型 brep

import rhinoscriptsyntax as rs
import scriptcontext as sc
tol = sc.doc.ModelAbsoluteTolerance  # 范围值

import Rhino

# 将需要切分的面构成一个 brep集合
cutter = Rhino.Geometry.Brep()
for b in y:
    cutter.Append(b)
    

pieces = x.Split(cutter, tol)

a = pieces
print(pieces)

ghpython 中引入包

rhinoscriptsyntax
import rhinoscriptsyntax as rs  

上面这个包比较好理解,直接调用即刻,不多说。

Rhino
import Rhino

可直接在脚本中执行grasshopper的电池的命令,代码执行能达到和电池类似的效果,比如:

import Rhino
import rhinoscriptsyntax as rs

initBrp = brepSets[0]

# 获取面的边缘线 等价于 brep  wireframe 这个电池
edges = Rhino.Geometry.Brep.GetWireframe(initBrp, -1)  

# 然后joincurves,这时候的格式为guid,会在图上产生线,最好用 joinEdge = Rhino.Geometry.Curve.JoinCurves(edges)
joinGuid = ( rs.JoinCurves(edges)  )

# 将guid转换成curve
joinEdge = ( Rhino.RhinoDoc.ActiveDoc.Objects.FindId(joinGuid[0]).Geometry  ) 

# 然后等价于执行 curve | brep 切割
a = Rhino.Geometry.Intersect.Intersection.CurveBrep(joinEdge, initBrp, 0)

如图

  

scriptcontext
import scriptcontext as sc
sc.doc = Rhino.RhinoDoc.ActiveDoc

上面这个包代表需要当前页面的“唤醒”,尤其是当 grasshopper崩溃之后,需要重新打开,这个包可以规避 rs 包指令不执行的问题。

 

原文地址:https://www.cnblogs.com/qianyuesheng/p/15633458.html