How to import a grasshopper component into Python?

So, I want to import an component into python.

  1. I am not sure if I imported it right.
  2. I do not know how to continue without knowing the variables for the ().
  3. Is it just, like in this example, (Curves, Lenght, Path)?
  4. How to return the outputs? T_T

Do you know what I should do?
Thanks in advance for your response.

python shortestwalk 01.gh (12.2 KB)

I can’t try out ghpythonlib on Rhino 6 at the moment, but a good way of exploring these things in the absence of (good) documentation is using dir() and help() functions:

import ghpythonlib.components as comps
print dir(comps)
# ouch, that's too many to sift through.. let python do the filtering:

print [c for c in comps if c.lower().contains("shortest")]

# assuming you found it: 
help(comps.ShortestWalkComponent) # or whatever it's called

Edit: oops, made a typo myself - should be

print [c for c in dir(comps) ... 
1 Like

Thank you for your help.
I think I missed something.
Do you know what I missed?

python shortestwalk 02.gh (14.4 KB)

Looks like a typo…? That above code was not meant as a copy-paste and run snippet, just a guide on how to approach the problem.

1 Like

Yes, I did not understood it completely how to continue.

Do you know any example wherein people input a component, while knowing how to fill in the variables for input and output related stuff?

I found shortestwalk with Dir very quickly, but did not really see other stuff/documentation.
I think I missed something again.

I got this with help.

Help on namespace_object in module ghpythonlib.components

 |  Data and other attributes defined here:
 |  
 |      __init__(self) unbound <class 'ghpythonlib.components.namespace_object'> method

Do you know how to find out what is in the class?

Hmm, so it might not be a regular python object, there may be some tricky IronPython magic going on here that links the classes, that I’m not familiar with either.
I would run dir() on the object again, or try and initialize it ( looks like __init__ takes 0 arguments) and inspect the resulting class instance, just keep digging until something turns up.

(How familiar with Python are you? This might not be the best approach for a relative beginner. Also if you’re trying to solve a particular problem, that may be achievable with regular GH components)

1 Like

Just as information:

thanks, I guess the discussion from here can continue on the other thread.

1 Like

@Edward,

Can you try the following?

import ghpythonlib.components as gh
a,_,_,_ = gh.ShortestWalk.ShortestWalk(x,(),y)

Right click on the x and y params and set the Type hint to No Type Hint.

Also set the x parameter to List access

note: @piac, helped me understand this.

2 Likes