示例#1
0
        public void SetStringParameter(Element element, int objDefId, BuiltInParameter parameterId, string value, bool allowUnfound)
        {
            Parameter parameter = element?.get_Parameter(parameterId);

            if (parameter == null)
            {
                if (!allowUnfound)
                {
                    Importer.TheLog.LogError(objDefId, "Parameter \"" + parameterId.ToString() + "\" not found, ignoring.", false);
                }
                return;
            }

            if (parameter.StorageType != StorageType.String)
            {
                Importer.TheLog.LogError(objDefId, "Parameter \"" + parameterId.ToString() + "\" not String type, ignoring.", false);
                return;
            }

            if (parameter.IsReadOnly)
            {
                Importer.TheLog.LogError(objDefId, "Parameter \"" + parameterId.ToString() + "\" is read-only, ignoring.", false);
                return;
            }

            parameter.Set(value);
        }
示例#2
0
        public static string ToStringGeneric(this BuiltInParameter value)
        {
            switch (value)
            {
            case BuiltInParameter.GENERIC_THICKNESS:          return("GENERIC_THICKNESS");

            case BuiltInParameter.GENERIC_WIDTH:              return("GENERIC_WIDTH");

            case BuiltInParameter.GENERIC_HEIGHT:             return("GENERIC_HEIGHT");

            case BuiltInParameter.GENERIC_DEPTH:              return("GENERIC_DEPTH");

            case BuiltInParameter.GENERIC_FINISH:             return("GENERIC_FINISH");

            case BuiltInParameter.GENERIC_CONSTRUCTION_TYPE:  return("GENERIC_CONSTRUCTION_TYPE");

            case BuiltInParameter.FIRE_RATING:                return("FIRE_RATING");

            case BuiltInParameter.ALL_MODEL_COST:             return("ALL_MODEL_COST");

            case BuiltInParameter.ALL_MODEL_MARK:             return("ALL_MODEL_MARK");

            case BuiltInParameter.ALL_MODEL_FAMILY_NAME:      return("ALL_MODEL_FAMILY_NAME");

            case BuiltInParameter.ALL_MODEL_TYPE_NAME:        return("ALL_MODEL_TYPE_NAME");

            case BuiltInParameter.ALL_MODEL_TYPE_MARK:        return("ALL_MODEL_TYPE_MARK");
            }

            return(value.ToString());
        }
示例#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
 public static string Get(BuiltInParameter builtInParameter,
                          BuiltInParameter onError = BuiltInParameter.INVALID)
 {
     try { return(LabelUtils.GetLabelFor(builtInParameter)); }
     catch (Exception)
     {
         try { return(LabelUtils.GetLabelFor(onError)); }
         catch (Exception) { return(onError.ToString()); }
     }
 }
        ///
        /// Return a string value for the specified
        /// built-in parameter if it is available on
        /// the given element, else an empty string.
        ///
        string GetParameterValueString(
            Element e,
            BuiltInParameter bip)
        {
            Parameter p = e.get_Parameter(bip);

            string s = string.Empty;

            if (null != p)
            {
                switch (p.StorageType)
                {
                case StorageType.Integer:
                    s = p.AsInteger().ToString();
                    break;

                case StorageType.ElementId:
                    s = p.AsElementId().IntegerValue.ToString();
                    break;

                case StorageType.Double:
                    s = Util.RealString(p.AsDouble());
                    break;

                case StorageType.String:
                    s = string.Format("{0} ({1})",
                                      p.AsValueString(),
                                      Util.RealString(p.AsDouble()));
                    break;

                default: s = "";
                    break;
                }
                s = ", " + bip.ToString() + "=" + s;
            }
            return(s);
        }
        public Result ExecuteObsolete(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            BindingMap bindings = doc.ParameterBindings;
            //Dictionary<string, Guid> guids = new Dictionary<string, Guid>();
            Dictionary <Definition, object> mapDefToGuid = new Dictionary <Definition, object>();

            int n = bindings.Size;

            Debug.Print("{0} shared parementer{1} defined{2}",
                        n, Util.PluralSuffix(n), Util.DotOrColon(n));

            if (0 < n)
            {
                DefinitionBindingMapIterator it
                    = bindings.ForwardIterator();

                while (it.MoveNext())
                {
                    Definition d = it.Key as Definition;
                    Binding    b = it.Current as Binding;
                    if (d is ExternalDefinition)
                    {
                        Guid g = ((ExternalDefinition)d).GUID;
                        Debug.Print(d.Name + ": " + g.ToString());
                        mapDefToGuid.Add(d, g);
                    }
                    else
                    {
                        Debug.Assert(d is InternalDefinition);

                        // this built-in parameter is INVALID:

                        BuiltInParameter bip = ((InternalDefinition)d).BuiltInParameter;
                        Debug.Print(d.Name + ": " + bip.ToString());

                        // if have a definition file and group name, we can still determine the GUID:

                        //Guid g = SharedParamGuid( app, "Identity data", d.Name );

                        mapDefToGuid.Add(d, null);
                    }
                }
            }

            List <Element> walls = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    walls, uidoc, typeof(Wall)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
        ? "Please select some wall elements."
        : "No wall elements found.";
            }
            else
            {
                //List<string> keys = new List<string>( mapDefToGuid.Keys );
                //keys.Sort();

                foreach (Wall wall in walls)
                {
                    Debug.Print(Util.ElementDescription(wall));

                    foreach (Definition d in mapDefToGuid.Keys)
                    {
                        object o = mapDefToGuid[d];

                        Parameter p = (null == o)
            ? wall.get_Parameter(d)
            : wall.get_Parameter((Guid)o);

                        string s = (null == p)
            ? "<null>"
            : p.AsValueString();

                        Debug.Print(d.Name + ": " + s);
                    }
                }
            }
            return(Result.Failed);
        }
        ///
        /// Return a string value for the specified
        /// built-in parameter if it is available on
        /// the given element, else an empty string.
        ///
        string GetParameterValueString(
            Element e,
            BuiltInParameter bip)
        {
            Parameter p = e.get_Parameter( bip );

              string s = string.Empty;

              if( null != p )
              {
            switch( p.StorageType )
            {
              case StorageType.Integer:
            s = p.AsInteger().ToString();
            break;

              case StorageType.ElementId:
            s = p.AsElementId().IntegerValue.ToString();
            break;

              case StorageType.Double:
            s = Util.RealString( p.AsDouble() );
            break;

              case StorageType.String:
            s = string.Format( "{0} ({1})",
              p.AsValueString(),
              Util.RealString( p.AsDouble() ) );
            break;

              default: s = "";
            break;
            }
            s = ", " + bip.ToString() + "=" + s;
              }
              return s;
        }
 /// <summary>
 ///     Performs a "ContainsKey" lookup on the current <see cref="PSCmdlet.MyInvocation"/> BoundParameters against
 ///     the specified built-in parameter, returning <see langword="true"/> if bound.
 /// </summary>
 /// <typeparam name="T">The type of <see cref="PSCmdlet"/> whose bound parameters are checked.</typeparam>
 /// <param name="cmdlet">The <see cref="PSCmdlet"/> that the method is extending.</param>
 /// <param name="parameter">The built-in parameter to check.</param>
 /// <returns></returns>
 public static bool ContainsBuiltinParameter <T>(this T cmdlet, BuiltInParameter parameter) where T : PSCmdlet
 {
     return(cmdlet.MyInvocation.BoundParameters.ContainsKey(parameter.ToString()));
 }