grasshopper之python电池执行逻辑

  在grasshopper中,需要导入的包虽然不多,但是相当绕人,所要实现的操作往往找不到,暂时做个分类。

双击输入 python 电池:  

# 导入rhino 包
import Rhino

#Rhino.Geometry 表示执行的是几何图形操作,例如:输入一个点和圆形

pt = Rhino.Geometry.Point3d(80233.3, 38977, 0)
cir = Rhino.Geometry.Circle(pt, 199)

# 不输出转出是无法在图形上显示出来
p = pt
a = cir

例如求点到线段的最近距离点:

import Rhino.Geometry as rg

success, t = rg.Curve.ClosestPoint(curveInput, ptInput)

# Get the closest point on the curve to your point 
crv_pt = rg.Curve.PointAt(curveInput, t)

# Measure the distance between both points
dist = ptInput.DistanceTo(crv_pt)
print(dist)
a = crv_pt

 另外一个常用包 rhinoscriptsyntax:

import rhinoscriptsyntax as rs
# 通过外界导入数据,对数据进行代码逻辑操作,可引用部分电池的代码操作,不需要进行可视化展示,然后进行导出数据,则调入rhinoscriptsyntax包


'''上述操作可同样用 rs包完成'''
# 输入 curve 和 point3d 类型
t = rs.CurveClosestPoint(curveInput, ptInput)
# 在curveInput 线上得到最近的点
crv_pt = rs.EvaluateCurve(curveInput, t) 
# 计算两点之间的距离
dist = rs.Distance(ptInput, crv_pt)
# 输出点
a = crv_pt

官方文档:https://developer.rhino3d.com/api/RhinoScriptSyntax/

同时这里面还有很多案例:https://wiki.mcneel.com/developer/pythonandrhinocommon

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