Last active
December 3, 2023 22:21
-
-
Save StepMaher/6eae99d6d12e033382e9 to your computer and use it in GitHub Desktop.
Reboots Grasshopper.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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