Grasshopper

algorithmic modeling for Rhino

hey all .. I am just learning to integrate python into my workflow and have some very basic questions. if you could help me wrap my head around the mix of gh and python it would be greatly appreciated... 

Basically I am confused about how do i output things to different outputs on the gh component? for instance I have a simple definition which takes two points, makes a line then adds a vector to the end point of that line to make a third point...

heres the code thats inside my gh python component:

import rhinoscriptsyntax as rs
def test ():
...pt1=x
...pt2=y
...line= rs.AddLine (pt1, pt2)
...pt_3= rs.VectorAdd (pt2, (3,0,0))
...pt3= rs.AddPoint (pt_3)

...return (line,pt3)
a=test()

so this returns both the line and the point to output : a but i'd like the line to output to a and the point to output to b??? Up till now i just use a point component and a clean tree after that to get my list to just the point but im sure thats not the right way... any advice THANKS -Ethan

Views: 531

Replies to This Discussion

Hi Ethan,

You are returning a tuple from the function (line, pt3). Change the last line to:

a, b=test()

so first item goes to a and second item goes to b.

An alternative would be something like this:

results =  test()

a = results [0]

b = results[1]

Mostapha

thanks - that's very helpful! -ethan

follow up question:

say i have a tuple with three items and I want item 0 and 1 to output to a while 2 goes to b... how could I make a list of the tuple indexes that output to one output...

could i say

a = results [0],[1]  

b= results [2]

thanks again.

Also is there any way to filter by types... to say all points in a tuple go to a while all lines go to be and all surfaces go to c or something like that?

or even how would i say a = results [all except certain ones... say index number 3]

thanks!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service