algorithmic modeling for Rhino
Hi,
I'm trying to write a script to retrieve slider's domain.
Being a total newbie in the languages used by GH, I tried to fix some Python I found on the web. It works, but only for sliders that are created after the python component itself. Also sometimes with the existing ones, but that looks really random, I can't figure out why.
Any idea ?
Here is the code I used :
"""
Retrieve a named slider's domain.
Args:
Sliders: Slider NickNames.
Update: Set to 'True' to update information.
Returns:
Start: Slider domain start.
End: Slider domain end.
Domain: Slider bounds as domain.
"""
# Name component
ghenv.Component.Name = "Slider Domain Retriever"
ghenv.Component.NickName = 'Slider Retriever'
# Import libraries
import Grasshopper as gh
# Get to the GH objects
gh_objects = ghenv.Component.OnPingDocument().Objects
ghenv.Component.Params.Input[0].NickName = "Sliders"
ghenv.Component.Params.Input[0].Name = "S"
ghenv.Component.Params.Input[1].NickName = "Update"
ghenv.Component.Params.Input[1].Name = "U"
ghenv.Component.Params.Output[0].NickName= "Start"
ghenv.Component.Params.Output[0].Name= "Start"
ghenv.Component.Params.Output[1].NickName= "End"
ghenv.Component.Params.Output[2].NickName= "Domain"
#ghenv.Component.Params.Output[3].NickName= "Value"
if Update:
# Iterate objects
for obj in gh_objects:
# Set the named slider values
if obj.NickName in Sliders:
# Get [Number Slider] objects with NickNames
if type(obj) is gh.Kernel.Special.GH_NumberSlider:
# Find mininimum and maximum values
Start = obj.Slider.Minimum
End = obj.Slider.Maximum
Domain = str(Start)+' to '+str(End)
#Value = obj.Slider.Value
# Update slider information
obj.ExpireSolution(True)
Tags:
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by