How to know what project user is workign on in the Event GrasshopperDocument.ObjectsAdded

Hey guys,

I have a tool that subscribes to the GrasshopperDocument.ObjectsAdded event.

Then everytime user adds a component to the canvas I save same info.

I need to also save the name of the model the user is working on, so far I have not found a way to do it.

Can you suggest something.

Thanks for the help guys,

Are you handling the ObjectsAdded event on the GH_Document or via the canvas? The canvas will relay the document events for whatever document is currently loaded, so you don’t have to worry about when documents get swapped, or loaded, or closed.

I think I found the way

I have this:
void addSourceChangeHandlerToNewlyAddedObjects(Object sender, GH_DocObjectEventArgs e)

The it seems Sender is the name of the project user is at the moment

The event arguments will also have a field for the document. Plus each object knows which document it belongs to, which you can do by invoking an event on the object and listening to the return value (OnPingDocument()). But note that not every object must at any time belong to a document.