Grasshopper

algorithmic modeling for Rhino

Hi David,

A quick query on an aspect I've been thinking about.

I'm trialling integrating the structural analysis model generation tools I've written into Grasshopper.  The way this would work is a custom component could update my plug-in database of node positions and element connectivity.  What I'm wondering, is if there would be a way to force a model redraw at the completion of the Grasshopper calculation, as I don't want to redraw every time an individual change is made.  There's two options I'm thinking that could trigger this redraw, either catching an event in the plug-in event watcher (which I'm confident has not been implemented, and wouldn't be quick/easy).  Or to add a component which is forced to recalculate everytime Grasshopper triggers a recalculation.  This is more likely, have you any ideas on an easy way to implement this?

If I've not described the scenario adequately, let me know.

Cheers,

Jon

Views: 1838

Replies to This Discussion

Jon,

I'm somewhat confused. Grasshopper does trigger a redraw whenever a new solution completes.

There's already an event that gets raised whenever a Solution completes. Have a look at Grasshopper.Kernel.GH_Document.SolutionEnd(GH_Document doc)

This event is raised even if the document is locked so you may want to test that flag as well, but only when the RaiseEvents property of the GH_Document is set to true.

All this is probably going to change whenever I rewrite Clusters, as then we'll have GH_Documents running as part of a parent GH_Document. Now, the system has been designed on the premise that only a single GH_Document is active at any given time.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hi David,

This is probably not a procedure you'd recommend, but I'm looking at interaction with my plug-in independently with Rhino objects. My components would still output points and line curves which would be handled by Grasshopper as per usual for preview geometry. But the component would call on my plug-in to independently move existing points or curves, or generate them. Each point (or structural node) and curve (or beam centreline) in the Rhino model is tagged and identified, and I want them to be redrawn rather than duplicates added to the document. The other means of achieving the desired outcome is if my custom compents can add attributes (preferably userText) to the created objects from the bake operation.

I appreciate this is all likely to be subject to development changes, just fishing for options for immediate means. I can add a button/command to my plugin to regenerate my structural model manually (my component would have updated positions/connections in the background), but this is less desirable as the objects in the Rhino model will not be coordinated with the internal database until the user instructs it (which might not happen). My first idea in the post was if the plug-in could catch an event (similar to the start of a command, or the events for new documents, modify attributes etc etc) when grasshopper was redrawing to the conduit, that I could also update my model objects.

Is that any clearer? If not, I'll shortly post a working example and you can take a look if you have a moment. Thanks,

Jon
I don't fully understand what's going on, but that's hardly needed for me to help you out.

The only sure way to know whether or not Grasshopper just finished a solution is to listen to the EndSolution event on GH_Document. You can access this document from within any Script component and add a handler to it. If you need to access the GH_Document from the outside, you'll have to also handle all the DocumentAdded, ActiveDocumentChanged etc. event that are thrown by the GH_DocumentServer. This is the only way to always respond to the currently active document.

If you implement your own DisplayConduit, you can also respond to redraws. Simply treat a call to ExecConduit as a cue that a redraw is in progress. But whether the redraw was caused by Grasshopper or by the user rotating the view or by some other command will be impossible to figure out at that point.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hi David,

Your reply sounds good, but I'm struggling with the exact means to add the event Handler.

I've attached my attempt if it helps. I assume this can be added as an isolated component to the Grasshopper document. Also, can I force my own c# components to recalculate on a start solution event (regardless of change or not to inputs)? At the moment I'd like to do this (I know there will be a penalty to recalculation times) but it makes a clean approach if I reset my internal database and add everything again rather than try to track which components had generated which items and what has changed.

Thanks a lot for your help, as always it's appreciated a lot.

Jon
Attachments:
Hi David,

So, I've posted a WIP screen capture of what I'm trying to do (it might not explain fully, but hopefully it helps). There are still some teething problems I'm working on that may be evident, but it's very close to a solution if I can capture events.

Video Screen Capture Grasshopper to GSA

What I'm trying to show manually in this video, are the procedures I'd like to call from event driven reactions. Prior to recomputing the solution, I reset my plug-in database of structure so that previously generated (or my own internal baking procedure) get deleted. Then I recompute the solution (so I would like to call the reset function from the event or start Recalculation), and then on completion, call on the plug-in redraw command (which would be executed from the Solution Complete event). As I mentioned in the last post, it would also be useful to "force" recalculation of my c# components every time a grasshopper recalculation takes place.

Using reflection, I studied the events and event handlers present in Grasshopper, but I still could not add my own event handlers (sorry). A VB.NET solution works for me if it's easier for you. I've attached the Grasshopper definition shown in this video if it helps at all, but it won't work until I update the public build of the plug-in which I'm hoping I can do when I have events handling the manual steps.

Thanks a heap in advance if you can help,

Jon
Attachments:
Does the attached hold any useful clues?

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Attachments:
At first glance, that looks brilliant. Thank you very much. I'm busy integrating it into my definition, and will get back to you.

Thanks,

Jon
Ok, that's really great. Perfect example David, just what I needed.

Now, I just have one outstanding issue that I mentioned and can't see covered. When I reset my model, I need to force my custom components to recalculate on the event of solution start regardless of if the inputs to the component have changed. I don't think I can set an event handler for this as it relies on the information being fed in from downstream components. This might not be easily achievable. It would be nice to do this because if I only make a change a long way upstream, I still need to recalculate downstream components (to save tracking what components are generating which objects).

Also (not that I want to make any extra work for you), I can now get a repeatable Rhino crash when altering this Grasshopper definition with the event watcher. I can give you instructions on how to repeat it if you want to know about it and have a look.

Cheers,

Jon
Hi Jon,

let's see what happens with this crash in 0.7. It'd be pointless to try and fix the 0.6. code.

I'm still trying to wrap my head around your other request.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Is there a way of triggering the entire solution being calculated (similar to the Recompute menu option)?
If I put it in the StartSolution event, I'd have to put it in a lock, to make sure it didn't recursively trigger a recalculation. Possibly making redundant computations, but would work (I think). For the time being manual recompute might be required, but that's not the end of the world.

I actually didn't trace the crash before I posted, so I'll check if I can fix at my end. Waiting for the next version is fine.
Jon, I send you a personal message.

--
David Rutten
david@mcneel.com
Poprad, Slovakia

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service