Skip to main content

Autodesk files

New in v14.25.0
Reference

For a more technical API reference, please see the following pages:

The AutodeskFileField lets a user select a single file from Autodesk cloud storage. For the AutodeskView, an access token is required; therefore, an Autodesk Platform Services integration must be set up first, and the integration name must be passed in the field.

import viktor as vkt

class Parametrization(vkt.Parametrization):
autodesk_file = vkt.AutodeskFileField(
"Select a file",
oauth2_integration="aps-integration-1",
)

Expand to see all available arguments

In alphabetical order:

  • description, add a tooltip with extra information
vkt.AutodeskFileField(..., description="This field represents the project model")
  • file_types, optional restriction of file types, case insensitive
vkt.AutodeskFileField(..., file_types=[".rvt"])
  • flex, width of the field between 0 and 100, default is 33
vkt.AutodeskFileField(..., flex=50)
  • name, defines the position of the parameter in params
vkt.AutodeskFileField(..., name="f")  # obtained using params.f
  • oauth2_integration, required integration name for Autodesk authentication
vkt.AutodeskFileField(..., oauth2_integration="aps-integration-1")
  • visible, control visibility based on other input fields
vkt.AutodeskFileField(..., visible=vkt.Lookup("another_field"))

See 'Hide a field' for elaborate examples.

Using AutodeskFileField in a Controller

The user input can be obtained through the params argument and can have the following values:

The following sections show how to use these methods and attributes to download the raw file and to display the model in VIKTOR apps.

Downloading a model file

To download a BIM model, you start with the AutodeskFile and follow a clear sequence. First, use the integration to obtain a token. Then request the latest AutodeskFileVersion, read its attributes to get the file metadata, and finally download the file. The code below demonstrates this flow:

  1. Obtain an access token with OAuth2Integration.
  2. Use get_latest_version(token) on the AutodeskFile to retrieve the latest version.
  3. Access metadata through version.attributes.
  4. (Optional) Get the model identifier with version.urn.
  5. Call version.get_file() to get the file content and return it in a DownloadResult..
import viktor as vkt

class Parametrization(vkt.Parametrization):
autodesk_file = vkt.AutodeskFileField(
"Select a file",
oauth2_integration="aps-integration-1",
)
download = vkt.DownloadButton("Download BIM model", method="download_model")


class Controller(vkt.Controller):
parametrization = Parametrization

def download_model(self, params, **kwargs):
if not params.autodesk_file:
raise vkt.UserError("Select a file in the Autodesk field")

integration = vkt.external.OAuth2Integration("aps-integration-1")
token = integration.get_access_token()

# Latest version and key metadata
version = params.autodesk_file.get_latest_version(token)
attrs = version.attributes # dict
display_name = attrs.get("displayName", "model")
urn = version.urn

vkt.UserMessage.info(f"Downloading BIM file, urn={urn}")

file_bytes = version.get_file()
return vkt.DownloadResult(file_content=file_bytes, file_name=display_name)

AutodeskFileVersion attributes

The AutodeskFileVersion.attributes property returns a dict with the file’s metadata. Common attributes include displayName (file name), versionNumber, createTime and createUserName, lastModifiedTime and lastModifiedUserName, fileType, storageSize, processing and review states such as processState, extractionState, splittingState, reviewState, and revision identifiers like revisionDisplayLabel and sourceFileName.

Displaying a model file

The AutodeskFile can be passed directly to a AutodeskResult to display the model in an AutodeskView. Refer to the complete documentation for sample code.

Miscellaneous file properties

There are various other file properties and methods:

AutodeskFile

AutodeskFileVersion

  • storage_url (≥ v14.26.0): Storage url of this version of the file.