Autodesk forge 在forge viewer中找不到分组元素
我正在使用Forge viewer,在Revit文件中,我们正在以组的形式创建一些图元。当在forge viewer中上载Revit文件时,我们无法找到Revit中给出的任何分组数据,我们只能看到整个元素组。有没有办法将Revit组放入forge viewer?。。。。。请帮助我们解决这个问题。您当然知道,Forge是一个完全通用的CAD建模环境 因此,它主要提供对跨领域CAD功能的支持 您寻求的Revit分组功能是BIM特有的,无法以有用的方式为Forge中的所有域重新创建 有很多方法可以解决这个问题 以下是您可能需要考虑的两种主要方法:Autodesk forge 在forge viewer中找不到分组元素,autodesk-forge,Autodesk Forge,我正在使用Forge viewer,在Revit文件中,我们正在以组的形式创建一些图元。当在forge viewer中上载Revit文件时,我们无法找到Revit中给出的任何分组数据,我们只能看到整个元素组。有没有办法将Revit组放入forge viewer?。。。。。请帮助我们解决这个问题。您当然知道,Forge是一个完全通用的CAD建模环境 因此,它主要提供对跨领域CAD功能的支持 您寻求的Revit分组功能是BIM特有的,无法以有用的方式为Forge中的所有域重新创建 有很多方法可以解决
- 实现Revit附加模块以检索和导出分组数据,并使其可用于Forge应用程序
- 在Forge Design Automation for Revit中实施应用程序,以从Forge中托管的RVT收集所需数据
- 实现Revit附加模块以检索和导出分组数据,并使其可用于Forge应用程序
- 在Forge Design Automation for Revit中实施应用程序,以从Forge中托管的RVT收集所需数据
- 杰里米建议的两种方法除外。还有另一种方法可以通过查询查看器属性数据库来实现
目前,Revit组不是“模型结构”面板(实例树)的一部分,并且没有与它们链接的混凝土网格,因此我们无法直接在查看器中使用它们,但幸运的是,它们可以在查看器属性数据库中找到
下面是一个小演示,用于证明这种可能性,请尝试一下:
//
// 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' );
//
//版权所有(c)Autodesk,Inc.保留所有权利
//
//在中使用、复制、修改和分发此软件的权限
//特此授予任何目的的目标代码表,且不收取任何费用,
//前提是上述版权声明出现在所有副本中,并且
//版权声明和有限保修以及
//以下限制权利通知出现在所有支持文件中
//文件。
//
//AUTODESK按“原样”提供此程序,并带有所有故障。
//AUTODESK明确否认对以下内容的任何默示担保:
//适销性或适合某一特定用途。AUTODESK公司。
//不保证程序的运行将
//不间断或无错误。
//
//Forge Autodesk.ADN.RevitGroup面板
//由Eason Kang提供-Autodesk开发者网络(ADN)
//
"严格使用",;
(功能(){
函数用户函数(pdb){
让_nameAttrId=pdb.getAttrName();
设_internalGroupRefAttrId=-1;
//迭代所有属性,找到我们感兴趣的属性的索引
枚举属性(函数(i、attrDef、attrRaw){
让category=attrDef.category;
让name=attrDef.name;
如果(名称=='组'&&category=='\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu){
_internalGroupRefAttrId=i;
return true;//停止对其余属性的迭代。
}
});
//log(_internalGroupRefAttrId);
//提前返回是因为模型不包含“组”的数据。
if(_internalGroupRefAttrId==-1)
返回null;
设_internalMemberRefAttrId=-1;
//迭代所有属性,找到我们感兴趣的属性的索引
枚举属性(函数(i、attrDef、attrRaw){
让category=attrDef.category;
让name=attrDef.name;
如果(名称=='Member'&&category=='\uuuuu internalref\uuuuuu'){
_internalMemberRefAttrId=i;
return true;//停止对其余属性的迭代。
}
});
//log(_internalMemberRefAttrId);
//提前返回是因为模型不包含“成员”的数据。
if(_internalMemberRefAttrId==-1)
返回null;
设_categoryAttrId=-1;
//迭代所有属性,找到我们感兴趣的属性的索引
枚举属性(函数(i、attrDef、attrRaw){
让category=attrDef.category;
让name=attrDef.name;
如果(名称=='Category'&&Category=='{
_categoryAttrId=i;
return true;//停止对其余属性的迭代。
}
});
//控制台日志(_categoryAttrId);
//提前返回是因为模型不包含“成员”的数据。
如果(_categoryAttrId==-1)
返回null;
常量组=[];
//现在迭代所有部分以查找所有组
枚举对象(函数(dbId){
设isGroup=false;
//对于每个零件,迭代其属性。
enumObjectProperties(dbId,函数(attrId,有效){
//仅处理“Caegory”属性。
//“属性”和“属性”可以互换使用。
if(attrId===\u categoryAttrId){
常量值=pdb.getAttrValue(attrId,有效);
如果(值=='Revit Group'){
isGroup=true;
//找到“Caegory:Revit组”后,停止迭代其他属性。
返回true;
}
}
});
如果(!isGroup)返回;
const children=[];
让groupName='';
//对于每个零件,迭代其属性。
pdb.e