Rhino Python Lecture 2016 | DAY4
Contents
- GHPython – Intro
- Download and install
- UI
- GHPython – Input Parameter
- Input variable declaration
- Access
- Type hint
- GHPython – Output Parameter
- Output variable declaration
- “Out” value – Console
- Rhinoscriptsyntax in GH
- Practice
- Parametric spark model
- The Golden Spiral – convert Python code to Ghpython code
1. GHPython – Intro
1.1. Download and install
- Download Ghpython from this site — http://www.food4rhino.com/project/ghpython?ufh(required Registration and Sigh up)
- Drag and drop downloaded file to GH’s UI (= install)
1.2. UI
- Set GHPython Component
- GHPython Editer
- Start-up Ghpython Editer
— Double Click Ghpython Component - Compare Python Editer and GHPython Editer
- Start-up Ghpython Editer
2. GHPython – Input Parameter
Input value requires specifying “data Access type”
- Item Access — Python or GH’s single value
- List Access — Python’s List
- Tree Access — GH’s DataTree
Input value requires specifying “Type hint”
3. GHPython – Output Parameter
3.1. Output variable declaration
Notice: Type hint of value “a” = int
3.2. “Out” value – Console
“Out” value is preset output value. Connecting to Pannel Component, It show cosole data.
4. Rhinoscriptsyntax in GH
5. Practice
Please send your program data to Shuta by the end of the day
→ Submission is closed.
5.1 Parametric spark model
Please draw Parametric spark model as folowing figure by GHpython scripting
- Random value
- Lengths of spark’s lines
- Angles of spark’s lines
- Input value
- input value1 “n”:Number of spark’s lines
- input value2 “l”:Max length of spark’s lines
- input value1 “n”:Number of spark’s lines
5.2 The Golden Spiral
Please convert Python code to Ghpython code.
- Input value
- input value “n”:Number of Fibonacci terms
- input value “x”:X value of start point
- input value “y”:Y value of start point
- input value “z”:Z value of start point
- input value “n”:Number of Fibonacci terms
- Algorithm of drawing The Golden Spiral
import rhinoscriptsyntax as rs roopNum = 10 originPt = [0.0, 0.0, 0.0] for i in range(roopNum): if i == 0 : fn1 = 0 #the initial term of Fibonacci number fn = 1 #the first term of Fibonacci number else: fn = fn1 + fn0 #Fibonacci progression #Print Fibonacci Num print fn #Replacement of data for originPt if not i == 0: if i%4 == 0: originPt[0] -= fn0 elif i%4 == 1: originPt[1] -= fn0 elif i%4 == 2: originPt[0] += fn0 elif i%4 == 3: originPt[1] += fn0 #Drawing Recrangle rec = rs.AddRectangle(originPt, fn, fn) rec = rs.RotateObject(rec, originPt, 90.0*i) #Drawing Arc arc = rs.AddArc(originPt, fn, 90.0) arc = rs.RotateObject(arc, originPt, 90.0*i) fn0 = fn1 #Replacement of data for next step (f0) fn1 = fn #Replacement of data for next step (f1)