In New York City you can start feeling the Fall weather and the Winter its starting to make its announcement that might be just around the corner, hopefully not another Polar Vortex year. Something that is keeping me warm are the memories from 2 weeks ago where I had the unique experience of taking some aerial pictures in the Island of Puerto Rico. Here is another one of my shots for you guys to enjoy and use as a background if you desire.
Back to Revit API, This week one case that caught my attention and got to work on came from our Autodesk Community Forum.
http://forums.autodesk.com/t5/revit-api/navisworks-export/td-p/5345767
Question: I was writing an add in that would export a NWC File to the location and file based on 2 parameters.
The actual code to export was working fine in 2014, but when built the code for 2015 the NWC export pop up dialog just hangs.
Is anyone aware of any changes the Document.Export() method that would make this not work on the newer version?
Answer:I tried on both 2014 and 2015 rebuilt a small piece of code to do an export to NWC, both of them work, can you provide what you are trying to check it out ? also at the beginning I noticed that my Revit 2015 didn't have the export functionality available but I fixed that and after that the popup dialog does what it's supposed to and everything works fine.
Looking forward to hear from you so I can help.
Response:The standard 2015 Exporter works from my Revit fine.
Here is trimmed code that I tried to get to work with no luck. It just hangs.
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
//create NWExportOptions
NavisworksExportOptions nweOptions =
new NavisworksExportOptions();
nweOptions.ExportScope = NavisworksExportScope.Model;
nweOptions.ViewId = uidoc.ActiveView.Id;
// Modify document within a transaction
using (Transaction tx = new Transaction(doc))
{
tx.Start("Export");
doc.Export(@"D:\Shared", @"test.nwc", nweOptions);
tx.Commit();
}
return Result.Succeeded;
}
}
Answer From Revit Expert:I admit I am not very familiar with the implementation of the latest version of Navisworks Exported, but I am fairly familiar with the code the exported depends on. I'll make two suggestions that may (but may not) help:
- I believe transaction should not be needed. I am basing this on the fact that that underlying export code does not need one. However, it is possible (though strange) that the Navisworks exporter would require transaction for changes it may make to the mode.
- I think the export works for 3D views only, but I suppose the Active one already is a 3D (otherwise I would expect an exception to be thrown).
- Naturally, both ActiveDocument and ActiveView may be null and should be checked, but that is probably not the problem here,
Answer: As my colleague said, a Transaction might not be needed, I tested your code and removing it makes the exporter work, can you please try it and let us know if you are good to go.
Here is how your code looks now.
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
//create NWExportOptions
NavisworksExportOptions nweOptions =
new NavisworksExportOptions();
nweOptions.ExportScope = NavisworksExportScope.Model;
nweOptions.ViewId = uidoc.ActiveView.Id;
doc.Export(@"D:\Shared", @"test.nwc", nweOptions);
return Result.Succeeded;
}
Response: That worked.So something must have changed in the transaction class? The Export worked in 2014 inside of the transaction.Either way, doesn’t matter to me.Thank you very much!
Special thanks to Arnošt Löbel for the insight in this case.
Thanks for reading and until next time.