Using Navisworks API from within a Revit macro?

Using Navisworks API from within a Revit macro?

samernajjar
Contributor Contributor
884 Views
1 Reply
Message 1 of 2

Using Navisworks API from within a Revit macro?

samernajjar
Contributor
Contributor

Hi,

 

I'm trying to write a Revit 2016 macro that exports a nwc file and then convert it into a 2015 nwd using the Navisworks API from within the same macro.

Is this possible?

 

I managed to use the Automation tools to simply save a 2016 nwd as follows

/*
 * Created by SharpDevelop.
 * User: Sam
 * Date: 2/8/2016
 * Time: 7:09 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;

using System.IO;
using Autodesk.Navisworks.Api.Automation;
using Autodesk.Navisworks.Api;

using ReviewConverter;

namespace MyTools
{
	[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
	[Autodesk.Revit.DB.Macros.AddInId("0450DEA7-E6A9-405F-AA51-28D7E8B7967E")]
	public partial class ThisApplication
	{
		private void Module_Startup(object sender, EventArgs e)
		{

		}

		private void Module_Shutdown(object sender, EventArgs e)
		{

		}

		#region Revit Macros generated code
		private void InternalStartup()
		{
			this.Startup += new System.EventHandler(Module_Startup);
			this.Shutdown += new System.EventHandler(Module_Shutdown);
		}
		#endregion
		public void ExportNWC()
		{
			UIDocument uidoc = this.ActiveUIDocument;
			Autodesk.Revit.DB.Document doc = uidoc.Document;
			NavisworksExportOptions opt = new NavisworksExportOptions();
			opt.ConvertElementProperties = true;
			opt.ExportLinks=true;
			opt.ExportRoomAsAttribute=false;
			opt.ExportRoomGeometry=false;
			opt.ExportScope= NavisworksExportScope.View;
			opt.FindMissingMaterials=false;
			opt.ViewId=uidoc.ActiveView.Id;
			
			
			doc.Export("C://nwcExportTest/","test", opt);
			

			FileInfo f = new FileInfo("C://nwcExportTest/test.nwc");
			Autodesk.Navisworks.Api.Automation.NavisworksApplication navApp = new NavisworksApplication();

			navApp.Visible=true;
			navApp.DisableProgress();
			navApp.OpenFile(f.FullName);
			navApp.SaveFile(f.FullName.TrimEnd(Char.Parse("c"))+"d");
			navApp.EnableProgress();
			
			


			
		}
	}
}

But the Automation.Navisworksapplication.saveFile() method does not have an overload for saving back to 2015, I see this available in the Autodesk.Navisworks.Api.Application.ActiveDocument.SaveFile() method, but I'm not sure how to use that from within the Revit macro.

 

Any suggestions?

 

Thanks,

Sam

 

0 Likes
885 Views
1 Reply
Reply (1)
Message 2 of 2

xiaodong_liang
Autodesk Support
Autodesk Support

 

Hi Sam,

 

I am far from being an expert of Revit API, so have no idea whether there is option to save Navisworks file to other release. While if you wanted to use Navisworks API, you have two ways. This assumes your machine has Naivsworks installed. 

 

  1. create an Navisworks plugin that use  Autodesk.Navisworks.Api.Application.ActiveDocument.SaveFile().  And start Navisworks Automation in your Revit program, this automation will execute the plugin to do the job of saving file.  

see <Navisworks SDK>\api\NET\examples\Basic Examples\CSharp\FileManipulation

Note: although automation application (NavisworksApplication) has also savefile method, but this method does not provide the argument of release. so we have to take advantage of a plugin if using automation.

 

  1. Navisworks API also provides a kind of access way: .NET control. The control can be non-view mode: DocumentControl. By this control, you can manipulate document directly like the plugin, including saving file to specific release.

 See <Navisworks SDK>\api\NET\examples\Controls\PublishFile

<Navisworks SDK> is available at: http://www.autodesk.com/developnavisworks

 

0 Likes