public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; WorksetConfiguration openConfig = new WorksetConfiguration(WorksetConfigurationOption.CloseAllWorksets); OpenOptions openOptions = new OpenOptions(); openOptions.SetOpenWorksetsConfiguration(openConfig); openOptions.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets; SaveAsOptions wsaveAs = new SaveAsOptions(); WorksharingSaveAsOptions saveConfig = new WorksharingSaveAsOptions(); saveConfig.SaveAsCentral = true; wsaveAs.SetWorksharingOptions(saveConfig); wsaveAs.OverwriteExistingFile = true; SaveAsOptions saveAs = new SaveAsOptions(); saveAs.OverwriteExistingFile = true; destinationpath = ""; documents.Clear(); string date = DateTime.Now.ToString("dd/MM/yyyy"); int completed = 0; int failed = 0; var exportdialog = new RevitBatchExporter.Dialogs.ExportDialog(); var dialog = exportdialog.ShowDialog(); if (dialog != DialogResult.OK) { return(Result.Cancelled); } bool purge = exportdialog.PurgeCheckBox.Checked; bool removeCADlinks = exportdialog.RemoveCADLinksCheckBox.Checked; bool removeCADImports = exportdialog.RemoveCADImportsCheckBox.Checked; bool removeRVTlinks = exportdialog.RemoveRVTLinksCheckBox.Checked; bool removeSchedules = exportdialog.SchedulesCheckBox.Checked; bool ungroup = exportdialog.UngroupCheckBox.Checked; bool removesheets = exportdialog.SheetsCheckBox.Checked; bool removeviewsON = exportdialog.ViewsONSheetsCheckBox.Checked; bool removeviewsNOT = exportdialog.ViewsNotSheetsCheckBox.Checked; bool exportnwc = exportdialog.NWCCheckBox.Checked; bool exportifc = exportdialog.IFCCheckBox.Checked; bool removeallsheetsviews = false; if (removesheets && removeviewsON && removeviewsNOT) { removeallsheetsviews = true; removesheets = false; removeviewsON = false; removeviewsNOT = false; } string reason = exportdialog.IssueReasonTextBox.Text.TrimEnd().TrimStart(); string customdate = exportdialog.DateTextBox.Text.TrimEnd().TrimStart(); string nameprefix = exportdialog.PrefixTextBox.Text.TrimEnd().TrimStart(); string namesuffix = exportdialog.SuffixTextBox.Text.TrimEnd().TrimStart(); string debugmessage = ""; bool samepath = false; List <string[]> results = new List <string[]>(); foreach (string path in documents) { string destdoc = nameprefix + Path.GetFileName(path.Replace(".rvt", "")) + namesuffix + ".rvt"; if (File.Exists(destinationpath + destdoc)) { samepath = true; break; } string pathOnly = Path.GetDirectoryName(path) + "\\"; if (pathOnly == destinationpath) { samepath = true; break; } } if (samepath) { TaskDialog td = new TaskDialog("XPORT"); td.MainInstruction = "Some documents already exist in the destination path."; td.MainContent = "The files will be overritten, do you wish to continue?"; td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Continue"); td.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "Cancel"); switch (td.Show()) { case TaskDialogResult.CommandLink1: break; case TaskDialogResult.CommandLink2: return(Result.Cancelled); default: return(Result.Cancelled); } } uiapp.DialogBoxShowing += new EventHandler <DialogBoxShowingEventArgs>(OnDialogBoxShowing); uiapp.Application.FailuresProcessing += FailureProcessor; DateTime start = DateTime.Now; foreach (string path in documents) { string[] result = new string[5]; if (!File.Exists(path)) { result[0] = Path.GetFileName(path.Replace(".rvt", "")); result[1] = "false"; result[2] = "false"; result[3] = "File Not Found"; result[4] = ""; results.Add(result); failed++; continue; } try { DateTime s1 = DateTime.Now; Document doc = uiapp.Application.OpenDocumentFile(ModelPathUtils.ConvertUserVisiblePathToModelPath(path), openOptions); Transaction t1 = new Transaction(doc, "XP"); t1.Start(); if (customdate != "") { date = customdate; } try { doc.ProjectInformation.LookupParameter("Model Issue Date").Set(date); } catch { }; try { doc.ProjectInformation.IssueDate = date; } catch { }; if (reason != "") { try { doc.ProjectInformation.LookupParameter("Model Issue Reason").Set(reason); } catch { } } if (removeCADlinks) { DeleteCADLinks(doc); } if (removeCADImports) { DeleteCADImports(doc); } if (removeRVTlinks) { DeleteRVTLinks(doc); } if (removeviewsNOT) { DeleteViewsNotOnSheets(doc); } if (removeviewsON) { DeleteViewsONSheets(doc); } if (removesheets) { DeleteSheets(doc); } if (removeallsheetsviews) { DeleteAllViewsSheets(doc); } if (removeSchedules) { DeleteSchedules(doc); } if (ungroup) { UngroupGroups(doc); } if (purge) { PurgeDocument(doc); } t1.Commit(); string docname = doc.Title; docname = docname.Replace("_detached", ""); if (docname.EndsWith(".rvt")) { docname = docname.Replace(".rvt", ""); } if (nameprefix != "") { docname = nameprefix + docname; } if (namesuffix != "") { docname = docname + namesuffix; } bool nwcexported = false; bool ifcexported = false; if (exportnwc) { nwcexported = ExportNWC(doc, destinationpath, docname); } if (exportifc) { ifcexported = ExportIFC(doc, destinationpath, docname); } try { if (doc.IsWorkshared) { doc.SaveAs(destinationpath + docname + ".rvt", wsaveAs); doc.Close(false); } else { doc.SaveAs(destinationpath + docname + ".rvt", saveAs); doc.Close(false); } } catch { doc.Close(false); } try { Directory.Delete(destinationpath + docname + "_backup", true); } catch { } try { Directory.Delete(destinationpath + "Revit_temp", true); } catch { } doc.Dispose(); completed++; DateTime e1 = DateTime.Now; int h = (e1 - s1).Hours; int m = (e1 - s1).Minutes; int s = (e1 - s1).Seconds; result[0] = Path.GetFileName(path.Replace(".rvt", "")); result[1] = nwcexported.ToString(); result[2] = ifcexported.ToString(); result[3] = "Completed"; result[4] = h.ToString() + ":" + m.ToString() + ":" + s.ToString(); results.Add(result); } catch (Exception e) { debugmessage = "\n" + "\n" + e.Message; result[0] = Path.GetFileName(path.Replace(".rvt", "")); result[1] = "false"; result[2] = "false"; result[3] = "Failed"; result[4] = ""; results.Add(result); failed++; } } uiapp.DialogBoxShowing -= OnDialogBoxShowing; uiapp.Application.FailuresProcessing -= FailureProcessor; DateTime end = DateTime.Now; int hours = (end - start).Hours; int minutes = (end - start).Minutes; int seconds = (end - start).Seconds; //TaskDialog.Show("Results", "Completed: " + completed.ToString() + "\nFailed: " + failed.ToString() + "\nTotal Time: " + hours.ToString() + " h " + minutes.ToString() + " m " + seconds.ToString() + " s" + debugmessage); TaskDialog rd = new TaskDialog("XPORT"); rd.MainInstruction = "Results"; rd.MainContent = "Exported to: " + destinationpath + "\n" + "Completed: " + completed.ToString() + "\nFailed: " + failed.ToString() + "\nTotal Time: " + hours.ToString() + " h " + minutes.ToString() + " m " + seconds.ToString() + " s"; rd.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Close"); rd.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "Show Details"); documents.Clear(); destinationpath = ""; switch (rd.Show()) { case TaskDialogResult.CommandLink1: return(Result.Succeeded); case TaskDialogResult.CommandLink2: var resultsdialog = new RevitBatchExporter.Dialogs.ResultsDialog(); foreach (string[] r in results) { var item = new ListViewItem(r); resultsdialog.ResultsView.Items.Add(item); } var rdialog = resultsdialog.ShowDialog(); return(Result.Succeeded); default: return(Result.Succeeded); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; destinationpath = ""; documents.Clear(); Dictionary <string, ElementId> views = GetViews(doc); string date = DateTime.Now.ToString("dd/MM/yyyy"); var exportdialog = new RevitBatchExporter.Dialogs.ExportDialog(); exportdialog.FilenameTextbox.Text = doc.Title; exportdialog.comboBox1.DataSource = views.Keys.ToList(); exportdialog.DWGCombobox.DataSource = optionname(doc); exportdialog.IFCCombobox.DataSource = IFCExportpredefined(doc); exportdialog.DWGCombobox.Enabled = false; exportdialog.IFCCombobox.Enabled = false; var dialog = exportdialog.ShowDialog(); if (dialog != DialogResult.OK) { return(Result.Cancelled); } string filename = exportdialog.FilenameTextbox.Text; ElementId selectedview = views[exportdialog.comboBox1.SelectedItem.ToString()]; string dwgoption = exportdialog.DWGCombobox.SelectedItem.ToString(); string settings = exportdialog.IFCCombobox.SelectedItem.ToString(); int count = 0; if (destinationpath.Trim() != "" && Directory.Exists(destinationpath)) { if (exportdialog.NWCCheckBox.Checked) { if (ExportNWC(doc, destinationpath, filename, selectedview, exportdialog.SharedRadio.Checked)) { count++; } } if (exportdialog.IFCCheckBox.Checked) { if (ExportIFC(doc, destinationpath, filename, selectedview, settings)) { count++; } } if (exportdialog.DWGCheckbox.Checked) { if (ExportDWG(doc, destinationpath, filename, selectedview, dwgoption)) { count++; } } TaskDialog.Show("Success", "exported " + count + " documents"); //clear the folder if (exportdialog.DeleteLogFilesButton.Checked) { DeleteLog(destinationpath); } //REPORT-------------- - //try //{ // string[] log = new string[6]; // List<string> rep = new List<string>(); // string locationpath = "\\\\zaha-hadid.com\\Data\\Projects\\2100_BIMManagement\\User\\MS\\users"; // DirectoryInfo exportFolder = new DirectoryInfo(destinationpath); // string filepath = destinationpath; // string path = string.Format(locationpath + "\\report.txt"); // string[] vs = new string[1]; // string a = ""; // foreach (FileInfo f in exportFolder.GetFiles()) // { // log[0] = (Environment.UserName.ToString()); // log[1] = (DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm"));//date;; // log[2] = Path.GetFileNameWithoutExtension(f.Name); // log[3] = f.Extension; // log[4] = (f.Length * 0.001).ToString(); // log[5] = Environment.NewLine; // a = log[0] + "," + log[1] + "," + log[2] + "," + log[3] + "," + log[4] + log[5]; // File.AppendAllText(path, a); // } //} //catch //{ //} return(Result.Succeeded); } else { return(Result.Cancelled); } }