I'm teaching myself C# for the sole purpose of writing plugins. I have a basic/intermediate knowledge of java and lisp but I'm not good enough yet to fully understand many of the concepts.. so please bear with me. One final note is that I'm actually writing a plugin for Navis and that's what I really need help with.. but the Navisworks API forum is dead. The theory and process should be the same though, so that shouldn't matter.
What I have working
Every time my plugin is loaded it reads the start/end points of the active Measurement (very similar to Distance in the data it provides), assigns them to a variable, and then calculates where those points would be if they were rotated 45 degrees. It then writes the new location to a textBox inside of a dockable window pane. All of this works perfectly.
Where I'm having trouble
I don't want to run the plugin each time a new measurement is made. I want my textboxes to update automatically each time the user draws a new measurement. I could add a button to do the calculations but I'd rather have everything done automatically.
Questions / What I think I need to do
I need to make an event handler that loads with the plugin. It should watch ActiveDocument.CurrentMeasurement.FirstPoint and .EndPoint for changes. As soon as it detects a change it executs my GetPoints() method which does the calculations and updates the text box. After GetPoints() executs the event handler will go back to watching for changes in FirstPoint and EndPoint. Is this correct?
The Navisworks API has a number of built in event handlers like:
public static event EventHandler<EventArgs> MainDocumentChanged
but none of them that I can find actively watch for changes in the measurements. The Measure Tools window pane contains the data for the measurement tools (x y z of start/end pos, distance between them, etc) and has a textBox for each value. My other thought was to make an event handler that watched those text boxes for changes and then ran GetPoints(), but I have no idea how to find out how to access/watch/call to (whatever) those specific textboxes.
Is an event handler the best way to achieve what I'm after or is there another way that would be that much better? If I could figure out how to extend the point-to-point measurement command could I add something to it that updated my additional text boxes every time it was ran?
Link to my original post in the Navisworks API forum if anybody is interested.
Thank you very much!
I can't tell you much about Navis as I've not done much with it, but what I would suggest if you don't get a better answer or find a more direct solution, is to open the NavisWorks assemblies in Reflector, and search for any classes that implement the INotifyPropertyChanged interface. This interface is non-specific and very generic, and simply allows an observer to get notified when a property on the observed object changes. It's quite possible that one of the API objects implements that interface, and assuming you have access to an instance of it, you can add a handler to it's PropertyChanged event, and when the event handler fires, you can examine the name of the property that changed (but not the value).
Access a broad range of knowledge to help get the most out of your products and services.