Skip to content

Instantly share code, notes, and snippets.

@StepMaher StepMaher/
Last active Jan 21, 2016

What would you like to do?
Add a slider with a given NickName to the Grasshopper Canvas.
Create a named number slider.
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):
# 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
You can’t perform that action at this time.