Exemple #1
0
        /// <summary>
        /// Method is taken from here:
        /// https://spiderinnet.typepad.com/blog/2011/08/revit-parameter-api-asvaluestring-tostring-tovaluestring-and-tovaluedisplaystring.html
        /// </summary>
        /// <param name="p">Revit parameter</param>
        /// <returns>Stringified contents of the parameter</returns>
        internal static string ToValueString(this Autodesk.Revit.DB.Parameter p)
        {
            string ret = string.Empty;

            switch (p.StorageType)
            {
            case StorageType.ElementId:
                ret = p.AsValueString().ToString();
                break;

            case StorageType.Integer:
                ret = p.AsInteger().ToString();
                break;

            case StorageType.String:
                ret = p.AsString();
                break;

            case StorageType.Double:
                ret = p.AsValueString();
                break;

            default:
                break;
            }

            return(ret);
        }
Exemple #2
0
        public static Model.ParameterValue AsValue(this Autodesk.Revit.DB.Parameter p)
        {
            string text   = null;
            double number = 0;

            switch (p.StorageType)
            {
            case Autodesk.Revit.DB.StorageType.String:
                text = p.AsString();
                return(new Model.ParameterValue {
                    ParameterValueType = ParameterValueType.Text, ValueText = text
                });

            case Autodesk.Revit.DB.StorageType.ElementId:
                text = revitData.Document.GetElement(p.AsElementId()).Name;
                return(new Model.ParameterValue {
                    ParameterValueType = ParameterValueType.Text, ValueText = text
                });

            case Autodesk.Revit.DB.StorageType.Integer:
                number = p.AsInteger();
                return(new Model.ParameterValue {
                    ParameterValueType = ParameterValueType.Number, ValueNumber = number
                });

            case Autodesk.Revit.DB.StorageType.Double:
                number = p.AsDouble().GetConvertValue(p.DisplayUnitType);
                return(new Model.ParameterValue {
                    ParameterValueType = ParameterValueType.Number, ValueNumber = number
                });
            }
            throw new Exception("Đoạn code này không được đọc tới.");
        }
Exemple #3
0
        private static string GetParameterValue(Parameter param)
        {
            string s;

            switch (param.StorageType)
            {
            case StorageType.Double:
                s = param.AsValueString();
                break;

            case StorageType.Integer:
                s = param.AsInteger().ToString();
                break;

            case StorageType.String:
                s = param.AsString();
                break;

            case StorageType.ElementId:
                s = param.AsValueString() == string.Empty ? param.AsElementId().IntegerValue.ToString() : param.AsValueString();
                break;

            case StorageType.None:
                s = "?NONE?";
                break;

            default:
                s = "?ELSE?";
                break;
            }

            return(s);
        }
Exemple #4
0
        /// <summary>
        /// Return value Of parameter all case unit
        /// </summary>
        /// <param name="_parameter"></param>
        /// <returns></returns>
        public static string GetValue(this Autodesk.Revit.DB.Parameter _parameter)
        {
            string value;

            switch (_parameter.StorageType)
            {
            // database value, internal units, e.g. feet:
            case StorageType.Double:
                value = RealString(_parameter.AsDouble());
                break;

            case StorageType.Integer:
                value = _parameter.AsInteger().ToString();
                break;

            case StorageType.String:
                value = _parameter.AsString();
                break;

            case StorageType.ElementId:
                value = _parameter.AsElementId().IntegerValue.ToString();
                break;

            case StorageType.None:
                value = "None";
                break;

            default:
                Debug.Assert(false, "unexpected storage type"); value = string.Empty;
                break;
            }

            return(value);
        }
Exemple #5
0
 public bool IsInt(out int?value)
 {
     value = null;
     if (parameter.StorageType == Rvt.StorageType.Integer)
     {
         value = parameter.AsInteger();
     }
     return(value != null);
 }
        public static bool?GetParameter_bool(this Element element, string parameterName)
        {
            Parameter parameter = element.get_Parameter(parameterName);

            if (parameter != null)
            {
                return(parameter.AsInteger() == 0);
            }
            return(null);
        }
Exemple #7
0
        public static object GetParameterValue(Autodesk.Revit.DB.Parameter param)
        {
            object result;

            switch (param.StorageType)
            {
            case StorageType.ElementId:
                int valueId = param.AsElementId().IntegerValue;
                if (valueId > 0)
                {
                    // When the element is obtained here, to convert it to our element wrapper, it
                    // need to be figured out whether this element is created by us. Here the existing
                    // element wrappers will be checked. If there is one, its property to specify
                    // whether it is created by us will be followed. If there is none, it means the
                    // element is not created by us.
                    var elem = ElementIDLifecycleManager <int> .GetInstance().GetFirstWrapper(valueId) as Element;

                    result = ElementSelector.ByElementId(valueId, elem == null ? true : elem.IsRevitOwned);
                }
                else
                {
                    int paramId = param.Id.IntegerValue;
                    if (paramId == (int)BuiltInParameter.ELEM_CATEGORY_PARAM || paramId == (int)BuiltInParameter.ELEM_CATEGORY_PARAM_MT)
                    {
                        var categories = DocumentManager.Instance.CurrentDBDocument.Settings.Categories;
                        result = new Category(categories.get_Item((BuiltInCategory)valueId));
                    }
                    else
                    {
                        // For other cases, return a localized string
                        result = param.AsValueString();
                    }
                }
                break;

            case StorageType.String:
                result = param.AsString();
                break;

            case StorageType.Integer:
                result = param.AsInteger();
                break;

            case StorageType.Double:
                result = param.AsDouble() * Revit.GeometryConversion.UnitConverter.HostToDynamoFactor(param.Definition.UnitType);
                break;

            default:
                throw new Exception(string.Format(Properties.Resources.ParameterWithoutStorageType, param));
            }

            return(result);
        }
Exemple #8
0
        //----------------------------------------------------------
        public static void GetParameterValue(Parameter para, Parameter para_change)
        {
            try
            {
                if (para != null)
                {
                    if (para.Definition.Name == para_change.Definition.Name && para.IsReadOnly == false)
                    {
                        // Use different method to get parameter data according to the storage type
                        switch (para.StorageType)
                        {
                        case StorageType.Double:
                            //covert the number into Metric
                            para.Set(para_change.AsDouble());
                            break;

                        case StorageType.ElementId:
                            //find out the name of the element
                            para.Set(para_change.AsElementId());
                            break;

                        case StorageType.Integer:
                            para.Set(para_change.AsInteger());
                            break;

                        case StorageType.String:
                            para.Set(para_change.AsString());
                            break;

                        default:
                            //defValue = "Unexposed parameter.";
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #9
0
        public ParameterJSON(RevitParam param,
                             [DefaultArgument("Synthetic.Revit.Document.Current()")] revitDoc Document)
        {
            this.Name        = param.Definition.Name;
            this.StorageType = param.StorageType.ToString();
            switch (this.StorageType)
            {
            case "Double":
                this.Value = param.AsDouble().ToString();
                break;

            case "ElementId":
                ElementIdJSON id = new ElementIdJSON(param.AsElementId(), Document);
                this.Value = ElementIdJSON.ToJSON(id);
                break;

            case "Integer":
                this.Value = param.AsInteger().ToString();
                break;

            case "String":
            default:
                this.Value = param.AsString();
                break;
            }

            this.Id = param.Id.IntegerValue;

            if (IsShared)
            {
                this.GUID = param.GUID.ToString();
            }
            else
            {
                this.GUID = "";
            }

            this.IsShared   = param.IsShared;
            this.IsReadOnly = param.IsReadOnly;
        }
Exemple #10
0
 ParamValueToStr(Revit.Parameter param)
 {
     if (param.StorageType == Revit.StorageType.Double)
     {
         return(param.AsDouble().ToString());
     }
     else if (param.StorageType == Revit.StorageType.ElementId)
     {
         return(param.AsElementId().ToString());
     }
     else if (param.StorageType == Revit.StorageType.Integer)
     {
         return(param.AsInteger().ToString());
     }
     else if (param.StorageType == Revit.StorageType.String)
     {
         return(param.AsString());
     }
     else
     {
         Debug.Assert(false);
         return(string.Empty);
     }
 }
        public SerialParameter(RevitParam parameter,
                               [DefaultArgument("Synthetic.Revit.Document.Current()")] RevitDoc Document)
        {
            this.Name        = parameter.Definition.Name;
            this.StorageType = parameter.StorageType.ToString();
            switch (this.StorageType)
            {
            case "Double":
                this.Value = parameter.AsDouble().ToString();
                break;

            case "ElementId":
                this.ValueElemId = new SerialElementId(parameter.AsElementId(), Document);
                //this.Value = param.AsElementId().ToString();
                break;

            case "Integer":
                this.Value = parameter.AsInteger().ToString();
                break;

            case "String":
            default:
                this.Value = parameter.AsString();
                break;
            }

            this.Id = parameter.Id.IntegerValue;

            if (IsShared)
            {
                this.GUID = parameter.GUID.ToString();
            }

            this.IsShared   = parameter.IsShared;
            this.IsReadOnly = parameter.IsReadOnly;
        }
Exemple #12
0
        //----------------------------------------------------------
        public static string GetParameterInformation(Parameter para, Document document)
        {
            string defValue = string.Empty;

            try
            {
                if (para != null)
                {
                    // Use different method to get parameter data according to the storage type
                    switch (para.StorageType)
                    {
                    case StorageType.Double:
                        //covert the number into Metric
                        defValue = para.AsValueString();
                        break;

                    case StorageType.ElementId:
                        //find out the name of the element
                        Autodesk.Revit.DB.ElementId id = para.AsElementId();
                        if (id.IntegerValue >= 0)
                        {
                            defValue = document.GetElement(id).Name;
                        }
                        else
                        {
                            defValue = id.IntegerValue.ToString();
                        }
                        break;

                    case StorageType.Integer:
                        if (ParameterType.YesNo == para.Definition.ParameterType)
                        {
                            if (para.AsInteger() == 0)
                            {
                                defValue = "False";
                            }
                            else
                            {
                                defValue = "True";
                            }
                        }
                        else
                        {
                            defValue = para.AsInteger().ToString();
                        }
                        break;

                    case StorageType.String:
                        defValue = para.AsString();
                        break;

                    default:
                        defValue = "Unexposed parameter.";
                        break;
                    }
                }
            }
            catch (Exception)
            {
                //MessageBox.Show(ex.Message);
            }
            return(defValue);
        }