A360 viewer: Fetching object properties for web application integration - autodesk-forge

I am trying to integrate the autodesk a360 viewer into my web application. However, we'll like to extract the object properties of the selected object to fetch additional information from within our database. For example, when user clicks on a door, we wan to extract the tag id of this door from the object properties and perform some sql query with this tag id.
I've seen autodesk forge, but it i m not too sure if it is an overkill or its to direction to go.

Yes, what you want to achieve is absolutely possible within Forge. Actually, there are 2 ways to get the properties for an object. Either from server side(Model Derivate API) or client side(Forge Viewer API), I listed both of them here in case you are interested. But for your case, I think the 2nd way to use Forge Viewer API is more suitable.
1st solution, with Model Derivative API, it provides the following 3 APIs, the 1st API is used to get a list of model view Ids for a design model. Then, you can use the 2nd API to get a hierarchical list of objects for the model view. With the last API, you can get all the properties for the specified object that is represented by guid.
Please check the Model Derivative API for the details about following 3 APIs.
GET :urn/metadata
GET :urn/metadata/:guid
GET :urn/metadata/:guid/properties
2nd Solution is using Forge Viewer API, first, you need to register an event of SELECTION_CHANGED_EVENT, within that event, it’s easy to get dbId of the selected object, and use the API getProperties as follow to fetch all the properties you want, then perform some sql query with this property as you want. The code snippet is as follow, and I have a small sample code to demonstrate the solution if you are interested.
currentModel.getProperties(dbId, function(result) {
console.log("List properties of DbId:" + dbId);
if (result.properties) {
result.properties.forEach(function(prop) {
// call API to perform sql query with the property you are interested
console.log(prop);
});
};
});
Hope it helps.

Related

Fetch All Properties Missing Room Information

this is a question and possibly an improvement request. When I use the model derivative api to fetch object properties from a converted Revit model, I don't understand why it won't fetch the room data.
In my example we are only processing 2D views, and those 2D views are interactive, similar to BIM 360 I'm able to select a room and query its properties in forge viewer. So I know the properties are there in the conversion, but for some reason, Object Tree doesn't give room objects and thus it doesn't give room parameter data.
What I tried:
Convert a Model Revit Model floor plan using the model derivative API. Viewing the model in Forge Viewer should allow you to select a room element and query its properties, such as the screenshot below.
Image of Room Selected in Forge Viewer Floor Plan View
so we know the data for the Room objects is in the forge conversion.
Using the model derivative api to fetch the object tree and / or metadata, the room objects don't exist. I read something that seemed to indicate to generate master views, but I'm not sure I understand why that is necessary because the 2D conversions I am doing, we aren't generating master views, but still seem to have the room data accessible in Forge Viewer.
What I expected
It seems to me as a developer and user that the model derivative API could fetch the room objects and their data. Please correct me if I'm missing something.

Get (dbis, externalid )Element property using api in forge viewer

we are working on to get element property from elementid and dbid, that we can get by loading model on viewer and access the method, but is there any api that forge provide, can we get element property without loading model for that is there any api is available or not.
Thank you.
If you want to get element parameters without opening the Forge Viewer, you can take advantage of the Model Derivative API itself. Here are three endpoints for your reference. Please execute them after your svf/svf2 translation job is completed&successful, then run them by sequence.
https://forge.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-metadata-GET/
https://forge.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-metadata-guid-GET/
https://forge.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-metadata-guid-properties-GET/

Get Discipline of View [Autodesk Model Derivative API]

I'm trying to get the Discipline Property of a Revit Model uploaded to BIM 360. I was able to get the list of views by GET
https://developer.api.autodesk.com/modelderivative/v2/designdata/URL_SAFE_URN_OF_SOURCE_FILE/metadata
However there is no data on Discipline. Where and how can I get it?
I'm not familiar with "Discipline Properties" in Revit but I can comment on the Forge side of things:
The GET :urn/metadata endpoint simply returns a list of "viewables" that were extracted from the source design file. In case of Revit, these are typically 3D views or 2D sheets. I'm not aware of any other types of viewables that could be extracted by the Model Derivative service.
If the "discipline property" is a property available on some of the Revit elements, you might want to take a look at the GET :urn/metadata/:guid/properties endpoint. This one returns a JSON with properties of objects in one of the extracted viewables. Note that those properties are also accessible from Forge Viewer using its APIs.
In general, the Model Derivative service is trying to extract the "right" amount of information, making sure that the viewer gets all the important data for visualization and analysis, but also making sure that the size of the converted output stays in bounds. If there is some specific information in Revit designs that you need that is not extracted automatically, you can consider using the Design Automation service to process your Revit models in the cloud and extract all the information with your custom Revit plugin.

How to set custom properties for an object via its dbid in Autodesk Forge Viewer?

I'm trying to set custom properties for objects via their dbids but the API they provide doesn't seem to help to achieve that because it requires object to be selected and it doesn't save the property. I also look at POST references in Model Derivative API and PATCH in Data Management API, but they're used at document level, not model item.
All resources in a model are currently read-only, so you won't find any endpoint that allows you to modify a model or its properties.
A workaround is to use a custom database along with custom endpoints exposed by your own server that would allow you to modify overwritten properties. You can take a look at this live demo. The source code is available at Viewing.Extension.MetaProperties.
This article also deals with that topic:
Use Forge or Spreadsheet to Create Shared Parameters

Autodesk ObjectId and ElementId in dwg

I am use to develop one web app using Forge API. It's working well and good. At the same time am using design automation in forge. I can able to create Package and it's working fine.
I will process the dwg file using forge api preparing to viewer. I can able to view dwg in browser.
My issue is I have viewer click event the event click populate the element id. However, my package I can get only the object id. element id and object id totally different.
What is the conman id each object client and server side.
Summary: when user click the object in viewer I want to capture id and store my local database. and using package I need to process the user clicked object.
Example: when user click the drawing number in viewer. From the next time I want change the drawing number dynamically using call package from C# code.
For an RVT file, one easy way to handle this is to extract the Forge externalId from the Forge object properties. That is equal to the Revit element UniqueId property. The RvtMetaProp Revit add-in makes use of this.
Oh, now I just found a better, more complete and succinct explanation of Unique IDs for Forge Viewer Elements:
The Viewer gives access to three types of IDs when dealing with Revit files:
dbId: this is viewer specific and used to manipulate elements within the viewer, such as for the .getProperties() method.
Revit ElementID: exposed as part of the Name property in the viewer. When you select something, the Property panel title is in the form of 'Name [12345]'. You can parse this name string and extract the element id.
Revit UniqueID: exposed as the externalId property in the .getProperty() response.