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

Forge Viewer多IFC文件属性查询需求:获取属性值并溯源来源文件

Querying Specific Properties Across Multiple Loaded IFC Files in Forge Viewer

Hey there! I’ve dealt with this exact scenario before—tracking property values back to their source IFC files when multiple models are loaded. Here’s a straightforward approach to make this work:

Step 1: Identify All Loaded Models

First, you need to grab references to every IFC model loaded in the viewer. Each model corresponds to one IFC file, and we can use its name (usually the original filename) to track the source.

// Get all visible models (adjust if you need hidden ones too)
const loadedModels = viewer.getVisibleModels();

Step 2: Traverse Each Model’s Properties

For each model, we’ll access its property database, iterate through its elements, and extract the target property (like "Name"). We’ll tie each property value back to its parent model.

Here’s a complete code snippet:

// Define the property you want to query (e.g., "Name")
const targetProperty = "Name";

// Store results: key = IFC filename, value = array of property entries
const propertyResults = {};

loadedModels.forEach(model => {
    const ifcFilename = model.name;
    propertyResults[ifcFilename] = [];

    // Get the model's property database
    const propDb = model.getPropertyDb();

    // Traverse all elements in the model
    model.getObjectTree(tree => {
        // Recursively iterate through every element starting from root
        tree.enumNodeChildren(tree.getRootId(), dbId => {
            // Fetch properties for the current element
            propDb.getProperties(dbId, props => {
                // Find the target property in the element's properties
                const matchedProp = props.properties.find(prop => prop.displayName === targetProperty);
                if (matchedProp) {
                    propertyResults[ifcFilename].push({
                        elementDbId: dbId,
                        propertyValue: matchedProp.displayValue,
                        elementType: props.type // Optional: add element type for context
                    });
                }
            });
        }, true); // Set to true for recursive traversal
    });
});

// Log or process your results
console.log("Property values grouped by IFC file:", propertyResults);

Key Notes to Keep in Mind

  • Property Name Variations: IFC properties might have different display names depending on localization or IFC version. For example, "Name" could be "Nom" in French locales, or the internal attribute name might be IFC_NAME. To be safe, print a sample of properties first (e.g., console.log(props.properties)) to confirm the exact name you need to target.
  • Performance Optimization: If you only need properties for specific element types (e.g., walls, doors), use model.search("Wall") to fetch those elements directly instead of traversing every element. This will speed up the process significantly.
  • Model Identification: If the model.name isn’t enough (e.g., duplicate filenames), you can use model.id as a unique identifier for each loaded model.

内容的提问来源于stack exchange,提问作者sanjay pandey

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 07:57:24