Skip to main content

Visualize Autodesk model

New in v14.25.0

This guide explains how to add an AutodeskView, to visualize a model from Autodesk cloud storage directly in the editor. For the AutodeskView an access token is required, meaning that an Autodesk integration should be set up beforehand.

Implementation

The AutodeskView both accepts an AutodeskFile (e.g. from an AutodeskFileField), or a version URN (of the form "urn:XXX?version=Y") directly:

import viktor as vkt


class Controller(vkt.Controller):

@vkt.AutodeskView('Autodesk')
def autodesk_view(self, params, **kwargs):
integration = vkt.external.OAuth2Integration("autodesk-integration")
token = integration.get_access_token()

autodesk_file = params.autodesk_file # value of AutodeskFileField
# or
autodesk_file = "urn:adsk.wipprod:fs.file:vf.xYz?version=4" # obtain the URN directly from cloud storage

return vkt.AutodeskResult(autodesk_file, access_token=token)

Testing

Methods decorated with @AutodeskView need to be mocked within the context of (automated) testing.

import unittest

import viktor as vkt

from app.my_entity_type.controller import MyEntityTypeController

class TestMyEntityTypeController(unittest.TestCase):

@vkt.testing.mock_View(MyEntityTypeController)
def test_autodesk_view(self):
params = ...
result = MyEntityTypeController().autodesk_view(params=params)
self.assertEqual(result._autodesk_file, ...)