【问题标题】:Grouping Elements cannot find in forge viewer在伪造查看器中找不到分组元素
【发布时间】:2020-09-11 02:09:12
【问题描述】:

我正在使用 Forge 查看器,在 Revit 文件中,我们将一些元素创建为组。当 Revit 文件在 Forge 查看器中上传时,我们找不到 Revit 中给出的任何分组数据,我们只能看到总元素组。有没有办法让 Revit 组进入 Forge 查看器?.....请帮助我们解决这个问题。

【问题讨论】:

    标签: autodesk-forge


    【解决方案1】:

    您当然知道,Forge 是一个完全通用的 CAD 建模环境。

    因此,它主要提供对跨域CAD功能的支持。

    您寻求的 Revit 分组功能是特定于 BIM 的,无法以有用的方式重新创建用于 Forge 中的所有域。

    有很多方法可以解决这个问题。

    您可能需要考虑以下两种主要方法:

    • 实施 Revit 插件以检索和导出分组数据并使其可用于您的 Forge 应用程序
    • 在 Forge Design Automation for Revit 中实施一个应用程序,以从 Forge 中托管的 RVT 收集所需数据

    【讨论】:

      【解决方案2】:

      Jeremy 建议的这两种方法除外。还有另一种方法可以通过查询查看器属性 DB 来实现。

      目前,Revit 组不是模型结构面板(实例树)的一部分,并且没有链接到它们的混凝土网格,因此我们无法直接在查看器中使用它们,但幸运的是它们可以在里面找到查看器属性 DB。

      这里有一个小演示来证明这种可能性,请试一试:

      //
      // Copyright (c) Autodesk, Inc. All rights reserved
      //
      // Permission to use, copy, modify, and distribute this software in
      // object code form for any purpose and without fee is hereby granted,
      // provided that the above copyright notice appears in all copies and
      // that both that copyright notice and the limited warranty and
      // restricted rights notice below appear in all supporting
      // documentation.
      //
      // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
      // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
      // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
      // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
      // UNINTERRUPTED OR ERROR FREE.
      //
      // Forge Autodesk.ADN.RevitGroupPanel
      // by Eason Kang - Autodesk Developer Network (ADN)
      //
      
      'use strict';
      
      (function() {
        function userFunction( pdb ) {
            let _nameAttrId = pdb.getAttrName();
      
            let _internalGroupRefAttrId = -1;
      
            // 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 === 'Group' && category === '__internalref__' ) {
                    _internalGroupRefAttrId = i;
                    return true; // to stop iterating over the remaining attributes.
                }
            });
      
            //console.log( _internalGroupRefAttrId );
      
            // Early return is the model doesn't contain data for "Group".
            if( _internalGroupRefAttrId === -1 )
              return null;
      
            let _internalMemberRefAttrId = -1;
      
            // 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 === 'Member' && category === '__internalref__' ) {
                    _internalMemberRefAttrId = i;
                    return true; // to stop iterating over the remaining attributes.
                }
            });
      
            //console.log( _internalMemberRefAttrId );
      
            // Early return is the model doesn't contain data for "Member".
            if( _internalMemberRefAttrId === -1 )
              return null;
      
            let _categoryAttrId = -1;
      
            // 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 groups = [];
            // Now iterate over all parts to find all groups
            pdb.enumObjects(function( dbId ) {
                let isGroup = false;
      
                // For each part, iterate over their properties.
                pdb.enumObjectProperties( dbId, function( attrId, valId ) {
      
                    // Only process 'Caegory' property.
                    // The word "Property" and "Attribute" are used interchangeably.
                    if( attrId === _categoryAttrId ) {
                        const value = pdb.getAttrValue( attrId, valId );
                        if( value === 'Revit Group' ) {
                            isGroup = true;
                            // Stop iterating over additional properties when "Caegory: Revit Group" is found.
                            return true;
                        }
                    }
                });
      
                if( !isGroup ) return;
      
                const children = [];
                let groupName = '';
      
                // For each part, iterate over their properties.
                pdb.enumObjectProperties( dbId, function( attrId, valId ) {
      
                    // Only process 'Member' property.
                    // The word "Property" and "Attribute" are used interchangeably.
                    if( attrId === _internalMemberRefAttrId ) {
                        const value = pdb.getAttrValue( attrId, valId );
                        children.push( value );
                    }
      
                    if( attrId === _nameAttrId ) {
                        const value = pdb.getAttrValue( attrId, valId );
                        groupName = value;
                    }
                });
      
                groups.push({
                    dbId,
                    name: groupName,
                    children
                });
            });
      
            return groups;
        }
      
        class AdnRevitGroupPanel extends Autodesk.Viewing.UI.DockingPanel {
          constructor( viewer, title, options ) {
            options = options || {};
      
            //  Height adjustment for scroll container, offset to height of the title bar and footer by default.
            if( !options.heightAdjustment )
              options.heightAdjustment = 70;
      
            if( !options.marginTop )
              options.marginTop = 0;
      
            super( viewer.container, viewer.container.id + 'AdnRevitGroupPanel', title, options );
      
            this.container.classList.add( 'adn-docking-panel' );
            this.container.classList.add( 'adn-rvt-group-panel' );
            this.createScrollContainer( options );
      
            this.viewer = viewer;
            this.options = options;
            this.uiCreated = false;
      
            this.addVisibilityListener(( show ) => {
              if( !show ) return;
      
              if( !this.uiCreated )
                this.createUI();
            });
          }
      
          async getGroupData() {
            try {
              return await this.viewer.model.getPropertyDb().executeUserFunction( userFunction );
            } catch( ex ) {
              console.error( ex );
              return null;
            }
          }
      
          async requestContent() {
            const data = await this.getGroupData();
            if( !data ) return;
      
            for( let i=0; i<data.length; i++ ) {
              const div = document.createElement( 'div' );
              div.innerText = `${ data[i].name }(${ data[i].children.length })`;
              div.title = `DbId: ${ data[i].dbId }`;
              div.addEventListener(
                'click',
                ( event ) => {
                  event.stopPropagation();
                  event.preventDefault();
      
                  this.viewer.clearSelection();
                  this.viewer.select( data[i].children );
                  this.viewer.fitToView( data[i].children );
                });
              this.scrollContainer.appendChild( div );
            }
      
            this.resizeToContent();
          }
      
          async createUI() {
            this.uiCreated = true;
      
            if( this.viewer.model.isLoadDone() ) {
              this.requestContent();
            } else {
              this.viewer.addEventListener(
                Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
                () => this.requestContent(),
                { once: true }
              );
            }
          }
        }
      
        class AdnRevitGroupPanelExtension extends Autodesk.Viewing.Extension {
          constructor( viewer, options ) {
            super( viewer, options );
      
            this.panel = null;
            this.createUI = this.createUI.bind( this );
            this.onToolbarCreated = this.onToolbarCreated.bind( this );
          }
      
          onToolbarCreated() {
            this.viewer.removeEventListener(
              Autodesk.Viewing.TOOLBAR_CREATED_EVENT,
              this.onToolbarCreated
            );
      
            this.createUI();
          }
      
          createUI() {
            const viewer = this.viewer;
      
            const rvtGroupPanel = new AdnRevitGroupPanel( viewer, 'Revit Group' );
      
            viewer.addPanel( rvtGroupPanel );
            this.panel = rvtGroupPanel;
      
            const rvtGroupButton = new Autodesk.Viewing.UI.Button( 'toolbar-adnRevitGroupTool' );
            rvtGroupButton.setToolTip( 'Revit Group' );
            rvtGroupButton.setIcon( 'adsk-icon-properties' );
            rvtGroupButton.onClick = function() {
              rvtGroupPanel.setVisible( !rvtGroupPanel.isVisible() );
            };
      
            const subToolbar = new Autodesk.Viewing.UI.ControlGroup( 'toolbar-adn-tools' );
            subToolbar.addControl( rvtGroupButton );
            subToolbar.adnRvtGroupButton = rvtGroupButton;
            this.subToolbar = subToolbar;
      
            viewer.toolbar.addControl( this.subToolbar );
      
            rvtGroupPanel.addVisibilityListener(function( visible ) {
              if( visible )
                viewer.onPanelVisible( rvtGroupPanel, viewer );
      
                rvtGroupButton.setState( visible ? Autodesk.Viewing.UI.Button.State.ACTIVE : Autodesk.Viewing.UI.Button.State.INACTIVE );
            });
          }
      
          load() {
            if( this.viewer.toolbar ) {
              // Toolbar is already available, create the UI
              this.createUI();
            } else {
              // Toolbar hasn't been created yet, wait until we get notification of its creation
              this.viewer.addEventListener(
                Autodesk.Viewing.TOOLBAR_CREATED_EVENT,
                this.onToolbarCreated
              );
            }
      
            return true;
          }
      
          unload() {
            if( this.panel ) {
              this.panel.uninitialize();
              delete this.panel;
              this.panel = null;
            }
      
            if( this.subToolbar ) {
              this.viewer.toolbar.removeControl( this.subToolbar );
              delete this.subToolbar;
              this.subToolbar = null;
            }
      
            return true;
          }
        }
      
        Autodesk.Viewing.theExtensionManager.registerExtension( 'Autodesk.ADN.RevitGroupPanel', AdnRevitGroupPanelExtension );
      })();
      
      viewer.loadExtension( 'Autodesk.ADN.RevitGroupPanel' );
      

      这是快照:

      【讨论】:

        猜你喜欢
        • 2021-11-01
        • 2018-09-22
        • 2012-01-15
        • 2018-06-28
        • 2018-10-22
        • 2019-05-15
        • 2021-12-31
        • 1970-01-01
        • 2023-03-18
        相关资源
        最近更新 更多