/// <summary> /// The implementation for IExternalCommand.Execute() /// </summary> /// <param name="commandData">The Revit command data.</param> /// <param name="message">The error message (ignored).</param> /// <param name="elements">The elements to display in the failure dialog (ignored).</param> /// <returns>Result.Succeeded</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document doc = commandData.Application.ActiveUIDocument.Document; Transaction trans = new Transaction(doc, "Modify ExportPDFSettings"); trans.Start(); try { ExportPDFSettings settings = ExportPDFSettings.FindByName(doc, "sample"); if (settings == null) { message = "Cannot find sample settings"; trans.RollBack(); return(Result.Failed); } PDFExportOptions options = settings.GetOptions(); options.PaperFormat = ExportPaperFormat.ISO_A4; // Change paper format options.HideCropBoundaries = false; // Change hide crop boundaries options.Combine = false; // Change name into the pattern of naming rule settings.SetOptions(options); // Activate changes } catch (Exception ex) { message = ex.ToString(); trans.RollBack(); return(Result.Failed); } trans.Commit(); return(Result.Succeeded); }
/// <summary> /// Export PDF format /// </summary> /// <returns></returns> public override bool Export() { base.Export(); bool exported = false; // Parameter: The list of view/sheet id to export IList <ElementId> views = new List <ElementId>(); if (m_currentViewOnly) { views.Add(m_activeDoc.ActiveView.Id); } else { ViewSet viewSet = m_selectViewsData.SelectedViews; foreach (View v in viewSet) { views.Add(v.Id); } } // Parameter: The exporting options, including paper size, orientation, file name or naming rule and etc. PDFExportOptions options = new PDFExportOptions(); options.FileName = m_exportFileName; options.Combine = m_combine; // If not combined, PDFs will be exported with default naming rule "Type-ViewName" exported = m_activeDoc.Export(m_exportFolder, views, options); return(exported); }
/// <summary> /// The implementation for IExternalCommand.Execute() /// </summary> /// <param name="commandData">The Revit command data.</param> /// <param name="message">The error message (ignored).</param> /// <param name="elements">The elements to display in the failure dialog (ignored).</param> /// <returns>Result.Succeeded</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document doc = commandData.Application.ActiveUIDocument.Document; Transaction trans = new Transaction(doc, "Modify a naming rule"); trans.Start(); try { ExportPDFSettings settings = ExportPDFSettings.FindByName(doc, "sample"); if (settings == null) { message = "Cannot find sample settings"; trans.RollBack(); return(Result.Failed); } PDFExportOptions options = settings.GetOptions(); // Naming rule remains the same in silence if exporting is combined if (options.Combine) { message = "Exporting is combined. To change naming rule you need to set exporting not combined."; trans.RollBack(); return(Result.Failed); } // Get naming rule IList <TableCellCombinedParameterData> namingRule = options.GetNamingRule(); // Find SHEET_APPROVED_BY rule BuiltInParameter param = BuiltInParameter.SHEET_APPROVED_BY; ElementId categoryId = Category.GetCategory(doc, BuiltInCategory.OST_Sheets).Id; ElementId paramId = new ElementId(param); TableCellCombinedParameterData rule = namingRule.SingleOrDefault(r => (r.CategoryId == categoryId && r.ParamId == paramId)); if (rule == null) { message = "No such rule in naming rule"; trans.RollBack(); return(Result.Failed); } // Mofidy rule rule.SampleValue = "Modify my sample value"; namingRule = namingRule.OrderBy(data => data.SampleValue).ToList(); // The order of rules is defined by the naming rule list options.SetNamingRule(namingRule); // Note that naming rule won't be changed if exporting is combined, see the comments of PDFExportOptions.SetOptions settings.SetOptions(options); } catch (Exception ex) { message = ex.ToString(); trans.RollBack(); return(Result.Failed); } trans.Commit(); return(Result.Succeeded); }
/// <summary> /// The implementation for IExternalCommand.Execute() /// </summary> /// <param name="commandData">The Revit command data.</param> /// <param name="message">The error message (ignored).</param> /// <param name="elements">The elements to display in the failure dialog (ignored).</param> /// <returns>Result.Succeeded</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document doc = commandData.Application.ActiveUIDocument.Document; Transaction trans = new Transaction(doc, "Add a naming rule"); trans.Start(); try { ExportPDFSettings settings = ExportPDFSettings.FindByName(doc, "sample"); if (settings == null) { message = "Cannot find sample settings"; trans.RollBack(); return(Result.Failed); } PDFExportOptions options = settings.GetOptions(); // Naming rule remains the same in silence if exporting is combined if (options.Combine) { message = "Exporting is combined. To change naming rule you need to set exporting not combined."; trans.RollBack(); return(Result.Failed); } // Get naming rule IList <TableCellCombinedParameterData> namingRule = options.GetNamingRule(); // Add naming parameter Sheets-Approved-By to naming rule BuiltInParameter param = BuiltInParameter.SHEET_APPROVED_BY; ElementId categoryId = Category.GetCategory(doc, BuiltInCategory.OST_Sheets).Id; ElementId paramId = new ElementId(param); TableCellCombinedParameterData itemSheetApprovedBy = TableCellCombinedParameterData.Create(); itemSheetApprovedBy.CategoryId = categoryId; itemSheetApprovedBy.ParamId = paramId; itemSheetApprovedBy.Prefix = "-"; // You can also add prefix/suffix itemSheetApprovedBy.Separator = "-"; itemSheetApprovedBy.SampleValue = param.ToString(); namingRule.Add(itemSheetApprovedBy); // Don't forget to set naming rule for options options.SetNamingRule(namingRule); // And save the options for settings // Note that naming rule won't be changed if exporting is combined, see the comments of PDFExportOptions.SetOptions settings.SetOptions(options); } catch (Exception ex) { message = ex.ToString(); trans.RollBack(); return(Result.Failed); } trans.Commit(); return(Result.Succeeded); }
public static string GetExportNameFromNamingRule(PDFExportOptions opts, ExportSheet vs) { var segs = opts.GetNamingRule(); string filenameTest = string.Empty; foreach (var seg in segs) { filenameTest += seg.Prefix; var pid = seg.ParamId; var cid = seg.CategoryId; var cidString = cid.ToString(); if (cid.IntegerValue == (int)BuiltInCategory.OST_ProjectInformation) { var param = vs.Sheet.Document.ProjectInformation.Parameters.Cast <Parameter>().Where(p => p.Id == pid); if (param.Count() > 0) { var paramValue = param.First().AsValueString(); filenameTest += paramValue; } } else { var param = vs.Sheet.Parameters.Cast <Parameter>().Where(p => p.Id == pid); if (param.Count() > 0) { // if (param.First().Definition.Name == "Current Revision" && vs.ForceDate) // { // filenameTest += "Current Revision"; // } // else // { var paramValue = param.First().AsValueString(); if (paramValue.Length < 1) { filenameTest += "Current Revision"; } else { filenameTest += paramValue; } //// } } } filenameTest += seg.Suffix; filenameTest += seg.Separator; } return(filenameTest); }
public ExportPdfViewModel(ExportArguments pdfArguments) { IsSaveEnabled = true; IsValidWidth = true; IsValidHeight = true; _pdfPapers = PDFExportOptions.GetPdfPapers(pdfArguments.PixelWidth, pdfArguments.PixelHeight, pdfArguments.Resolution).ToList(); SelectedPDFPaperType = _pdfPapers[0]; SelectedPDFPaperType.PaperHeight = Validate(SelectedPDFPaperType.PaperHeight); SelectedPDFPaperType.PaperWidth = Validate(SelectedPDFPaperType.PaperWidth); _paperOrientations = PDFExportOptions.GetPaperOrientations().ToList(); SelectedOrientation = _paperOrientations[0]; _pdfDeviceOptions = PDFExportOptions.GetPdfDeviceOptions().ToList(); SelectedDevice = _pdfDeviceOptions[0]; }
/// <summary> /// The implementation for IExternalCommand.Execute() /// </summary> /// <param name="commandData">The Revit command data.</param> /// <param name="message">The error message (ignored).</param> /// <param name="elements">The elements to display in the failure dialog (ignored).</param> /// <returns>Result.Succeeded</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document doc = commandData.Application.ActiveUIDocument.Document; Transaction trans = new Transaction(doc, "Create ExportPDFSettings"); trans.Start(); try { PDFExportOptions options = new PDFExportOptions(); string name = "sample"; ExportPDFSettings settings = ExportPDFSettings.Create(doc, name, options); } catch (Exception ex) { message = ex.ToString(); trans.RollBack(); return(Result.Failed); } trans.Commit(); return(Result.Succeeded); }