Пример #1
0
        public ParameterParam(DB.Parameter p) : this()
        {
            ParameterName    = p.Definition.Name;
            ParameterType    = p.Definition.ParameterType;
            ParameterGroup   = p.Definition.ParameterGroup;
            ParameterBinding = p.Element is DB.ElementType ? RevitAPI.ParameterBinding.Type : RevitAPI.ParameterBinding.Instance;

            if (p.IsShared)
            {
                ParameterSharedGUID = p.GUID;
            }
            else if (p.Id.TryGetBuiltInParameter(out var parameterBuiltInId))
            {
                ParameterBuiltInId = parameterBuiltInId;
            }

            try { Name = $"{DB.LabelUtils.GetLabelFor(ParameterGroup)} : {ParameterName}"; }
            catch (Autodesk.Revit.Exceptions.InvalidOperationException) { Name = ParameterName; }

            NickName        = Name;
            MutableNickName = false;

            try { Description = p.StorageType == DB.StorageType.ElementId ? "ElementId" : DB.LabelUtils.GetLabelFor(p.Definition.ParameterType); }
            catch (Autodesk.Revit.Exceptions.InvalidOperationException)
            { Description = p.Definition.UnitType == DB.UnitType.UT_Number ? "Enumerate" : DB.LabelUtils.GetLabelFor(p.Definition.UnitType); }

            if (ParameterSharedGUID.HasValue)
            {
                Description = $"Shared parameter {ParameterSharedGUID.Value:B}\n{Description}";
            }
            else if (ParameterBuiltInId != DB.BuiltInParameter.INVALID)
            {
                Description = $"BuiltIn parameter {ParameterBuiltInId.ToStringGeneric()}\n{Description}";
            }
            else
            {
                Description = $"{ParameterBinding} project parameter\n{Description}";
            }
        }
Пример #2
0
        public ParameterParam(DB.Parameter p) : this()
        {
            ParameterName    = p.Definition.Name;
            ParameterType    = p.Definition.ParameterType;
            ParameterGroup   = p.Definition.ParameterGroup;
            ParameterBinding = p.Element is DB.ElementType ? DBX.ParameterBinding.Type : DBX.ParameterBinding.Instance;

            if (p.IsShared)
            {
                ParameterClass      = DBX.ParameterClass.Shared;
                ParameterSharedGUID = p.GUID;
            }
            else if (p.Id.TryGetBuiltInParameter(out var parameterBuiltInId))
            {
                ParameterClass     = DBX.ParameterClass.BuiltIn;
                ParameterBuiltInId = parameterBuiltInId;
            }
            else if (p.Element.Document.GetElement(p.Id) is DB.ParameterElement paramElement)
            {
                if (paramElement is DB.GlobalParameter)
                {
                    ParameterClass = DBX.ParameterClass.Global;
                }
                else
                {
                    switch (paramElement.get_Parameter(DB.BuiltInParameter.ELEM_DELETABLE_IN_FAMILY).AsInteger())
                    {
                    case 0: ParameterClass = DBX.ParameterClass.Family;  break;

                    case 1: ParameterClass = DBX.ParameterClass.Project; break;
                    }
                }
            }

            try { Name = $"{DB.LabelUtils.GetLabelFor(ParameterGroup)} : {ParameterName}"; }
            catch (Autodesk.Revit.Exceptions.InvalidOperationException) { Name = ParameterName; }

            NickName        = Name;
            MutableNickName = false;

            try { Description = p.StorageType == DB.StorageType.ElementId ? "ElementId" : DB.LabelUtils.GetLabelFor(p.Definition.ParameterType); }
            catch (Autodesk.Revit.Exceptions.InvalidOperationException)
            { Description = p.Definition.UnitType == DB.UnitType.UT_Number ? "Enumerate" : DB.LabelUtils.GetLabelFor(p.Definition.UnitType); }

            if (string.IsNullOrEmpty(Description))
            {
                Description = ParameterType.ToString();
            }

            if (ParameterSharedGUID.HasValue)
            {
                Description = $"Shared parameter {ParameterSharedGUID.Value:B}\n{Description}";
            }
            else if (ParameterBuiltInId != DB.BuiltInParameter.INVALID)
            {
                Description = $"BuiltIn parameter {ParameterBuiltInId.ToStringGeneric()}\n{Description}";
            }
            else if (ParameterBinding != DBX.ParameterBinding.Unknown)
            {
                Description = $"{ParameterClass} parameter ({ParameterBinding})\n{Description}";
            }
            else
            {
                Description = $"{ParameterClass} parameter\n{Description}";
            }
        }