Viewpoint manipulation and threading in 2013 .NET API
Hi all,
So I've got my hands on 2013 and am exploring the new Viewpoint functionality within the API. Ultimately, I'm continuing to look at building a custom 3D mouse plugin for Navisworks that can move the camera around in 6DoF. So I'm taking things one step at a time and have code similar to examples I've seen online to:
A) get the current active document
B) get the current active viewpoint from the document
C) create a copy of the current viewpoint
D) modify some aspect of the copy of the current viewpoint (change position, for example)
E) reset the current viewpoint of the current document with the copied viewpoint (containing the new position) using the CopyFrom() method
Of course this works just fine when called as a one-off command within the plugin Execute() method. But ultimately I'd like to package this functionality into a separate thread that runs a continual loop, retreiving data from my device and updating the camera accordingly.
So when I put this code in a separate function, use it to create a thread object, and call start on that thread in Execute(), I get an InvalidOperationException when calling CopyFrom() on the current viewpoint within that thread. I've narrowed it down and know that CopyFrom() is causing the problem but I don't know how to fix it or further debug it. It seems as though there is a problem with modifying the document's current viewpoint from a separate thread that is not the main plugin thread, but why would this be the case? The exception seems to indicate that I'm trying to do an operation on a resource that is closed or not available... possibly, but if this is the case I don't know how to proceed.
I would think this functionality should be available. Has anyone else run into this trying to do modify operations in separate threads? Anything I may be missing?
Thanks,