Hello
How we find the count of inputs and outputs of component
print "number of inputs: " + str(ghenv.Component.Params.Input.Count)
inputs = "input names: "
for input in ghenv.Component.Params.Input:
inputs += input.Name + ", "
print inputs
print "number of outputs: " + str(ghenv.Component.Params.Output.Count)
outputs = "output names: "
for output in ghenv.Component.Params.Output:
outputs += output.Name + ", "
print outputs
ComponentParameters.gh (13.4 KB)
Thank you, work fine except the components which don’t have input like Button or other components like panel, curve …
i need to find a way to separate them
You can figure out what members are there for an object by using dir(obj). Use that to see “inside” them. You could also use it to check during runtime.
You can also check if an object is a component like this:
import Grasshopper as gh
objects = ghenv.Component.OnPingDocument().Objects
name = []
input = []
output = []
for obj in objects:
name.append(obj.Name)
if gh.Kernel.IGH_Component in list(type(obj).__bases__):
input.append(obj.Params.Input.Count)
output.append(obj.Params.Output.Count)
else:
input.append('-')
output.append('-')
ComponentParameters.gh (16.0 KB)
Thanks i will try that
Thank you i will try it
Work fine but don’t find all inputs and outputs
Maybe suggestion of @nathanletwory will separate them all and find different cases
This is the definition if someone want add more features like input/output names; wires, different input/output cases …
component in rhino.gh (17.5 KB)
These input params implement Grasshopper.Kernel.IGH_Param. The following works:
import Grasshopper as gh
import GhPython
import rhinoscriptsyntax as rs
ghObjects = ghenv.Component.OnPingDocument().Objects
points = []
bndsPt = []
bndsH = []
bndsW = []
names = []
name = []
input = []
output = []
for obj in ghObjects:
pivotX = obj.Attributes.Pivot.X
pivotY = obj.Attributes.Pivot.Y
pvt = rs.CreatePoint(pivotX,-pivotY)
points.append(pvt)
bndX = obj.Attributes.Bounds.X
bndY = obj.Attributes.Bounds.Y
bndPt = rs.CreatePoint(bndX,-bndY)
bndsPt.append(bndPt)
bndW = obj.Attributes.Bounds.Width
bndH = obj.Attributes.Bounds.Height
bndsW.append(bndW)
bndsH.append(-bndH)
name = obj.NickName
names.append(name)
if gh.Kernel.IGH_Component in list(type(obj).__bases__):
input.append(obj.Params.Input.Count)
output.append(obj.Params.Output.Count)
elif gh.Kernel.IGH_Param in list(type(obj).__bases__):
input.append(0)
output.append(1)
else:
input.append(0)
output.append(0)
Pivots = points
Corners = bndsPt
X = bndsW
Y = bndsH
names = names
import Rhino.Geometry as rg
import Grasshopper as gh
objects = ghenv.Component.OnPingDocument().Objects;
names = []
grips = []
bounds = []
plane = rg.Plane.WorldXY
for obj in objects:
names.append(obj.Name)
bound = obj.Attributes.Bounds
plane.Origin = rg.Point3d(bound.X, -bound.Y, 0)
bounds.append(rg.Rectangle3d(plane, rg.Interval(0, bound.Width), rg.Interval(0, -bound.Height)))
if gh.Kernel.IGH_Component in list(type(obj).__bases__):
for input in obj.Params.Input:
grip = input.Attributes.Pivot
grips.append(rg.Circle(rg.Point3d(bound.X, -grip.Y, 0),2.0))
for output in obj.Params.Output:
grip = output.Attributes.Pivot
grips.append(rg.Circle(rg.Point3d(bound.X+bound.Width, -grip.Y, 0),2.0))
else:
if obj.Attributes.HasInputGrip:
grip = obj.Attributes.InputGrip
grips.append(rg.Circle(rg.Point3d(grip.X, -grip.Y, 0),2.0))
if obj.Attributes.HasOutputGrip:
grip = obj.Attributes.OutputGrip
grips.append(rg.Circle(rg.Point3d(grip.X, -grip.Y, 0),2.0))
ComponentParameters.gh (16.6 KB)
Thank you @nathanletwory , Thank you @Mahdiyar
I will check the files
Is there a way to find the exact coordinates of grips targets?
Method used by @Mahdiyar give Bounds or Pivots but the points are not above output points;
i tried to separate inputs/outputs and find closest point to the target but i stop here.
I think there is a simple way from input parameters
ComponentParameters (4).gh (26.8 KB)
I think this work
rs.CreatePoint(tar.X+tar.Width,-tar.Y-(tar.Height/2))
Is it possible to extract icons of components? I want use them as textures
I tried python component but the script don’t detect the inputs
Yeah, each IGH_DocumentObject has an Icon property which returns a 24x24 pixel System.Drawing.Bitmap. Or it might return null in some cases, so check for that.











