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
        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 #3
0
 public static Dictionary <string, object> GetParameterNameAndValue(Autodesk.Revit.DB.Parameter parameter)
 {
     return(new Dictionary <string, object>
     {
         { "Name", parameter.Definition.Name },
         { "Value", parameter.AsValueString() },
     });
 }
Exemple #4
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);
        }
 public override object GetValue(object component) =>
 parameter.Element is object && parameter.Definition is object?
 (parameter.StorageType == DB.StorageType.String ? parameter.AsString() :
  parameter.AsValueString()) : null;
Exemple #6
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);
        }