Skip to content

Instantly share code, notes, and snippets.

@StepMaher StepMaher/reboot_GH.py
Last active Nov 4, 2015

Embed
What would you like to do?
Reboots Grasshopper.
"""
Reboots Grasshopper.
Inputs: Reboot: Set to 'True' to reboot Grasshopper.
"""
ghenv.Component.Name = "Reboot Grasshopper"
ghenv.Component.NickName = 'GH-Rebooter'
# Stephen P. Maher / 2015
# Many thanks to Andrew Heumann for the help.
import Grasshopper as gh
import System.Drawing as sd
import rhinoscriptsyntax as rs
comp = ghenv.Component
ghdoc = comp.OnPingDocument()
canvas = gh.Instances.ActiveCanvas
hasExecutedOnce = False
# The array accessor lets you pick which input you want
targetInput = comp.Params.Input[0]
# Define a function to expire this component.
def expireThis(doc):
hasExecutedOnce = True
comp.ExpireSolution(False)
# Make sure the input doesn't already have a button
if targetInput.Sources.Count==0:
# Create the button
button = gh.Kernel.Special.GH_ButtonObject()
# Recompute this component so that it has access to the value of the button
if not hasExecutedOnce:
# Add the button
ghdoc.AddObject(button,False,ghdoc.ObjectCount+1)
thisPivot = targetInput.Attributes.Pivot
# Set the button location
button.Attributes.Pivot = sd.PointF(thisPivot.X-200,thisPivot.Y-10)
# Connect the button
targetInput.AddSource(button)
# Expire the solution
ghdoc.ScheduleSolution(5,expireThis)
if Reboot:
rs.Command("_GrasshopperUnloadPlugin", True) # Unload Grasshopper
rs.Command("_Grasshopper", True) # Reload Grasshopper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.