March 12, 2019

search returns different dbId than selection in UI

You can use the search() function to find elements with certain properties and that might return a different element from the one you imagine.

dbId of elements at different levels

When selecting through the UI, always the leaf elements (the lowest one in the tree branch with no children) are selected. Depending on where the model comes from, those might be Solid/Body elements and not the Component/Part they belong to. It's similar to how things are in manufacturing softwares like Inventor or Fusion 360: there are components/parts and they contain one or more solid bodies with the actual geometry

Elements at different levels of the branch (Component vs Body) have different properties, so depending on what properties you are using for the search, it might not return the leaf element, but one of its parents. In case of the model shown in the topmost picture, only the Component has the "Component Name" property, and only the Body has the "Appearance" property. So if you search for "Component Name", you'll get back a Component and not a Body.
Note: a component may have multiple bodies

However, depending on what you want to do with the element you found, it might make no difference if you found the Component or the Body. E.g. if I use the isolate() function it produces pretty much the same result (apart from a different element being selected in the Structure Browser):

Component vs Body

If you need to, you can of course walk up and down the tree branch to get from a Body to a Component or vice-versa - see enumNodeChildren() and getNodeParentId()

Related Posts

July 11, 2019

New Autodesk Forge Viewer 7.0 is Now Available

Autodesk Forge is our collection of Application Program Interfaces (APIs), documentation, sample code, and a community of cust

Read More

July 10, 2019

Look for exact property value and more

When using the search() function of the Viewer, you can only look for strings that at least partially match a given value.

Read More

July 9, 2019

Webpack and three.js in forge applications

In the newer versions of forge viewers( v6 and above) three.js is included in the forge viwer js file itself.

Read More