Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ActiveDocument Gets NULL

1 REPLY 1
Reply
Message 1 of 2
Anonymous
829 Views, 1 Reply

ActiveDocument Gets NULL

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?

 

 

1 REPLY 1
Message 2 of 2
xiaodong_liang
in reply to: Anonymous

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report