Revit 2022 API - Exporting An NWC File

Revit 2022 API - Exporting An NWC File

RBroad
Explorer Explorer
784 Views
4 Replies
Message 1 of 5

Revit 2022 API - Exporting An NWC File

RBroad
Explorer
Explorer

I am trying to make an app to export an NWC file from Revit using the api, based on certain file names & then publish this into a document management system.

 

I use the following code to export the nwc, but no model is exported.  Does anyone have any example of this or has experienced this issue and knows how to solve it?

UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;

Transaction trans = new Transaction(doc,"Export Models");
trans.Start();

ElementId ExportViewId = doc.ActiveView.Id;

bool isNWCExporterInstalled = OptionalFunctionalityUtils.IsNavisworksExporterAvailable();
if (isNWCExporterInstalled == true)
{

string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
NavisworksExportOptions nwcOptions = new NavisworksExportOptions();

nwcOptions.ViewId = ExportViewId; // Sets the view id to be exported.
nwcOptions.ExportScope = NavisworksExportScope.View;

doc.Export(filePath, "MyModel.nwc", nwcOptions);
}

 

trans.Commit();

return Result.Succeeded;

0 Likes
785 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

Have you checked and ensured that IsNavisworksExporterAvailable returns true? If not, nothing will happen.

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 5

RBroad
Explorer
Explorer

Jeremy,

Thank you for your fast response, I did check this and it was returning true.

I did some further investigation and moving it outside the transaction start / commit block seemed to solve the issue.

 

Hopefully this is helpful if anyone else runs into the same issue.

 

 

Thanks,

 

Rob

0 Likes
Message 4 of 5

RBroad
Explorer
Explorer

Jeremy,

Thank you for your fast response, I did check this and it was returning true.

I did some further investigation and moving it outside the transaction start / commit block seemed to solve the issue.

 

Hopefully this is helpful if anyone else runs into the same issue.

 

Thanks,

 

Rob

0 Likes
Message 5 of 5

jeremy_tammik
Alumni
Alumni

Thank you, Rob,

   

for the information and appreciation. Yes, that is useful to know. Some operations in Revit that would appear to be read-only still require a transaction, and others do not. In this case, apparently, an open transaction may even cause a failure. That ought to be explicitly documented. 

  

Cheers

  

Jeremy

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes