ActiveDocument Gets NULL

Not applicable
05-09-2017
06:51 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I tried again "GET AND SET VIEWPOINT PROPERTIES" using .NET API, NOT COM API this time.
Problem is that I could open Navisworks Application and open some NWD files using new NavisworksApplication() function, but couldn't even get the viewpoint properties whereas COM API could.
It seems that's because of Application.ActiveDocument : Null.
the Code looks like as below.
using Autodesk.Navisworks.Api; using Autodesk.Navisworks.Api.Automation; using Autodesk.Navisworks.Api.Controls; namespace WindowsFormsApplication1 { public partial class Form1 : Form { NavisworksApplication NWApp = null; public Document NWDoc; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "NWD files|*.nwd"; dlg.Title = "Open Navisworks Document"; DialogResult result = dlg.ShowDialog(); if (result == DialogResult.OK) { try { NWApp = new NavisworksApplication(); NWApp.DisableProgress(); NWApp.Visible = true; string filename = dlg.FileName; NWApp.OpenFile(filename); NWDoc = Autodesk.Navisworks.Api.Application.ActiveDocument; } catch (Autodesk.Navisworks.Api.Automation.AutomationException ex1) { System.Windows.Forms.MessageBox.Show("Error: " + ex1.Message); } catch (Autodesk.Navisworks.Api.Automation.AutomationDocumentFileException ex2) { System.Windows.Forms.MessageBox.Show("Error: " + ex2.Message); } } } private void button2_Click(object sender, EventArgs e) { Viewpoint Vpoint = NWDoc.CurrentViewpoint; Viewpoint VpointCopy = Vpoint.CreateCopy(); label1.Text = VpointCopy.Position.X.ToString(); label2.Text = VpointCopy.Position.Y.ToString(); label3.Text = VpointCopy.Position.Z.ToString(); } } }
How can I get ActiveDocument to work properly?