Last active
January 21, 2016 17:02
-
-
Save StepMaher/c0d98153593b3247f8cc to your computer and use it in GitHub Desktop.
Add a slider with a given NickName to the Grasshopper Canvas.
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
""" | |
Create a named number slider. | |
Inputs: | |
Name: Slider NickName. | |
Add: Set to 'True' to create the slider. | |
""" | |
# Name component | |
ghenv.Component.Name = "Slider Creator" | |
ghenv.Component.NickName = 'Slider Creator' | |
# Thanks to Andrew Heumann for his help. | |
# Import libraries | |
import Grasshopper as gh | |
import System.Drawing as sd | |
comp = ghenv.Component | |
ghdoc = comp.OnPingDocument() | |
canvas = gh.Instances.ActiveCanvas | |
# The array accessor lets you pick where to place the slider | |
targetInput = comp.Params.Input[1] | |
# Define a function to expire this component | |
def expire_this(doc): | |
comp.ExpireSolution(False) | |
# Create 'Add' toggle | |
if Add == True: | |
# Create the slider | |
Slider = gh.Kernel.Special.GH_NumberSlider() | |
Slider.NickName = Name | |
# Add the slider | |
ghdoc.AddObject(Slider, False, ghdoc.ObjectCount + 1) | |
# Set the slider location | |
thisPivot = targetInput.Attributes.Pivot | |
Slider.Attributes.Pivot =sd.PointF(thisPivot.X-200,thisPivot.Y-100) | |
# Recompute the component | |
if Add == False: | |
ghdoc.ScheduleSolution(5, expire_this) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment