Reputation: 59
How can I get some component information on Forge viewer?
When I click a column or beam, I want get it`s property(name,id...). Suppose it has property.
Which API can use?
thanks
Upvotes: 0
Views: 544
Reputation: 2206
Viewer provides getProperties that sends back all properties of an object. The code below is a demo. It assumes some objects have been selected. If you have delegated SELECTION_CHANGED_EVENT, event.dbIdArray returns the selection set.
//get selection set (DbIds array)
var sel = myviewer.getSelection();
//if we only want to check the first object in the selected set
myviewer.getProperties(sel[0],function(objProp){
if(objProp){
console.log(objProp);
//iterate each property
for(var index in objProp.properties){
var Prop = objProp.properties[index];
console.log('name: ' + Prop.displayName + ' value:'
+Prop.displayValue);
}
}
});
if you want to get one specific property, you can use viewer.model.getBulkProperties. The blog tells more https://forge.autodesk.com/blog/getbulkproperties-method
Upvotes: 1