Перейти к основному содержанию

Step 5: Loading model information

Около 1 мин

Step 5: Loading model information

In order to find out the GUID of the desired token, you need to find out information about the models stored on the server.

In order to download the model information, you must first obtain information about the companies in which the account from which the token is obtained participates.

Since one account can participate in several companies and models belong to one company, you will need the GUID of the desired company to get information about them.

Getting information about companies

Create a function to get information about companies in functions.js:

export async function fetchCompanies() {
	const response = await axios.get(TANGL_AUTH_SERVER + "/api/app/company",
		 {
			 headers: {
				 'Authorization': 'Bearer ' + tanglToken
			 },
		 })

	if (response?.data) {
		console.info("Companies are fetched: ", response.data)
	}

	return response.data
}

Add a function call after getting the token in index.js:

import {fetchCompanies, fetchToken, tanglToken} from "./functions.js";
...
await fetchToken()
sceneManager.setToken(tanglToken)

const companies = await fetchCompanies()

The answer should come with a list of companies available for the account, their GUIDs and names:

 [
    {
        "id": "178fda74-d35c-fec7-1d4a-3a077ce1cc24",
        "name": "Developers Demo"
    }
]

Save the company GUID:

const companyId = companies[0].id

Getting information about models

Create a function to get model information in functions.js:

const TANGL_SERVER = "https://platform.tangl.cloud"
export async function fetchModels(companyId) {
	const response = await axios.get(TANGL_SERVER + "/api/app/metaModels",
		 {
			 params: {
				 CompanyId: companyId,
			 },
			 headers: {
				 'Authorization': 'Bearer ' + tanglToken
			 },
		 })

	if (response?.data) {
		console.info("Models are fetched: ", response.data)
	}

	return response.data
}

Add a function call after getting the company GUID to the index.js:

import {fetchModels, fetchCompanies, fetchToken, tanglToken} from "./functions.js";
...
const models = await fetchModels(companyId)

The answer should come with a list of models in the company:

[
    {
        "name": "rac_advanced_sample_project",
        "companyId": "178fda74-d35c-fec7-1d4a-3a077ce1cc24",
        "sw": "RVT",
        "checkedForAnalysis": false,
        "modelPath": "C:\\Program Files\\Autodesk\\Revit 2021\\Samples\\rac_advanced_sample_project.rvt",
        "desc": "Model elements data",
        "date": "2022-11-12T13:56:57.18Z",
        "totalElementsCount": 5760,
        "elementsCount": 5760,
        "versions": null,
        "lastModifiedEmail": "devdemo@tangl.cloud",
        "extraProperties": {},
        "concurrencyStamp": "3f718b9bea9546358ddcf7f3d3299629",
        "id": "52340e85-61af-45a9-63a5-3a077e4e4f99"
    },
    ...
]

Save the GUID of the first model in the list:

const modelId = models[0].id

You can now use it to load the scene:

//load scene from bucket via bucket GUID and zoom camera after load process
sceneManager
   .onAllLoaded(() => {
     renderManager.zoomCameraToSelection()
   }).load(modelId)

This will load the first model from the list - "rac_advanced_sample_project":