You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Revit API读取族类型参数值与Revit 2017显示不符求助

Fixing Inconsistent Family Type Parameter Value Display in Revit 2017

It looks like the core issue here is that you’re overriding the UI-formatted, user-facing value provided by AsValueString() with raw numeric data for Double-type parameters. Revit’s properties panel displays values using the project’s unit settings (like architectural inches instead of raw feet for depth), but your code is replacing that formatted output with a manual conversion of the raw double value—this is why the numbers don’t match what you see in Revit 2017.

Let’s break down the fix step by step:

The Root Problem

In your FamilyParamValueString method, you correctly start by grabbing the UI-matching value with t.AsValueString(fp), but immediately overwrite it for Double-type parameters using Util.RealString((double)t.AsDouble(fp)) + " (double)". This raw numeric value ignores Revit’s unit formatting, rounding rules, and display preferences, so it can’t match the properties panel.

The Solution

To get values that exactly match what’s shown in Revit, lean on AsValueString() as your primary source for all parameter types where it’s supported. Only supplement or replace it for types where AsValueString() doesn’t provide meaningful output (like ElementId). Here’s the updated method:

static string FamilyParamValueString(FamilyType t, FamilyParameter fp, Document doc) {
    // Start with the UI-formatted value that matches Revit's properties panel
    string value = t.AsValueString(fp);
    
    // Only adjust for types where AsValueString doesn't give full context
    switch (fp.StorageType) {
        case StorageType.ElementId:
            ElementId id = t.AsElementId(fp);
            Element e = doc.GetElement(id);
            value = $"{id.IntegerValue} ({Util.ElementDescription(e)})";
            break;
        case StorageType.String:
            // Add quotes for clarity if needed, keep the AsValueString result
            value = $"'{value}'";
            break;
        // For Double, Integer, and default cases: keep the AsValueString output
        case StorageType.Double:
        case StorageType.Integer:
        default:
            break;
    }
    return value;
}

Key Details

  • AsValueString() is purpose-built for this: It returns the parameter value formatted exactly as it appears in Revit’s UI, respecting project units (e.g., converting raw feet to inches for depth), rounding, and display conventions. For the Dimension’s Depth parameter, this will give you something like "1/2"" (architectural units) instead of the raw double value like 0.0416666666666667.
  • If you need the raw numeric value for calculations, you can still use AsDouble() alongside AsValueString(), but don’t use it as the primary display value if you want to match the UI.
  • Double-check that you’re accessing the correct type parameter (not an instance parameter) and that familytype.HasValue(fp) is correctly flagging parameters with valid values.

内容的提问来源于stack exchange,提问作者Ali Asad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:28:06