Revits 系统浏览器进入 Autodesk Forge

问题描述 投票:0回答:1

[Revit系统浏览器](https://i.stack.imgur.com/ubi2Y.png)

我无法将 Revit 系统浏览器带入 forge。我附上的图片是系统浏览器。

我尝试用很少的代码来带系统浏览器。无法进入系统浏览器.....

autodesk-forge forge
1个回答
0
投票

不幸的是,Model Derivative API 仅将常见的 Revit 数据提取到 SVF/SVF2 中,并非所有 Revit 数据都会存在(例如系统关系)。

但是,如果您只想像系统浏览器一样显示系统层次结构,而不是系统浏览器的所有功能。这是您的起点。请随意修改它以满足您的需求。

function userFunction(pdb) {
    let _nameAttrId = pdb.getAttrName();
    let _childAttrId = pdb.getAttrChild();

    // Iterate over all attributes and find the index to the one we are interested in
    pdb.enumAttributes(function (i, attrDef, attrRaw) {
    let category = attrDef.category;
    let name = attrDef.name;

    if (name === 'Category' && category === '__category__') {
        _categoryAttrId = i;
        return true; // to stop iterating over the remaining attributes.
    }
    });

    //console.log( _categoryAttrId );

    // Early return is the model doesn't contain data for "Member".
    if (_categoryAttrId === -1)
        return null;


    const mepSystemCateNames = [
        'Duct Systems', 'Piping Systems', 'Electrical Circuits'
    ];

    let cateDbIds = pdb.bruteForceSearch('Revit Category', ['Category'], {searchHidden: true});

    const mepSystems = [];

    // Now iterate over all parts to find all mep system categories
    cateDbIds.forEach(function (dbId) {
        let mepSystemCate = false;

        // For each part, iterate over their properties.
        pdb.enumObjectProperties(dbId, function (attrId, valId) {
            if (attrId === _nameAttrId) {
                const nameVal = pdb.getAttrValue(attrId, valId);
                
                if (mepSystemCateNames.includes(nameVal)) {
                    mepSystemCate = true;
                    return true;
                }
            }
        });


        if (!mepSystemCate) return;

        const children = [];
        let systemName = '';

        pdb.enumObjectProperties(dbId, function (attrId, valId) {
            if (attrId === _childAttrId) {
                const childDbId = pdb.getAttrValue(attrId, valId);
                const props = pdb.getObjectProperties(childDbId, ['name']);

                let child = {
                    name: props.name,
                    dbId: childDbId
                };

                let systemTypeChild = pdb.getObjectProperties(childDbId, ['System Name', 'System Type']);
                if (systemTypeChild && systemTypeChild.properties.length > 0)
                   child.systemType = systemTypeChild.properties[0].displayValue;

                children.push(child);
            }

            if (attrId === _nameAttrId) {
                const value = pdb.getAttrValue(attrId, valId);
                systemName = value;
            }
        });

        if (children.length > 0) {
            for(let i=0; i<children.length; i++) {
                const child = children[i];
                let grandChildren = [];

                pdb.enumObjectProperties(child.dbId, function (attrId, valId) {
                    if (attrId === _childAttrId) {
                        const grandChildDbId = pdb.getAttrValue(attrId, valId);
                        const props = pdb.getObjectProperties(grandChildDbId, ['name']);

                        let grandChild = {
                            name: props.name,
                            dbId: grandChildDbId
                        };

                        let systemTypeGrandChild = pdb.getObjectProperties(grandChildDbId, ['System Name', 'System Type']);
                        if (systemTypeGrandChild &&  systemTypeGrandChild.properties.length > 0)
                            grandChild.systemType = systemTypeGrandChildproperties[0].displayValue;

                        grandChildren.push(grandChild);
                    }
                });

                if (grandChildren.length > 0) {
                    for (let j=0; j<grandChildren.length; j++) {
                        const grandChild = grandChildren[j];
                        let grandGrandChildren = [];

                        pdb.enumObjectProperties(grandChild.dbId, function (attrId, valId) {
                            if (attrId === _childAttrId) {
                                const grandGrandChildDbId = pdb.getAttrValue(attrId, valId);
                                const props = pdb.getObjectProperties(grandGrandChildDbId, ['name']);

                                let grandGrandChild = {
                                    name: props.name,
                                    dbId: grandGrandChildDbId
                                };

                                let systemTypeGrandGrandChild = pdb.getObjectProperties(grandGrandChildDbId, ['System Name', 'System Type']);
                                if (systemTypeGrandGrandChild && systemTypeGrandGrandChild.properties.length > 0)
                                    grandGrandChild.systemType = systemTypeGrandGrandChild.properties[0].displayValue;

                                grandGrandChildren.push(grandGrandChild);
                            }
                        });

                        if(grandGrandChildren.length > 0) {
                            grandChild.children = grandGrandChildren;
                        }
                    }

                    child.children = grandChildren;
                }
            }

            let systemType = pdb.getObjectProperties(dbId, ['System Name']);

            mepSystems.push({
                systemName,
                systemType: systemType?.displayValue,
                children
            });
        }
    });

    return mepSystems;
}

let model = viewer.getAllModels()[0];

await model.getPropertyDb().executeUserFunction(userFunction);

结果

© www.soinside.com 2019 - 2024. All rights reserved.