revit参数

Storagetype 描述了内部存储参数值的类型。在Revit里所有的参数值可以分为5种类型:

None None represents an invalid storage type. This value should not be used.
Integer The internal data is stored in the form of a signed 32 bit integer.
Double The data will be stored internally in the form of an 8 byte floating point number.
String The internal data will be stored in the form of a string of characters.
ElementId The data type represents an element and is stored as the id of the element. 

检查参数值是否可以设为double类型值:

public bool SetParameter(Parameter parameter, double value)
{
    bool result = false;
    //if the parameter is readonly, you cannot change the value of it
    if (null != parameter && !parameter.IsReadOnly)
    {
        StorageType parameterType = parameter.StorageType;
        if (StorageType.Double != parameterType)
        {
            throw new Exception("The storagetypes of value and parameter are different!");
        }
        //If successful, the result is true
        result = parameter.Set(value);
    }
    return result;
}

每个Paramter的参数值类型可以通过Parameter.StorageType来判断

StorageType是一个枚举包含了上面5中参数值类型,

对于StorageType为StorageType.None的参数,不能通过Parameter.Set()来设置,

也不能通过Parameter直接获取到它的值。

对于Integer可以通过Parameter.AsInteger()来获取它们的值

对于Double可以通过Parameter.AsDouble()来获取他们的值,这个返回的是一个英尺单位的值,

还可以通过Parameter.AsValueString(),获取它对于的毫米单位值对应的String。

(比如有一个200.0,你通过AsDouble()得到的是200.0转换的英尺的值,而用AsValueString()得到一个为 “200.0“  的string)

对于String可以通过Parameter.AsString()来获取他们的值

对于ElementId 可以通过Parameter.AsElementId()来获取他们的值

在Set值的时候

传入的参数一定要个Parameter的StorageType对应起来

猜你喜欢

转载自blog.csdn.net/weixin_42479664/article/details/80883569
今日推荐