Active Contributor
36 Posts
2 Kudos
Registered: ‎12-05-2011
Post 1 of 2

C# Events - I need guidance!

221 Views, 1 Replies
03-19-2013 08:47 AM

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!


Valued Mentor
370 Posts
175 Kudos
Registered: ‎05-06-2012
Post 2 of 2

Re: C# Events - I need guidance!

03-19-2013 11:41 PM in reply to: Ixath

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).



Post to the Community

Have questions about Autodesk products? Ask the community.

New Post