<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Viewpoint manipulation and threading in 2013 .NET API in Navisworks API Forum</title>
    <link>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/3698250#M7292</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A) get the current active document&lt;/P&gt;&lt;P&gt;B) get the current active viewpoint from the document&lt;/P&gt;&lt;P&gt;C) create a copy of the current viewpoint&lt;/P&gt;&lt;P&gt;D) modify some aspect of the copy of the current viewpoint (change position, for example)&lt;/P&gt;&lt;P&gt;E) reset the current viewpoint of the current document with the &amp;nbsp;copied viewpoint (containing the new position) using the CopyFrom() method&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
    <pubDate>Wed, 14 Nov 2012 00:38:34 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-11-14T00:38:34Z</dc:date>
    <item>
      <title>Viewpoint manipulation and threading in 2013 .NET API</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/3698250#M7292</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A) get the current active document&lt;/P&gt;&lt;P&gt;B) get the current active viewpoint from the document&lt;/P&gt;&lt;P&gt;C) create a copy of the current viewpoint&lt;/P&gt;&lt;P&gt;D) modify some aspect of the copy of the current viewpoint (change position, for example)&lt;/P&gt;&lt;P&gt;E) reset the current viewpoint of the current document with the &amp;nbsp;copied viewpoint (containing the new position) using the CopyFrom() method&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2012 00:38:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/3698250#M7292</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-11-14T00:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Viewpoint manipulation and threading in 2013 .NET API</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/3747799#M7293</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if you have referred to the blogs below, could you provide a small sample project to show the problem? I cannot tell what happened with the the description only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In adition, did you mean the problem occurs when you running the plugin directly, right?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://adndevblog.typepad.com/aec/2012/06/navisworks-net-api-2013-new-feature-viewpoint-1.html" target="_blank"&gt;http://adndevblog.typepad.com/aec/2012/06/navisworks-net-api-2013-new-feature-viewpoint-1.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://adndevblog.typepad.com/aec/2012/06/navisworks-net-api-2013-new-feature-viewpoint-1.html" target="_blank"&gt;http://adndevblog.typepad.com/aec/2012/06/navisworks-net-api-2013-new-feature-viewpoint-2.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://adndevblog.typepad.com/aec/2012/06/navisworks-net-api-2013-new-feature-viewpoint-1.html" target="_blank"&gt;http://adndevblog.typepad.com/aec/2012/06/navisworks-net-api-2013-new-feature-viewpoint-3.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2013 05:58:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/3747799#M7293</guid>
      <dc:creator>xiaodong_liang</dc:creator>
      <dc:date>2013-01-08T05:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Viewpoint manipulation and threading in 2013 .NET API</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/3749653#M7294</link>
      <description>&lt;P&gt;The simplest case is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following code works as you would expect, moving the camera 1 unit in the positive X direction each time you activate the plugin.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Plugins;
using System.Threading;

using api = Autodesk.Navisworks.Api;

namespace ViewManipPlugin
{
    [PluginAttribute("ViewManipPlugin:ViewManipPlugin", "TME", ToolTip = "ViewManipPlugin by TME", DisplayName = "View Manipulation")]
    public class ViewManpiPlugin: AddInPlugin
    {
        public override int Execute(params string[] parameters)
        {
            moveCam();

            return 0;
        }

        private void moveCam()
        {
            Document doc = api.Application.ActiveDocument;

            Viewpoint curVP = doc.CurrentViewpoint;
            Viewpoint copyVP = curVP.CreateCopy();

            double inc = 1;

            Point3D pos = new Point3D(copyVP.Position.X + inc,
                                         copyVP.Position.Y,
                                         copyVP.Position.Z);
            copyVP.Position = pos;

            doc.CurrentViewpoint.CopyFrom(copyVP);
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now this code, the only difference being calling the moveCam() function from a thread, produces a System.StackOverflowException at the doc.CurrentViewpoint.CopyFrom(copyVP); line in moveCam().&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Plugins;
using System.Threading;

using api = Autodesk.Navisworks.Api;

namespace ViewManipPlugin
{
    [PluginAttribute("ViewManipPlugin:ViewManipPlugin", "TME", ToolTip = "ViewManipPlugin by TME", DisplayName = "View Manipulation")]
    public class ViewManpiPlugin: AddInPlugin
    {
        public override int Execute(params string[] parameters)
        {
            Thread t = new Thread(this.moveCam);
            t.Start();

            return 0;
        }

        private void moveCam()
        {
            Document doc = api.Application.ActiveDocument;

            Viewpoint curVP = doc.CurrentViewpoint;
            Viewpoint copyVP = curVP.CreateCopy();

            double inc = 1;

            Point3D pos = new Point3D(copyVP.Position.X + inc,
                                         copyVP.Position.Y,
                                         copyVP.Position.Z);
            copyVP.Position = pos;

            doc.CurrentViewpoint.CopyFrom(copyVP);
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;I'm trying to figure out why this function would produce that exception in a thread.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2013 23:18:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/3749653#M7294</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-01-09T23:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: Viewpoint manipulation and threading in 2013 .NET API</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/3752117#M7295</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can reproduce this problem. I think this may because the .NET API is &lt;STRONG&gt;not&lt;/STRONG&gt; thread safe, all calls to the Navisworks .NET API should be made on the same thread.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I tested with &amp;nbsp;camera of COM API, it looks working. &lt;SPAN&gt;&amp;nbsp;I have not a conclusion if camera of .NET API can work or not in a thread, however these are what I can see at this moment.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;public override int Execute(params string[] parameters)
{
      System.Threading.Thread t = new System.Threading.Thread(this.moveCam);
   t.Start();

   while (!t.IsAlive) ;
   return 0;
 }

      private void moveCam()
      {
          //Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument;

          //Viewpoint curVP = doc.CurrentViewpoint;
          //Viewpoint copyVP = curVP.CreateCopy();

          //double inc = 1;

          //Point3D pos = new Point3D(copyVP.Position.X + inc,
          //                             copyVP.Position.Y,
          //                             copyVP.Position.Z);
          //copyVP.Position = pos;

          //doc.CurrentViewpoint.CopyFrom(copyVP);

          ComApi.InwOpState10 state;
          state = ComBridge.State;
          ComApi.InwNvViewPoint NvViewPoint = state.CurrentView.ViewPoint;
          ComApi.InwNvCamera NvCamera = NvViewPoint.Camera;
          ComApi.InwLPos3f NvCamPos = NvCamera.Position;

          NvCamPos.SetValue(NvCamPos.data1 + 10, NvCamPos.data2 + 10, NvCamPos.data3); 
      }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jan 2013 07:37:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/3752117#M7295</guid>
      <dc:creator>xiaodong_liang</dc:creator>
      <dc:date>2013-01-14T07:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: Viewpoint manipulation and threading in 2013 .NET API</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/4319181#M7296</link>
      <description>&lt;P&gt;Yes, that is what I have found. Thanks for the confirmation&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2013 00:45:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/4319181#M7296</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-07-04T00:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Viewpoint manipulation and threading in 2013 .NET API</title>
      <link>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/4589793#M7297</link>
      <description>&lt;P&gt;Is there a solution for this problem?&lt;/P&gt;&lt;P&gt;I want to do the same, I have an input device and want to use it with Navisworks. I created a RenderPlugin, that manipulates the actual view with CopyViewpointFrom() inside of RenderModel(View view, Graphics graphics).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't use threads. The result is the same: It only updates the view if I keep the mouse moving...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stefan&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2013 20:03:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/navisworks-api-forum/viewpoint-manipulation-and-threading-in-2013-net-api/m-p/4589793#M7297</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-04T20:03:34Z</dc:date>
    </item>
  </channel>
</rss>

