Dynamo API Events


#1

Can anyone explain what each workspacemodel event does in Dynamo? I have been playing with them but I cannot seem to figure out what event triggers them. The descriptions are rather vague too.

http://dynamods.github.io/DynamoAPI/Dynamo_Graph_Workspaces/WorkspaceModel/#events

RequestNodeCentered
CurrentOffsetChanged
Cleared (several have a Cleared event but not sure what it is)
Note (Added Removed Cleared)
Annotation
Connector
MessageLogged

Thanks


#2

The added and removed events are for when some type of element is added to the workspace (ie nodes, notes annotations and connectors). This is useful if you want to know if the user has added or removed something and react to it… for instance, i have an extension that listens to new groups (annotations) being made so i can automatically change the colour. I also have another extension that tracks nodes being used, so i need to know when they are added/removed.

When a graph is closing/clearing, from what i understand all elements are cleared, that’s to say, unloaded from the graph space. I haven’t found a need for this event, but you might.

I havent used the request node centered event nor the current offset changed, but i can only assume the first is when the user focuses on a node via the [ ] button and the latter is when the user is panning in the graph (not sure on these though, just a guess until I test or someone else corrects me, try fire up a message box or put a breakpoint to flag when the event is fired).

There’s also the PropertyChanged event which is very useful and allows you to watch for certain changes to named properties. I would suggest leaning about MVVM patterns if you dont know what this is.

I would recommend searching on the Dynamo Github as there is usally something that has what you need in it, maybe in the tests directory. Pretty much how i started learning. I also think there is some learning material on there too and also on AU website from the past AU Vegas classes.

I hope that helps a little.

Cheers,
Dan


#3

@Steven

I wrote something very quick in my lunch you might find useful…

This tracks all the WorkspaceModel Events and lists them in the window as they happen. You can find the source code here. Feel free to copy it completely and make it your own. It is built using Dynamo API v2.0.2 and is ‘as is’…

This should hopefully help you with understanding what is happening and when.

Cheers,
Dan


#4

Wow while your first explanation was great this was something else. This is definitely going to help with what I am trying to do.

Thanks Daniel,


#5

You’re welcome @Steven,

I remember starting to learn all this just over a year back and how frustrated I was with the lack of info, the lack of descriptions in the API and no tutorials/documentation. However, I found learning MVVM/WPF very useful to understanding the API though and how Model, ViewModels and Views interact. Once you learn that, the API doesn’t seem that flaky tbh. :slight_smile:


#6

I will check that stuff out for sure. Every time I go looking through the API I just get lost. It takes me forever to find stuff.