algorithmic modeling for Rhino
Hi David (and Vicente and all),
I was wondering if there was any way to instanciate small definitions using VB.
For exemple: when we hold shift and select components, they seem to be added to some kind of buffer, and then we place those components at specific locations manually on the canvas, draw connections etc.
I would like to automate this kind of behaviour depending on my inputs (in a way that the component would select the good sets of components needed to build the mini-definition, and place them in a group on the canvas so we can move it afterwards. If it's possible to pre-draw the connections between a few components it would be even better).
Do you think it's possible?
Sure, you can try to do the following ...ah wait, you are asking David. Sorry. I'll go now.
Hehe, I updated my post for you Vicente :D
It's true that it's a bad habit to start with "Hi David", but as I was not sure there was someone else knowing the answer... (I did not found any similar topic on the forum).
Of the dozens of posts asking specifically for David, this is probably one of the more appropriate ones. I doubt someone else has a good answer for this, but you never know.
Sorry if I made you think I had an answer :P
The Grasshopper SDK is mostly open, some classes and methods are marked with the Friend/internal accessor and of course sometimes logic is handled within a single method and you can't get into the middle of this. Things like component instantiation and tab/panel clicks are typically not open enough to add additional functionality from the outside.
It is of course possible to insert both components and wires into a Grasshopper document. And it's possible to handle object addition events. You can also create your own widgets which allow you to draw stuff on the canvas and have special mouse handling for them.
All of the above will however require significant amounts of probably quite difficult code in a poorly documented section of the Grasshopper SDK.
Thank you for your answer David,
I will keep posting questions on this post when I will have decrypted a little more what I found about all this in the SDK.
Here's a dumb idea:
create an example configuration of the components you want to create, copy and paste them into a text editor, reverse-engineer the xml representation of the components, generate the xml in a script, and then force a "paste" to the canvas of that xml.
I know this sounds crazy but I've actually done it (for the admittedly trivial case of a stack of sliders with different values) and for all I know it's actually easier than doing it properly through SDK code, since the copy-paste interface handles some of the messiness. If an approach like this interests you let me know and I'll upload the file tomorrow - it's on my work machine.
This sounds really interesting, I will try do mimic this today with my components but if you can send me your exemple, I will be happy to study it.
Here you go.
Thank you! works fine!