public void ExportRFA(Document doc, string filePath) { LogTrace("Exporting RFA file."); BIMComponent bimComponent = getBIMComponent(doc); if (bimComponent == null) { LogTrace("Could not export RFA file."); return; } NameValueMap nvm = inventorApplication.TransientObjects.CreateNameValueMap(); string currentDir = System.IO.Directory.GetCurrentDirectory(); var reportFileName = System.IO.Path.Combine(currentDir, "Report.html"); nvm.Add("ReportFileName", reportFileName); bimComponent.ExportBuildingComponentWithOptions(filePath, nvm); LogTrace("Exported RFA file."); }
BIMComponent getBIMComponent(Document doc) { BIMComponent bimComponent = null; var docType = doc.DocumentType; if (docType == DocumentTypeEnum.kAssemblyDocumentObject) { AssemblyDocument _doc = doc as AssemblyDocument; bimComponent = _doc.ComponentDefinition.BIMComponent; } else if (docType == DocumentTypeEnum.kPartDocumentObject) { PartDocument _doc = doc as PartDocument; bimComponent = _doc.ComponentDefinition.BIMComponent; } else { Trace.TraceInformation("NOT supported document type."); } return(bimComponent); }
public void ExportRFA(Document doc) { LogTrace("Export RFA file."); BIMComponent bimComponent = getBIMComponent(doc); if (bimComponent == null) { return; } var startDir = System.IO.Directory.GetCurrentDirectory(); // output file name var fileName = System.IO.Path.Combine(startDir, "Output.rfa"); NameValueMap nvm = _inventorApplication.TransientObjects.CreateNameValueMap(); LogTrace($"Exporting to {fileName}"); var reportFileName = System.IO.Path.Combine(startDir, "Report.html"); LogTrace($"Reporting to {reportFileName}"); nvm.Add("ReportFileName", reportFileName); DateTime t = DateTime.Now; DateTime t2; using (new HeartBeat()) { try { bimComponent.ExportBuildingComponentWithOptions(fileName, nvm); LogTrace("Export finished"); t2 = DateTime.Now; } catch (Exception e) { t2 = DateTime.Now; LogTrace($"ERROR: Exporting FAILED : {e.Message}"); } } if (System.IO.File.Exists(fileName)) { LogTrace($"EXPORTED to : {fileName}"); LogTrace($"EXPORT took : {(t2 - t).TotalSeconds} seconds"); } else { LogTrace($"ERROR: EXPORT does not exist !!!!!!!"); } if (System.IO.File.Exists(reportFileName)) { LogTrace($"REPORT generated."); } else { LogTrace($"ERROR: REPORT does not exist !!!!!!!"); } }