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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM