Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

ActiveDocument Gets NULL

Anonymous

ActiveDocument Gets NULL

Anonymous
Not applicable

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?

 

 

0 Likes
Reply
852 Views
1 Reply
Reply (1)

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

Autodesk.Navisworks.Api.Application is accessible within a plugin. With Automation API only, what you can do is to open file, append file, merge file etc. For further abilities such as accessing active document, manipulating model, you will need to write a plugin, and invoke the plugin in Automation by NavisworksApplication.ExecuteAddInPlugin .

 

While if you simply wanted to do some batch job, .NET DocumentControl is also an option. There is a sample in SDK\api\NET\examples\Controls\PublishFile, it can publish file like a plugin does, and you can also access  active document by Autodesk.Navisworks.Api.Application.ActiveDocument.

 

Hope this helps.

0 Likes