Grasshopper

algorithmic modeling for Rhino

Hi,

I am new to python. I am trying to read simple bouncing ball example.

Can you explain me what sc.sticky function do here?

Maybe you could give me a link to scriptcontext documentation?

# Add the count variable to the sticky dict
if "count" not in sc.sticky:
sc.sticky["count"] = rs.VectorCreate(StartPt, org)
if "vel" not in sc.sticky:
sc.sticky["vel"] = rs.VectorCreate(dir, StartPt)

def re():
if Reset:
sc.sticky["count"] = rs.VectorCreate(StartPt, org)
s = rs.VectorCreate(dir, StartPt)
sLen = rs.VectorUnitize(s)
sc.sticky["vel"] = rs.VectorScale(sLen, length)
return

def bound():
if sc.sticky["count"][0]> box[0] or sc.sticky["count"][0]< -box[0]:
sc.sticky["vel"][0] = - sc.sticky["vel"][0]
if sc.sticky["count"][1]> box[1] or sc.sticky["count"][1]< -box[1]:
sc.sticky["vel"][1] = - sc.sticky["vel"][1]
if sc.sticky["count"][2]> box[2] or sc.sticky["count"][2]< -box[2]:
sc.sticky["vel"][2] = - sc.sticky["vel"][2]
return

def main():

print(sc.sticky["count"])

if Toggle:
ac = sc.sticky["count"]
bc = sc.sticky["vel"]
add = rs.VectorAdd(ac, bc)
sc.sticky["count"] = add
print(sc.sticky["count"])

bound()

# Reset the count
re()

# Return count to GH
Count = sc.sticky["count"]
pt_x = sc.sticky["count"][0]
pt_y = sc.sticky["count"][1]
pt_z = sc.sticky["count"][2]

a = rs.AddPoint(pt_x, pt_y, pt_z)

return a

a = main()
b = box

Views: 791

Replies to This Discussion

Hi Petras

scriptcontext is a small Python module that ships with rhinoscriptsyntax. It contains just a few variables that are used in the context of a script: the target document (doc) that is implied when you use "AllLine()" and a sticky dictionary (sticky) that is shared between Grasshopper and Rhino are two things that come to mind.

It's open-source. You can step into it with the debugger when using the _EditPythonScript editor in Rhino.

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service