Metablock
Last updated
Was this helpful?
Last updated
Was this helpful?
Metablock allows pro-code designers to leverage libraries to add their dynamic blocks in XMPro using script files.
We recommend leveraging generative AI to write the scripts. This approach can significantly streamline the development process and enhance the functionality of the blocks.
Upload the HTML script file that will be rendered in your Metablock, which is used to create dynamic blocks that may display data from a or from .
Alternatively, you can write your scripts in a single HTML file that includes both CSS and JavaScript. This approach is ideal for smaller applications.
If you wish to add styling, upload a CSS file to style your Metablock control.
If you wish to run JavaScript, upload a JavaScript file for your Metablock. Place any initial/startup values as constants in this file.
Common properties include: filter, sort, show # of results, and skip # of results;
If you wish to define value mappings for run-time use, you can configure user-defined key-value pairs. These values remain static during application rendering.
When selecting Server Variables as a Source for the Value Mapping, the list of unencrypted Server Variables will be displayed. Tick the Encrypt checkbox to use an encrypted Server Variable for values like keys, secrets, or password.
Encrypted Server Variables will not have their value available immediately on the Metablock. Instead, you can use them inside a Fetch/XHR request or a Websocket/MQTT message before being forwarded to the actual target.
Fetch/XHR Request - You can use encrypted server variables as part of the URL, Header, or Body of the Fetch/XHR request.
Websocket/MQTT Message - You can use encrypted server variables as part of the Websocket message. For MQTT Messages, you can use it as part of the following message types: Connect (Username and Password), Publish (Payload), and Subscribe (Subscribe Topics)
Tick to proxy requests on the AD Server before being forwarded to the actual request. This is ticked by default when using an encrypted server variable on the value mapping, but you can opt in to use it even without any encrypted server variable.
Note: The password property will not have the actual value yet when it is mapped from an Encrypted Server Variable. Instead, it is just a template for the Server Variable name.
Use Value Mapping to incorporate user input for displaying Harmonic Frequency, maintaining connector integrity while improving data visualization.
Leverage Value Mapping to dynamically pass URLs from other data sources or utilize expressions, eliminating the need for manual URL adjustments during version updates.
Note: This is a simple example to demonstrate the APS Viewer API using an unauthenticated repository. Refer to the authenticated use case for a more complex example that includes security measures for credentials.
Find relevant sample, we search for sample Autodesk Forge code and found the following links:
Adapt the sample code to the Metablock format. For simplicity, the HTML, CSS & JavaScript has been combined into a single file.
Test it locally before implementation by running it from another html file (test-harness.html) via a local webserver. A 3D interactive model of a house should load in your browser.
Create the test-harness.html
file in the same directory as your Metablock files.
Run the test-harness.html
in a webserver (node.js)
Open a terminal or command prompt and navigate to your project folder where the metablock files are.
Initialize a new Node.js project by running npm init -y
Install Express by running npm install express
Create public
folder and moved your HTML
, CSS
& JavaScript
files inside
Create a file named server.js
copy and paste below code in server.js
file
To start the server, run node server.js
Drag the Metablock onto your page.
Open Block Properties.
Add the 3 Metablock files by clicking on the plus icon and uploading the main.html
, main.css
, main.js
files and selecting each from their respective dropdown.
Add a Value Mapping of key model_url
and Value https://developer-autodesk.github.io/translated-models/dwfx-sample-house/f0224dd3-8767-45c1-ff99-5c9c881b9fee/0.svf
Save the page
Launch the page
We have added security features in Metablock to safeguard the users from potential attacks, When developing applications, we have selectively enabled the following features:
Form Submission
Pop-up windows
Modal Dialogs
JavaScript Features
External Resources
Allowed Downloads
Additionally, Metablock allows the use of specific hardware APIs for enhanced application capabilities, including camera, encrypted-media, full-screen, geo-location, speaker, accelerometer, gyroscope, magnetometer, and midi.
Due to the timing of function instantiation, we recommend checking the document's ready state instead of relying on the load event:
Check document's ready state:
Alternatively use one of the existing functions.
To load external script files, include a script block like you would usually do on an html file. The same thing applies for styles/css files.
You can also reference resources (js, css, image) uploaded on your App Files folder by following the correct format for the URL when referencing. Prefix the path with "./AppFiles/" and append the path of the App Files resource:
See the following example for the html that links different resources from the App File:
App Files
For an App Files folder structure that looks like this:
HTML
Link the resources by following the correct format.
ex. "./AppFiles/offline_files/offline-script.js"
Note: Displaying the Metablock may take some time since it needs to finish loading all referenced App File resources before it is shown on the Application. Avoid referencing heavy files from the App Files and use external resources instead.
You can also dynamically load JavaScript files but only for external resources and not from the App Files.
This can occur if your HTML file includes inline script import code that does not follow the correct format. Only link external resources or make sure the file is uploaded on App Files and the URL format is correct.
To use the Data Source property, include these predefined JavaScript functions in your :
You can refer to a working example script that demonstrates an Autodesk Forge visualization .
The Value Mapping opens a new blade to setup the Key and Value configuration. The options for the Value Source are Static, , and .
To use Value Mapping, include this predefined JavaScript function in your :
Access and visualize your engineering data and designs from the cloud using (APS, formerly Forge).
Leverage when embedding the in XMPro App Pages to display interactive 2D and 3D views of your designs.
When authentication is needed to dynamically load 2D and 3D views of your designs using the . We could utilize a Connector or the Value Mapping and use server variables for the credentials. This eliminates the need for hardcoded credentials while maintaining secure access to the visualization platform, (APS, formerly Forge). See the following Metablock examples on how to use these methods.
Leverage the to get Token from the authentication service and the to pass the token to the Metablock.
Leverage the to pass an encrypted Server Variable to the Metablock and call the authentication service using a Fetch request to get the Token.
Demo:
Github:
Make sure you have Node.js installed on your computer. You can download it from .
Open a web browser and go to
Refer to the simple use case for a complete set of files for this example.