How to use IGH_VariableParameterComponent in component written in ghpython?

Hi all,
I want to creating custom component with variable number of inputs, but after searching the forum, none on this. I tried to implement in ghpython, but seems the input number is not as that in C#:

Why it takes 3 arguments? according to this:
https://developer.rhino3d.com/wip/api/grasshopper/html/T_Grasshopper_Kernel_IGH_VariableParameterComponent.htm
I suppose 2 arguments is enough, am I losing something?
Since the first time compiling my own components, and I have no knowledge about C# or VB. That’s no suprising my method is totally wrong. :sweat_smile:

Here is your answer, in C#

Ps: don’t learn python if you are just learning to program, it has terrible programing practices, go for C++ or C# or even the Java version that processing uses (forgot the name of it).

3 Likes

haha I 've saw your this nice answer days before and downloaded the clean sample! :grinning:
Thanks a lot for your prompt reply. In fact I’m working on research and the main practice is on matlab and python(for data exchange and visualization), that’s why I haven’t any knowledge on C#. So for primary modify of data structure, the ghpython is enough, until now… The C# learning curve is sooo… :upside_down_face:

So @piac can this function work on ghpython? Is there some more deep tutorial on python beyond this?

By the look of the link, it should be possible, you just have to translate my example to python. Well I would still suggest for you to do your data structure stuff in C# though. If you get stuck down the road you can always post in the Dev group and we can help.

Probably Giulio developed that workflow specially thinking on how to help Butterfly and Honeybee compile the plugin in a more robust way.

@rawitscher-torres Thank you so much for your patience. The only thing is I have no knowledge in C#, so I installed the Visual studio, and try my best typping things like the C# example, and many question rises:

  1. Is this kind of block function like the ‘def’ in python?
    and why declare the int index but in the block don’t need to set or use it

2.I’ve notice the tips in the python compiler like below:


so I type like this:

def CanInsertParameter(self,side,idx):
    if side==self.GH_ParameterSide.Input:
        return 1
    else:
        return 0

and no Error message, but after compiling, still can’t add variable input.
Definitly know there must be some silly operation, forgive me :rofl:

I do know that if I don’t compile the script, this component can run very well regardless of efficiency. But so curious of all this amazing function.
I think to upload my script is necessary.This is a tiny component to ‘juxtapose’ trees and remain their structure, which is very helpful for my data processing.
TreeAdding.gh (4.3 KB)

Yes, so anything in C# that is on the lines of


  public void Foo( method arguments)
        {


        }

will be a python function

def Foo(function arguments)
        pass

Make sure your JuxtaposeTree class implements the IGH_VariableParameterComponent interface
After that try compiling again using the robust method, and see if you can add variable inputs.

If it still wont work, I am afraid one of the python developers at McNeel will have to help you on this one, since I am not a big python user.

In C#, the component class inherits GH_Component and IGH_VariableParameterComponent.
While you can do that in python:
class JuxtaposeTree(component,[VariableParameterComponent])
I do not know what the [VariableParameterComponent] would refer to to get it to work.
Going into component base, you only get the following:

from GhPython.Assemblies import DotNetCompiledComponent as dotnetcompiledcomponent
from GhPython.Assemblies import ExecutingComponent as executingcomponent

For which the only reference is a 6 year old repository and seems to be missing the code.
So I don’t think we have any way of implementing the interface.

Considering what @christopher.ho clarified, maybe this will be a good excuse for you to switch over to C# :wink:

Just do an all day marathon so you learn the syntax, the rest is all the same logic.

1 Like

@Miracle_arc
I got bored on a sat, so here is the c# code equivalent of your code.
As well as the compiled .gha file.
JuxtaposeTreeComponent.cs (4.1 KB)
JuxtaposeTree.gha (10 KB)

1 Like

You are soooo nice! Now it’s time for me to learn line by line carefully! And thank you @rawitscher-torres. Now can wait for the great python developers’ explain how the python method. Hope they have spare time developing WIP :grin: