加载多个模型时,在Forge Viewer中获取选定的元素属性 [英] Getting selected elements properties in forge viewer when more then one model loaded
问题描述
我有一个装有8个模型的查看器应用程序
I have have a viewer app with 8 models loaded
我有一个插件在寻找"AGGREGATE_SELECTION_CHANGED_EVENT"
事件
I have a plugin looking for the "AGGREGATE_SELECTION_CHANGED_EVENT"
event
this.viewer.addEventListener(Autodesk.Viewing.AGGREGATE_SELECTION_CHANGED_EVENT, this.onSelectionBinded);
我需要能够访问所选元素的属性
I need to be able to get access to the selected elements properties
this.viewer.getProperties(_dbId, (result) => { })
但它接缝显示查看器仅查看最后加载的模型,而不是全部查看.我是否必须 load/switch
到其他型号?如果可以的话.
but it seams the viewer is only looking at the last loaded model not all of them.
do i have to load/switch
to the other models ? and if so how.
推荐答案
根据我的经验, viewer.model
始终指向第一个加载的模型.如果要访问其他已加载的模型,则可以通过调用 viewer.impl.modelQueue().getModels()
来获取它们.然后,以这种方式调用Viewer属性API:
The viewer.model
is always pointed to the first loaded model with my experience. If you want to access other loaded models, you can obtain them via calling viewer.impl.modelQueue().getModels()
. Afterward, call Viewer properties APIs in this way:
var allModels = viewer.impl.modelQueue().getModels();
var model = allModels[1];
model.getProperties( dbId, onSuccessCallback, onErrorCallback );
此外,您可以在 onSelectionBinded
回调的函数参数 event
中获得模型实例.因此,可以根据上述逻辑将您的 onSelectionBinded
修改为此:
Besides, you can obtain the model instance in the function argument event
of your onSelectionBinded
callback. So, your onSelectionBinded
can be modified to this based on the above logic:
this.onSelectionBinded = function( event ) {
var selSet = event.selections;
var firstSel = selSet[0];
var model = firstSel.model;
var dbIds = firstSel.dbIdArray;
var firstDbId = dbIds[0];
model.getProperties( firstDbId, onSuccessCallback, onErrorCallback );
}
希望有帮助!
这篇关于加载多个模型时,在Forge Viewer中获取选定的元素属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!