Fernando Vazquez
Fernando Vazquez

Reputation: 23

How get model information using IronPython from Navisworks session? (No NavisPythonShell)

How I can get information from a Navisworks .NWD file using its NET API by IronPython (mainly name of each item in orden to confirm that all parts are already modeled).

I have not experience with C# but with python, so I want to use IronPython.

I know about NavisPythonShell but After some attempts, it didn't work for me. Navisworks crashed as soon as plugin run.

Anyway I got some advances using IronPython. Navisworks opens, load a file and close, but using Autodesk.Navisworks.Api.Application.ActiveDocument, It only got NoneType "object".

import sys, clr
navis_path = r'C:\Program Files\Autodesk\Navisworks Manage 2017'
nw_model = r'C:\Users\myName\Client\navis\nodel.nwd' 
sys.path.append(navis_path)

clr.AddReference('Autodesk.Navisworks.Api')
clr.AddReference('Autodesk.Navisworks.Automation')
clr.AddReference('Autodesk.Navisworks.Controls')

from Autodesk.Navisworks.Api import *
from Autodesk.Navisworks.Api.Automation import *
from Autodesk.Navisworks.Api.Controls import *

nw = NavisworksApplication()
nw.Visible = True
nw.OpenFile(nw_model)

doc = Application.ActiveDocument

Type of doc equal to "NoneType"

Upvotes: 1

Views: 2040

Answers (1)

Dmitry Dronov
Dmitry Dronov

Reputation: 400

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.

Upvotes: 1

Related Questions