Rhino Python Lecture 2016 | DAY4

Contents

  1. GHPython – Intro
    1. Download and install
    2. UI
  2. GHPython – Input Parameter
    1. Input variable declaration
    2. Access
    3. Type hint
  3. GHPython – Output Parameter
    1. Output variable declaration
    2. “Out” value – Console
  4. Rhinoscriptsyntax in GH
  5. Practice
    1. Parametric spark model
    2. The Golden Spiral – convert Python code to Ghpython code

1. GHPython – Intro

1.1. Download and install

  1. Download Ghpython from this site — http://www.food4rhino.com/project/ghpython?ufh(required Registration and Sigh up)
  2. Drag and drop downloaded file to GH’s UI (= install)

1.2. UI

  1. Set GHPython Component
    set
  2. GHPython Editer
    • Start-up Ghpython Editer
      — Double Click Ghpython Component
    • Compare Python Editer and GHPython Editer
  3. compare


2. GHPython – Input Parameter

  • 2.1. Input variable declaration
    • Increase variable
      input1
    • Name(Rename) variable
      input2
      input_mark
    • Check input
      check
  • 2.2. Access
  • Input value requires specifying “data Access type”
    access

    • Item Access — Python or GH’s single value
    • List Access — Python’s List
    • Tree Access — GH’s DataTree
  • 2.3. Type hint
  • Input value requires specifying “Type hint”
    typehint


    3. GHPython – Output Parameter

    3.1. Output variable declaration

  • Increase variable
    out1
  • Name(Rename) variable
    out2
    Out_mark
  • Check output
    check_out
    Notice: Type hint of value “a” = int
    check_out_2
  • 3.2. “Out” value – Console

    “Out” value is preset output value. Connecting to Pannel Component, It show cosole data.
    out_console


    4. Rhinoscriptsyntax in GH

    rs


    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

    ex1

    • 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

    5.2 The Golden Spiral

    Please convert Python code to Ghpython code.
    golden

    • 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
    • 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)