I realise this is probably something I should be writing in a compiled component, but:
I’m fiddling about with some ideas that involves assigning data to output parameters, without assigning them as usual (that is, via the implied link between the parameter name and the variable name in the code) but instead based on their index. As far as I’ve been able to gather, this requires going through the GH_Param for the output parameter and implementing one of the methods there for adding/appending data. This appears to work somewhat, but I wonder if this is even the “correct” approach?
For instance, in this minimal example I get “strange” nulls if the GHPython components have input parameters, but things appear to work as (I) expected without any inputs:
180913_AddVolatileData_GHPython_00.gh (4.7 KB)
I’ve tried other approaches as well, such as accessing the GH_Structure of the parameter directly and calling
AppendRange etc, with the same result as above.
Any inputs here would be great.
GhPython does not find the “a” variable, and assigns “None” to the output. There’s nothing that can immediately be done regarding that.
What are you trying to solve here? Why can’t you just swap the variable names? Or construct a DataTree/GH_Structure and pass it out to the variable name?
for Robert McNeel & Associates
Ah yes, that makes sense. Just for completeness, how come this doesn’t occur in the two examples without input params?
We’ve been following a pattern lately that involves shoving large chunks of agnostic data (mostly environmental analysis stuff, but also geometric information) from various sources (also outside of Rhino/Grasshopper) into Python dictionaries and pickling these to file. Making for a simple/uniform method for serialising and interfacing data across our platforms.
On the Grasshopper side, I’ve been adding input/output parameters through the ZUI when pickling and unpickling these database files, assigning the dictionary values by their keys to the input/output params. This works just fine, but I/we were getting kinda tired of performing this manually. So I was experimenting yesterday with automating the process. I’ve got the write/pickling component working (i.e. iterate the input params: get their nicknames and harvest their volatile data, shove all this into a dict and pickle it). And sorta have the read/unpickle component working, apart from a series of funky behaviours one might expect while being naughty.
I can share the full example when I’m back in the office. I wonder though, this probably is something I should be able to do in a non-naughty way using the compiled GHPython mode right? If so, could you perhaps provide a small snippet of how to add output parameters and assign data to them?
The components without inputs get executed because their code has not been evaluated yet. The other gets executed for the iteration
x == None and
y == None.
For the second part, it sounds like you might want to pack all your info into a single class and pass that around. If you are adding too many outputs, that might be simpler. You cannot add or remove outputs during a solution (Grasshopper demands that).
I’m not talking about passing around data within a Grasshopper definition, but between multiple platforms that expose a Python interface (Blender, Revit/Dynamo, Google Sheets, CFD, etc). Where a problem within this platform (i.e. Grasshopper), has been how to unpack a Python dictionary with a minimum amount of manual labour (it isn’t much work, but tedious and error prone). Here’s a minimal example, just imagine that the
Dict input on the second GHPython is unpickled from a file on disc:
180914_DictToParamsOutput_GHPython_00.gh (14.7 KB)
Right, but could one imagine a (compiled GHPy perhaps) component that is passed a dict, iterates the key/value pairs, adding an output parameter named after the key and assigning the value to it? As I said, I did manage to throw together a somewhat working example of this (somewhat being the key word), but I feel like I’ve definitely seen compiled components that behave similar to this (i.e. automatically adding outputs based on inputs), I might be misremembering though.
Edit: I was thinking about
Bang!, which does in fact not automatically add the outputs, but raises a warning prompting the user to add them. That’s also probably the way to go here, but does still leave me with the problem of assigning the data without the
You are not allowed in those terms.
What you could do is change at any point after the solution has finished updating. For example via a right-click menu similar to “Explode Tree → right click → March output”.
Personally I would just compose the right datatree – using
ghpythonlib.treehelpers – and then pass it to the “Explode Tree”.
EDIT: In case you think it’s worth to pursue the “Match outputs” option, here is a sample for Rhino 6 - only for the sake of completion, do not use in production code:
set-outputs.gh (3.5 KB)
for Robert McNeel & Associates
Cheers Giulio, that does indeed seem pretty convoluted for something that might simply be output as a datatree. That’s a nice and simple solution, think I’ll just go down that route. Good with some input on this
Did you finally found a way to update your component volatile data automatically ?
No I never did find a good reason to do so.
i checked your component as i was searching for something similar on the forum - but stumbled across some odd behaviour at first glance.
When i move the comp after updating all the wires break off?! any suggestions on that? my knowledge of pyhton is to superficial to get it working…
thx in advance,
Yes, mangling with the components on the canvas can have unintended consequences. I strongly suggest to use normal Grasshopper logic and not modify inputs or outputs.
This is only for educational purposes. I’ve added a note above.