algorithmic modeling for Rhino
I have a grasshopper cluster with nickname MyCluster. It outputs a series of curves. The output param name is MyOutput. I want to write a script that gets the data in MyOutput ( as a tree ) without connecting it to anything. How do I do this ? Python preferred.
Thank you.
Tags:
If you want to do this during a solution, you must make sure that the output has been solved before you harvest the data. If you're doing this outside of solutions you can be certain that the data has been calculated.
Either way you'll have to get a hold of the GH_Document your component is running in, iterate over all objects in that document, find your cluster, (make sure the cluster is computed, not just expired) get a hold of the correct output and access its VolatileData.
I can show you in C#, but not Python.
Thanks for the quick reply. I want it only after solution. I didn't understand what you meant by "outside of solutions".
I am using OnPingDocument() an iterating through objects till I find a NickName match. I can then get object.Params.Output[0] but it doesn't contain what I'm looking for. I can go with C#. I'll try finding the equivalent Python method.
Thanks
Hi David,
Sorry to bother you, but did you have time to look at it ?
PS:- I'm going to use this in the upcoming SmartGeometry in Gothenburg. I am a cluster expert in the Parallel Parametrics cluster. I could also use some help with some other things, if we could talk about what we're doing for the cluster.
Best,
To be fair, I don't think I fully managed to test the Collect/Compute calls that the script makes on the cluster in case it hasn't solved itself yet, so if you're getting nulls when you're expecting data (or even weird error messages), let me know.
Thanks for the solution, I'm not getting nulls but it does not change if the output changes, ie - if I change the slider of my cluster, the output geometry collected by the C# component doesn't change, it's still the same. Maybe we need to add event handlers ?
Best,
Ah no it doesn't, there's no logical connection between the script and the output so Grasshopper doesn't know to expire the script when the cluster changes. However you initially said that your code was supposed to run outside of solutions (presumably when someone presses a button manually) so I figured this wouldn't be a problem.
It's difficult to use events because you don't know which cluster and which output you're supposed to be working with until the solution is already in full swing. So unless you can somehow know for sure that the output you're looking for this time will be the same one you will be looking for next time you can add an event handler for when the cluster expires.
Or you can add a handler for the GH_Document.SolutionStart event and expire your own script component if the cluster is expired, but there's a potential bug here since the cluster might be expired after you handle that event.
It's beginning to look like you're digging a deeper and deeper hole that wouldn't be necessary if only you'd connect a wire up to the output whose data you want.
So thanks again.
So unless you can somehow know for sure that the output you're looking for this time will be the same one you will be looking for next time you can add an event handler for when the cluster expires.
How do I achieve this ? My cluster.NickName and output node name doesn't change. The cluster may get modified though.
I can't connect a wire, because this needs to be automated. It will happen on a remote machine. If you have time, I'd love to share details with you. You can look up SmartGeometry > Parallel Parametrics for an overview of what we're doing.
Best,
How do I achieve this?
I don't know. You can duplicate Grasshopper solution logic to a degree, for example if you input the cluster+output name using Text Panels that themselves have no sources I suppose you could look in the user strings of those panels, but that really limits what sort of objects you can use to control your component.
The attached script handles the SolutionStart event and always expires the script component. You could try and make that smarter...
Thanks ! It works fine, I can do with this. For multiple harvests I use multiple instances of this component ( I know not the cleanest way )
The cluster that I want to harvest data from is updated remotely as well. I do a document ping, and loop through ghObjects and check for a nickname match, then I
input.Sources[i].Slider.Value = value
obj.ExpireSolution
<to update the sliders. Although I face no problems with the cluster harvest, I'm sometimes getting a weird "Expired Solution" warning window when I bake GH geometry and export to OBJ via python, and right click stops working on the canvas, till I do another export ( I use rs.Command("long string with export OBJ options")
)
Do you think these are related ? Turning out to be a major pain.
Can I see the actual error message?
Ok, I can't replicate the "Solution Expired" warning anymore. I had some errors in my code and I fixed them. I can't tell if they were related. Also, I am using Flux.
The data I harvested with your script was being sent through Flux, and it was causing Flux to behave strangely, often not updating values. When I stopped using your script, Flux behaves fine. I also noticed an asterisk constantly next to the file name, even if I save it. So I'm looking for workarounds.
Now, however, my biggest pain is after I bake and export geometry, the entire canvas becomes unresponsive. There's a button I click to do a bake & export. After clicking once, right click and left click stop working on the canvas and nothing can be added. But strangely, the same button accepts a click, and the canvas becomes responsive again. So weird !
Here's the code I referred to, and below is mine
baked = gh.BakeDataInObject(comp_guid)
rs.Command("_SelNone", True) rs.Command("_SelLast", True)
command = '-_Export "{}{}{}" {}'.format(path, uid, "."+"obj", e_str) # e_str defined in link, albeit minus detailed options
rs.Command(command, True)
rs.Command("_SelLast", True)
rs.Command("_Delete", True)
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by