how to pass the model name in Viewer.fitToView() - autodesk-forge

We have uploaded multiple BIM models in our web application and we have used Forge Aggregate View to display the all the uploaded BIM models as a merged format. Also we have used Object ID to zoom the object in Forge Viewer. But in Forge Aggregate View we have displayed multiple files. Each file contains the same object id which is point out the different equipments. For Example: File 1 contains object id "2204" (Object name: A) file 2 contains same object id "2204" (Object name: B) I would like to zoom Object A (File 1) in Forge Viewer. So we pass the Object ID 2204 to the Forge Viewer. But the Object B (File 2) has been zoomed in Forge Viewer instead of Object A (File 1).
how to pass the model name in Viewer.fitToView() and Viewer.select() methods.
Is there any way to pass model name directly as a parameter?

Viewer methods like fitToView or select typically accept an additional parameter specifying the model on which the specific action should be executed. Instead of a model name, however, you need to provide an actual instance of the Model class. To obtain the reference to one of the loaded models, you can use the viewer.getVisibleModels() method (which returns Model[]), and pick the model you want to act on, for example, like so:
const models = viewer.getVisibleModels();
viewer.fitToView([2204], models[0]);

Related

Autodesk forge viewer, model properties and model coordination ID relationships

It is not clear for me the relationship between the identifiers used in the Model Coordination API and the ones used in the Model Properties API:
loid: (Model coordination API)
lvid: (model coordination API)
svf2Id:(Model properties API)
databaseId: (Model properties API)
let's say I have some objects with specific propery values and I have found those object by means of the Model properties API.
Then I have some clashes and I would like to know if any of the elements involved in the clashes belongs to the previous group of elements.
Is there any relationship between the loid and the svf2Id for example? how could I achieve this task?
Thanks in advance
Here is the difference between the ids you are asking:
The loid of Model coordination API is the stable object id, but it's just for our service use internally. It's nothing related to what you want, unfortunately. (Same as roid)
The lvid of model coordination API) is the object dbId in SVF format, which matches with the lmvId in Model Properties query results within the exact same model file version in Document Management, so the same version which clashed must be the one which is queried via the Model Properties API.
The lmvId of of Model properties API is dbId for this object in the SVF format.
The svf2Id of Model properties API is dbId for this object in the Forge viewer when loading the model in SVF2 format and when you translated the model to SVF2 format.
The databaseId of Model properties API is the index manifest key for the PDB resource that contains this row for Model properties API.
Therefore, you must use the lvid and rvid, which match with the lmvId in Model Properties query results.

Autodesk Model Derivative API does not retrive all Revit data

Following this question
I am dealing with the same. I am trying to to retrive the type and type parameters, instances and instance parameters of all elements in a 3D view using Model Derivative API, but the data coming from GET/{urn}/metadata/{modelGuid} and GET/{urn}/metadata/{modelGuid}/properties is incomplete.
I.E. You can't get the Revit ID from Categories and Types.
The thing is that in the forge viewer this information appears and you can see the Revit IDs of Categories and Types and their parameters.
I am missing anything? I don't want to go through Design Automation if is not necessary.
Cheers.
What is your Revit ID? Element Id or Unique Id?
If it's element id, you can find it in the object name in Forge Viewer, or decode it from the external id like this thread: Missing revit ID in instance elements
Note. For the worksharing Revit models, the element id decoded from
the external id is different from its actual value, since the final
element id is determined after the element is synced to the central
model.
For Revit unique id, you can find it in the external id of the object properties in Forge viewer.
So, you can find the similarities in the response of GET {urn}/metadata/{modelGuid}/properties, but it's a flattened data structure. To get the relationship of instance, type, and category, we need to iterate the object tree from the GET {urn}/metadata/{modelGuid}.
Note. SVF2 model will remove element id from the object name. If you don't
see that, that means your model was translated to SVF2. You can use
the request header x-ads-derivative-format: fallback to get SVF
properties if the model is stored on BIM360 Docs/Autodesk Docs, or if
you request SVF translation for the same model.
Here is another explanation of the difference between Revit Element Id and unique id: https://stackoverflow.com/a/48720285/7745569
Lastly, here is the JavaScript code snippet of extracting element id from the object name using regex:
const name = 'Floors [123456]'
const elementIdRegx = new RegExp(/\[(.*?)\]/gm);
const result = elementIdRegx.exec( name );
const elementId = result[1]; //!<<< 123456

How to create a model browser like objects from Model Derivative API metadata

I am using this call provided by Forge API to get all Model metadata properties.
https://forge.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-metadata-guid-properties-GET/
I am getting all parent and child objects returned as separate nodes in the json that I am getting in the response. There is no linkage or relationship property saying that object X is a parent of object Y like we get in Model Browser option of Forge Viewer.
Is there a way possible that we can create this object tree after getting the metadata from Forge Model Derivative API. I really appreciate you help.
You can take advantage of the buildModelTree mentioned in this thread to rebuild the instance tree hierarchy:
https://stackoverflow.com/a/60807152/7745569

Attribute names for NWD files in Autodesk Forge viewer different from source Revit file

When I search elements in the Forge viewer using a few parameters in the model that was translated from an NWD file, I find that the attribute names are different from the source Revit file. For example, there is a parameter called "Assembly Name" in the source Revit file, but this name is changed to "LcRevitData_Element:lcldrevit_parameter_-1150420" in the model that was translated from the NWD file.
I found this out when I did a viewer.getProperties() and saw that for the "Assembly Name" parameter:
displayName = "Assembly Name"
attributeName = "LcRevitData_Element:lcldrevit_parameter_-1150420"
But the viewer.search() function uses the attributeName to perform the search in the model. I have functions that search the model based on a few different parameters, so I have hardcoded these attributeNames to do the search. But if there is a revised NWD and I need to upload it again to Forge, will these attributeNames change? They look like some randomly generated string... Or is there some other method that can use the actual parameter name to do a search?
Thanks a lot for any help!
All data extractor from the model should remain the same and authentic to the original model so long as the updates do not change them. Let us know if they change unexpectedly and send us the original model and relevant details to forge.help at autodesk.com.
It's the meta data/identifiers that are generated by our service for use of Viewer and other stacks that change each time the model is translated again and those include dbid(node ID) etc.

Is it possible to load only one specific object from the model(document) when initializing the document in the Forge viewer?

We would like to know if it possible to initialize the viewer to only render an specific object id.
There is a tutorial to extract geometry from a model, but it involves using the derivative to convert geometry to OBJ.
https://forge.autodesk.com/en/docs/model-derivative/v2/tutorials/extract-geometry-from-source-file/
The idea is to create a catalog of objects based on the elements in a model (document). We usually work with Revit files.
Viewer works with dbIds (or nodeIds which are equivalent to objectIds) and may load bubbles (geometry constructs) selectively based on - see live sample here
viewer.loadModel(svfUrl,{ids:[dbIds...]})