2011年9月8日 星期四

"hello python chai(ee)r"




試著使用Rhino 5裡面新的程式撰寫工具
PYTHON 形塑簡單的曲線造型
作為熟悉該程式語言的練習
其實他在Rhino裡面的操作跟使用
RhinoScript差不多
只是說法不同

Try to use the new programming tool "PYTHON"
in Rhino 5.0 to do some simple example for being familiar with 
the program language.
It is similar to the RhinoScript, but different language to 
describe the CODE. 

Python是蟒蛇的意思
所以這張椅子的造型也有蟒蛇的感覺

PYTHON is also a kind of snake.
so the FORM fits to its name.

簡單來看
就是將三條曲線
做等分之後
連結其等分點
The code is just divide three reference 
curves and connect them and pipe them.






看起來像個烏賊在他形塑的時候
it looks like a squid when it is forming.

謝謝 Jose Sanchez給的VIMEO tutorial影片

Thanks for Jose Sanchez's 
to get me into the python world.
They are good tutorial to go step by step to learn it.





有些簡單規則要注意
大小寫很敏感
空格很重要
不要讀該行 要用 "#" 符號

There are some rules we have to know:
Python is Case Sensitive
Python is Indent Sensitive
The " # " sign is used for comments, the computer will skip over them.

pythonScript here:
import rhinoscriptsyntax as rs
class myClass:
    
    def __init__ (self, _strCurve01, _strCurve02, _strCurve03, _numberDivide):
        self.strCurve01= _strCurve01
        self.strCurve02= _strCurve02
        self.strCurve03= _strCurve03
        self.numberDivide = _numberDivide
    
    def drawLineBetweenCurves(self):
        ptList1= rs.DivideCurve(self.strCurve01,self.numberDivide,True,True)
        ptList2= rs.DivideCurve(self.strCurve02,self.numberDivide,True,True)
        ptList3= rs.DivideCurve(self.strCurve03,self.numberDivide,True,True)
        rs.Command("selCrv")
        rs.Command("delete")
        
        for i in range(0,self.numberDivide):
            rs.AddLine(ptList1[i],ptList2[i])
            rs.AddLine(ptList2[i],ptList3[i])
            rs.AddLine(ptList3[i],ptList1[i])
            rs.Command("selCrv" )
            rs.Command("join")
            rs.Command("selLast")
            rs.Command("_Pipe 1 Enter" )
            #circles = rs.AddCircle3Pt(ptList1[i],ptList2[i],ptList3[i])
            #circleAll = rs.GetObject(circles,4)
            #rs.selObject(circleAll)
            
strCurve1 = rs.GetObject("select 1st curve",4)
strCurve2 = rs.GetObject("select 2nd curve",4)
strCurve3 = rs.GetObject("select 3rd curve",4)

obj1 = myClass(strCurve1,strCurve2,strCurve3,79)
obj1.drawLineBetweenCurves()
rs.Command("SelNone")
rs.Command("SelPt")
rs.Command("delete") 



1 則留言: