Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document doc = commandData.Application.ActiveUIDocument.Document; //Application.OpenIFCDocument Method (String, IFCImportOptions) //public Document OpenIFCDocument(string fileName,IFCImportOptions importOptions) List <string> ifcList = new List <string>(); IFCtoRVTForm IFCtoRVTForm = new IFCtoRVTForm(); IFCtoRVTForm.ShowDialog(); if (IFCtoRVTForm.ifcPaths != null) { ifcList = IFCtoRVTForm.ifcPaths; } IFCImportOptions option = new IFCImportOptions(); for (int i = 0; i < ifcList.Count(); i++) { Transaction openIFC = new Transaction(doc, "openIFC"); openIFC.Start(); Document ifcDoc = commandData.Application.Application.OpenIFCDocument(ifcList[i], option); openIFC.Commit(); ifcDoc.SaveAs(ifcList[i] + ".rvt"); ifcDoc.Close(); } return(Result.Succeeded); }
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { string tmpPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\ifcComponentImporter"; string filePath = ""; string rvtPath = ""; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "IFC Files|*.ifc"; openFileDialog1.Title = "Select a ifc File"; if(!Directory.Exists(tmpPath)) { Directory.CreateDirectory(tmpPath); } if (openFileDialog1.ShowDialog() == DialogResult.OK) { filePath = openFileDialog1.FileName; var ifcops = new IFCImportOptions(); Document document = commandData.Application.Application.OpenIFCDocument(filePath, ifcops); DocumentPreviewSettings settings = document.GetDocumentPreviewSettings(); FilteredElementCollector collector = new FilteredElementCollector(document); collector.OfClass(typeof(ViewPlan)); FilteredElementCollector uicollector = new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document); uicollector.OfClass(typeof(ViewPlan)); Func<ViewPlan, bool> isValidForPreview = v => settings.IsViewIdValidForPreview(v.Id); ViewPlan viewForPreview = collector.OfType<ViewPlan>().First<ViewPlan>(isValidForPreview); using (Transaction tx = new Transaction(document)) { tx.Start("tr"); viewForPreview.SetWorksetVisibility(viewForPreview.WorksetId, WorksetVisibility.Visible); tx.Commit(); } SaveAsOptions options = new SaveAsOptions(); options.PreviewViewId = viewForPreview.Id; rvtPath = tmpPath + @"\" + Path.ChangeExtension(Path.GetFileName(filePath), "rvt"); if (File.Exists(rvtPath)) { File.Delete(rvtPath); } document.SaveAs(rvtPath, options); commandData.Application.PostCommand(RevitCommandId.LookupCommandId("ID_LOAD_GROUP")); Process process = new Process(); process.StartInfo.FileName = "PostAction.exe"; process.StartInfo.Arguments = "\""+rvtPath+"\""; process.Start(); } return 0; } catch (Exception ex) { message = ex.Message; return Autodesk.Revit.UI.Result.Failed; } }