PR: Not able to export with linked files from custom Revit addin
josbornes opened this issue · comments
Problem Description
... I can export with linked files using Revit Export Interface, but when trying to export from my custom addin it doesnt include linked elements.
When debugging looks like option is correctly included in IFCExportConfiguration but just ignored. All other options are correctly applied.
IFCExportOptions ifcOptions = new IFCExportOptions();
BIM.IFC.Export.UI.IFCExportConfiguration myIFCExportConfiguration = BIM.IFC.Export.UI.IFCExportConfiguration.CreateDefaultConfiguration();
myIFCExportConfiguration.ExportLinkedFiles = Revit.IFC.Export.Utility.LinkedFileExportAs.ExportSameProject;
myIFCExportConfiguration.UpdateOptions(ifcOptions, view.Id);
doc.Export(RutaExportIFC, NombreParaIFC, ifcOptions);
Revit Version
2024.0.x
IFC for Revit Addon Version
24.x.x
Windows Version
11 22H2
Here is my full code (simplified). Maybe I'm doing something wrong... Any help?
public void ExportaIFCVista()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
View view = doc.ActiveView;
using (Transaction t = new Transaction(doc, "Export IFC"))
{
t.Start();
IFCExportOptions ifcOptions = new IFCExportOptions();
IFCExportConfiguration config = IFCExportConfiguration.CreateDefaultConfiguration();
IFCExportConfiguration myIFCExportConfiguration = IFCExportConfiguration.CreateDefaultConfiguration();
myIFCExportConfiguration.IFCVersion = IFCVersion.IFC2x3CV2;
myIFCExportConfiguration.ExportLinkedFiles = LinkedFileExportAs.ExportSameProject;
myIFCExportConfiguration.VisibleElementsOfCurrentView = true;
myIFCExportConfiguration.UpdateOptions(ifcOptions, view.Id);
doc.Export(@"c:\tmp\", "000-TestingIF", ifcOptions);
t.Commit();
}
} //ExportaIFCVista
I would recommend that you export the "standard" options to a JSON and copy them all into your project to try to get it to work, and then you can remove stuff if it feels extraneous.
I did, and the Json just set the property to it's enum value of LinkedFileExportAs.ExportSameProject
"Export2DElements": false,
"ExportLinkedFiles": 2,
"VisibleElementsOfCurrentView": true,
Moustafa at Revit API forum point me to the solution to this problem. You must add two additional IFCExportOptions options in order to make it happen. Quick working sample code:
public void ExportaIFCVista()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
View view = doc.ActiveView;
FilteredElementCollector collector = new FilteredElementCollector(doc);
ElementFilter elementFilter = new ElementClassFilter(typeof(RevitLinkInstance));
List<RevitLinkInstance> rvtLinkInstances = collector.WherePasses(elementFilter).Cast<RevitLinkInstance>().ToList();
string linkGuidOptionString = string.Empty;
foreach (RevitLinkInstance linkInstance in rvtLinkInstances)
{
string sGUID = GUIDUtil.GetSimpleElementIFCGUID(linkInstance);
linkGuidOptionString += linkInstance.Id.ToString() + "," + sGUID + ";";
}
using (Transaction t = new Transaction(doc, "Export IFC"))
{
t.Start();
IFCExportOptions ifcOptions = new IFCExportOptions();
ifcOptions.AddOption("ExportingLinks", LinkedFileExportAs.ExportSameProject.ToString());
ifcOptions.AddOption("FederatedLinkInfo", linkGuidOptionString);
IFCExportConfiguration config = IFCExportConfiguration.CreateDefaultConfiguration();
IFCExportConfiguration myIFCExportConfiguration = IFCExportConfiguration.CreateDefaultConfiguration();
myIFCExportConfiguration.IFCVersion = IFCVersion.IFC2x3CV2;
//myIFCExportConfiguration.ExportLinkedFiles = LinkedFileExportAs.ExportSameProject;
myIFCExportConfiguration.VisibleElementsOfCurrentView = true;
myIFCExportConfiguration.UpdateOptions(ifcOptions, view.Id);
doc.Export(@"c:\tmp\", "000-TestingIF", ifcOptions);
t.Commit();
}
} //ExportaIFCVista
I already placed a pull request for this matter. I hope it can be merged soon.
Thank you very much Moustafa!! For the explanation, the workaround and the fix!