Hi I’m trying to write a ghpython function that adds a value list to the python component when the component is dropped onto the canvas. I was able to figure out adding the valuelist part of the coding.The issue I’m having is when I make a user object of this python component and drop it onto canvas, the newly created value list is not taking the correct pivot location set. When I delete the valuelist component, that is when newly added valuelist is in the correct location. Does anyone know what might be causing this behavior? below is the code and my file. Any help is appreciated!
from ghpythonlib.componentbase import executingcomponent as component
import Grasshopper, GhPython
import System
import Rhino
import rhinoscriptsyntax as rs
import ghpythonlib.treehelpers as th
import Grasshopper
import Rhino.Geometry as rg
import Grasshopper.Kernel.Special as ghks
from System.Drawing import PointF
class MyComponent(component):
def RunScript(self, x, y):
def create_value_list(input_name, value_list_name, offset):
params = ghenv.Component.Params.Input
for i in range(len(params)):
param_name = params[i].NickName
if param_name == input_name:
if params[i].SourceCount == 0:
ghenv.Component.ExpireSolution(True)
params = ghenv.Component.Params.Input
valuelist = ghks.GH_ValueList()
valuelist.CreateAttributes()
valuelist.NickName = value_list_name
X_cord = params[i].Attributes.InputGrip.X - offset
Y_cord = params[i].Attributes.InputGrip.Y - 11
coord = PointF(X_cord, Y_cord)
valuelist.Attributes.Pivot = coord
Grasshopper.Instances.ActiveCanvas.Document.AddObject(valuelist, False)
ghenv.Component.Params.Input[i].AddSource(valuelist)
ghenv.Component.ExpireSolution(True)
create_value_list("x", "TEST",100)
Reference.gh (3.6 KB)