Пример #1
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, "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);
        }
Пример #2
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, "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);
        }
Пример #3
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, "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);
        }
Пример #4
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);
        }