Autodesk Forge API: How can I access the count of elements of a BIM model that is displayed in the Model browser via the API? - autodesk-forge

I need to filter out all parents and childs to obtain only BIM model information about the individual elements of the BIM model. In the Model browser the total counts of individual elements are displayed, but I cannot figure out how to get this information via the API. Below is a picture of what I'm am talking about
How can I access the count of elements of a BIM model that is displayed in the Model browser via the API?
Edit: The question is a bit more elaborate.
What we are able to discern is the root and the leaf node (the end node). When we're using this method at the screenshot shown above, we are not able to retrieve the correct parent (which shows the count of the children). Here, I'd like to get the parent named 'NLRS_31_DO_UN_deurblad_hout_opdek_glas_gen_cie:Standaard', when we're navigating from leaf 'CIE_NLRS_31_DO_o1_glas_helder'.
How can I retrieve in this example the lowest child node (in AutoDesk's viewer model browser) indicated with the number '3' from the corresponding leaf node?

Suppose the dbId of the parent node 16.12-f...ihw, recht:500x 600 is 1234.
To get its child count, just call InstanceTree#getChildCount on it.
let model = viewer.getAllModels()[0];
let it = model.getInstanceTree();
let nChild = it.getChildCount( 1234 ); //!<<< here you go

Related

Is it possible to implement the highlight function in Forge Viewer by receiving a specific ID from an external web page?

IFC format project is being viewed with Forge Viewer. IFC project elements (top panel, slab, right wall, etc.) are listed on an external web page, and I want to implement a function that highlights in Forge Viewer when one of them is selected.
Should I use 'GLOBALID' to implement the function?
I've been looking for Forge Viewer's API(v7), but I'm curious if it provides the same functionality as above.
Yeah, it's possible. Here is a sample demonstrating this idea:
https://github.com/yiskang/forge-viewer-iframe-interoperability
This sample supports two ways to locate objects:
By passing querying strings to viewer page's URL (See public/extlink.html):
urn: It stands for which model to load by the Forge Viewer.
idType: It stands for the IFC guid type. If the IFC model is translated by the legacy IFC pipeline, then the idType is GLOBALID. On the contrary, if you're using modern pipeline, the idType is IfcGuid.
guid: It stands for the IFC guid of the object you want to locate.
With those parameters, you can locate objects after model is loading completely immediately by passing them to the URL like the below:
http://localhost:3000/viewer/?urn=dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3bGt3ZWo3eHBiZ3A2M3g0aGwzMzV5Nm0yNm9ha2dnb2YvcmFjX2Jhc2ljX3NhbXBsZV9wcm9qZWN0X2xlZ2FjeS5pZmM&type=GLOBALID&guid=2cgXCjpDT0ZxBvxMSr3pfm
By triggering LOCATE_ELEMENT_EVENT (See public/index.html):
// Trigger event from iframe's parent page
const guid = event.target.getAttribute('data-guid');
const idType = event.target.getAttribute('data-idType');
if (!idType || !guid) return;
const iframeWind = viewerIframe.contentWindow;
iframeWind.NOP_VIEWER.fireEvent({
type: iframeWind.Autodesk.ADN.ElementLocator.Event.LOCATE_ELEMENT_EVENT,
idType,
guid
});

Missing rooms issue with generatedMasterView and room material replacement using three.js

1st question: Missing room models
I used the model-derivative api from Forge with generatedMasterViews params to extract room nodes from the cloud Revit model (BIM360Team) it work perfectly fine for some model but I had the missing room issues with others.
Successful translated model
Some of the translated model's room nodes was missing and that's weird because their height and phase are the same and the rooms in 2d view were shown.
2D views has no problem at all
3D room nodes in the same floor were missing
So my question is, are their some limitation to extract the room geometry and convert to .svf files? e.g. publish view setting / view range / crop views / crop region ? or something I'm missing in my request ? I tried to align all the parameter or remove some component (e.g. furniture) but the result still the same. If you guys had noticed this issues before please help, your help would be appreciate.
2nd question: Room mesh and materials
I've write the function to highlight the selected elements and its work with almost every nodes except the room elements.
const highLightElement = (dbId, hexColor) => {
const myMaterial = createMaterial(hexColor)
const instanceTree = viewerApp.model.getInstanceTree()
const fragList = viewerApp.model.getFragmentList()
instanceTree.enumNodeFragments(dbId, function(fragId) {
fragList.setMaterial(fragId, myMaterial)
const fragProxy = viewerApp.impl.getFragmentProxy(viewerApp.model, fragId)
fragProxy.scale = new window.THREE.Vector3(scaleRatio, scaleRatio, scaleRatio)
fragProxy.updateAnimTransform()
}, true)
viewerApp.impl.invalidate(true)
}
The material of the room was gloomy white but if use section tool on it the section color already change to the color I choose (0xAB00EE - magenta). I don't know that is the room mesh different from others? or might be need some special procedure to do so?
Successful coloring nodes
Room nodes coloring
Z-section of colored room nodes
Regarding issue #1, it's possible that there are certain limitations preventing the Forge Model Derivative service from extracting room information but that would be more on the Revit side. If you wouldn't mind sharing the Revit model with us (confidentially) via forge (dot) help (at) autodesk (dot) com, we'd be happy to investigate it with the engineering team. In that case, please indicate which rooms are missing, too.
Regarding issue #2, from the Forge Viewer standpoint, rooms are just another geometry in the scene, with the only difference that this geometry is usually transparent and hidden by default. As far as I know, the visibility flag should not interfere with something like setting the material of a fragment but double-check if that really isn't the root cause.

how to get URN of clicked object(mechanical equipment ) in forge?

I have created small web app which can able to render revit model using Forge Viewer, now i want to extend to next level. there is any way to fetch URN of each object on click event. here object refer to mechanical equipment.
i want to open new web page with that particular selected object(single object). single object should be there
Not sure if you wanted the selected nodes (parts) of the model selected or visible/loaded only when the page is opened so I'd cover both options here...
You can either select the components/nodes by their dbids soon as the model's loaded (when the model tree is available so nodes can be associated with their dbids):
const selection = viewer.getSelection()
//persist or pass the dbid array as parameter for the new page
//...
NOP_VIEWER.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, e=>{
viewer.select(selection) // or viewer.isolate(selection) depending on your needs
})
Or load the selected components only following here ...

How to show item in revit file using Forge Viewer?

We have a web app connected with Autodesk Forge. We were able to upload and view revit files and get the metadata of the file. Now, we want to view specific item in the file without viewing the whole file. How can we make that using the Forge Viewer??
EDIT
The correct option to pass in should be ids and not dbids, been a while since I used this so had to brush up on it...
Yes simply pass in an array of dbids for Viewer to partially load the model:
const options = {
ids: [233,2333 ...]
//...
}
viewer.start/loadModel(svfUrl, options) // or viewer.loadDocumentNode(doc, geom, options)
Note that with this approach there's no option to load the rest of the nodes back w/o reloading the entire model with their dbids passed in again.
Also note that dbids are inconsistent between conversions (they are subject to change if the model is translated again) so use externalIds of a node to map it to a component in the editor space (Revit).

Is there extension to show the models on a level?

I'd like to make a function to show models on a level which someone selected like a function that we can see in BIM 360 docs.
level selection in BIM 360 docs
Is there such kind of extension?
Try the Autodesk.AEC.LevelsExtension extension - so long as the model comes with the required AEC data about existing floors:
viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT/Autodesk.Viewing.GEOMETRY_LOADED_EVENT , //wait till design data is loaded
viewer.loadExtension('Autodesk.AEC.LevelsExtension')
)
You can inspect whether your model contains the necessary data using model.getAecModelData()