public static string GetFileName() { FileSaveDialog fsd = new FileSaveDialog("Text Files (*.txt)|*.txt"); fsd.Title = "Database File"; fsd.Show(); ModelPath mp = fsd.GetSelectedModelPath(); string filename = ModelPathUtils.ConvertModelPathToUserVisiblePath(mp); return(filename); }
/// <summary>Displays a SaveAs dialog and gets the chosen options as <cref="FileProperties" />.</summary> /// <param name="dialog">The dialog to display.</param> /// <returns>The chosen file properties, or null in case SaveAs was canceled.</returns> private FileProperties ShowSaveAsDialog(FileSaveDialog dialog) { dialog.Show(); bool toSaveAs = dialog.WaitForResponse(); if (!toSaveAs) { return(null); } string path = dialog.Filename; Encoding encoding = Encodings.GetEncoding(dialog.Encoding.CodePage); SubtitleType subtitleType = dialog.SubtitleType; NewlineType newlineType = dialog.NewlineType; TimingMode timingMode = Base.TimingMode; return(new FileProperties(path, encoding, subtitleType, timingMode, newlineType)); }
static string GetPathToFile() { string path = null; // Create a Revit task dialog to communicate information to the user. TaskDialog customTaskDialog = new TaskDialog("Shared Parameters"); customTaskDialog.MainInstruction = "Please browse for a file to which to export the shared parameters."; customTaskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning; // Add commandLink options customTaskDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Browser"); // Set common buttons customTaskDialog.CommonButtons = TaskDialogCommonButtons.Cancel; // Show the task dialog TaskDialogResult tResult = customTaskDialog.Show(); if (TaskDialogResult.CommandLink1 == tResult) { FileSaveDialog fileSaveDialog = new FileSaveDialog("Text files|*.txt"); //FileOpenDialog openFileDialog = new FileOpenDialog("Text files|*.txt"); ItemSelectionDialogResult sbResult = fileSaveDialog.Show(); if (sbResult == ItemSelectionDialogResult.Canceled) { return(path); } else if (sbResult == ItemSelectionDialogResult.Confirmed) { ModelPath modelPath = fileSaveDialog.GetSelectedModelPath(); path = ModelPathUtils.ConvertModelPathToUserVisiblePath(modelPath); } } else if (TaskDialogResult.Cancel == tResult) { return(path); } return(path); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public virtual Result Execute(ExternalCommandData commandData , ref string message, ElementSet elements) { try { // check user selection var uidoc = commandData.Application.ActiveUIDocument; var doc = uidoc.Document; var collection = uidoc.Selection.GetElementIds(); var hasFabricationPart = false; using (var trans = new Transaction(doc, "Change Spool Name")) { trans.Start(); foreach (var elementId in collection) { var part = doc.GetElement(elementId) as FabricationPart; if (part != null) { hasFabricationPart = true; part.SpoolName = "My Spool"; } } trans.Commit(); } if (hasFabricationPart == false) { message = "Select at least one fabrication part"; return(Result.Failed); } var callingFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var saveAsDlg = new FileSaveDialog("PCF Files (*.pcf)|*.pcf"); saveAsDlg.InitialFileName = callingFolder + "\\pcfExport"; saveAsDlg.Title = "Export To PCF"; var result = saveAsDlg.Show(); if (result == ItemSelectionDialogResult.Canceled) { return(Result.Cancelled); } var fabParts = collection.ToList(); string filename = ModelPathUtils.ConvertModelPathToUserVisiblePath(saveAsDlg.GetSelectedModelPath()); FabricationUtils.ExportToPCF(doc, fabParts, filename); TaskDialog td = new TaskDialog("Export to PCF") { MainIcon = TaskDialogIcon.TaskDialogIconInformation, TitleAutoPrefix = false, MainInstruction = "Export to PCF was successful", MainContent = filename, AllowCancellation = false, CommonButtons = TaskDialogCommonButtons.Ok }; td.Show(); return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public virtual Result Execute(ExternalCommandData commandData , ref string message, ElementSet elements) { try { // check user selection var uidoc = commandData.Application.ActiveUIDocument; var doc = uidoc.Document; ISet <ElementId> parts = null; using (Transaction tr = new Transaction(doc, "Optimise Preselection")) { tr.Start(); ICollection <ElementId> selElems = uidoc.Selection.GetElementIds(); if (selElems.Count > 0) { parts = new HashSet <ElementId>(selElems); } tr.Commit(); } if (parts == null) { MessageBox.Show("Select parts to export."); return(Result.Failed); } var callingFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var saveAsDlg = new FileSaveDialog("CSV Files (*.csv)|*.csv"); saveAsDlg.InitialFileName = callingFolder + "\\geomExport"; saveAsDlg.Title = "Save Part Geometry As"; var result = saveAsDlg.Show(); if (result == ItemSelectionDialogResult.Canceled) { return(Result.Cancelled); } string filename = ModelPathUtils.ConvertModelPathToUserVisiblePath(saveAsDlg.GetSelectedModelPath()); string ext = Path.GetExtension(filename); filename = Path.GetFileNameWithoutExtension(filename); int partcount = 1, exported = 0; foreach (ElementId eid in parts) { // get all rods and kist with rods FabricationPart part = doc.GetElement(eid) as FabricationPart; if (part != null) { Options options = new Options(); options.DetailLevel = ViewDetailLevel.Coarse; IList <Mesh> main = getMeshes(part.get_Geometry(options)); IList <Mesh> ins = getMeshes(part.GetInsulationLiningGeometry()); int mlp = 0; foreach (Mesh mesh in main) { String file = String.Concat(filename, partcount.ToString(), "-main-", (++mlp).ToString(), ext); if (exportMesh(file, mesh)) { exported++; } } int ilp = 0; foreach (Mesh mesh in ins) { String file = String.Concat(filename, partcount.ToString(), "-ins-", (++ilp).ToString(), ext); if (exportMesh(file, mesh)) { exported++; } } } partcount++; } String res = (exported > 0) ? "Export was successful" : "Nothing was exported"; String manywritten = String.Format("{0} Parts were exported", exported); TaskDialog td = new TaskDialog("Export Part Mesh Geometry") { MainIcon = TaskDialogIcon.TaskDialogIconInformation, TitleAutoPrefix = false, MainInstruction = res, MainContent = manywritten, AllowCancellation = false, CommonButtons = TaskDialogCommonButtons.Ok }; td.Show(); return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public virtual Result Execute(ExternalCommandData commandData , ref string message, ElementSet elements) { try { // check user selection var uidoc = commandData.Application.ActiveUIDocument; var doc = uidoc.Document; var elementIds = new HashSet <ElementId>(); uidoc.Selection.GetElementIds().ToList().ForEach(x => elementIds.Add(x)); var hasFabricationParts = false; foreach (var elementId in elementIds) { var part = doc.GetElement(elementId) as FabricationPart; if (part != null) { hasFabricationParts = true; break; } } if (hasFabricationParts == false) { message = "Select at least one fabrication part"; return(Result.Failed); } var callingFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var saveAsDlg = new FileSaveDialog("MAJ Files (*.maj)|*.maj"); saveAsDlg.InitialFileName = callingFolder + "\\majExport"; saveAsDlg.Title = "Export To MAJ"; var result = saveAsDlg.Show(); if (result == ItemSelectionDialogResult.Canceled) { return(Result.Cancelled); } string filename = ModelPathUtils.ConvertModelPathToUserVisiblePath(saveAsDlg.GetSelectedModelPath()); ISet <ElementId> exported = FabricationPart.SaveAsFabricationJob(doc, elementIds, filename, new FabricationSaveJobOptions(true)); if (exported.Count > 0) { TaskDialog td = new TaskDialog("Export to MAJ") { MainIcon = TaskDialogIcon.TaskDialogIconInformation, TitleAutoPrefix = false, MainInstruction = string.Concat("Export to MAJ was successful - ", exported.Count.ToString(), " Parts written"), MainContent = filename, AllowCancellation = false, CommonButtons = TaskDialogCommonButtons.Ok }; td.Show(); } return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }