Creating Automation Scripts in SAP Integrated Product Development

Objective

After completing this lesson, you will be able to configure a script in SAP Integrated Product Development Visualization and test it against a visualization.

Automation Scripts

Introduction

Imagine you've converted CAD data into a viewable online format within SAP Integrated Product Development (IPD) Visualization. To optimize these visualizations for future use or authoring, you need to perform modifications. For example, cleaning up scenes, adding metadata, or creating smaller visualizations from larger ones. SAP Integrated Product Development Visualization's built-in scripting engine allows administrators to create scripts to automate these tasks, streamlining your workflow.

Data Sources, Cards, and Viewer Templates are powerful tools for building use cases within IPD Visualization. However, complex requirements may need custom code for advanced analysis or processing. The SAP Integrated Product Development Visualization scripting engine enables the creation of custom solutions to meet these needs.

Previously, scripts were executed through workflows. Now, they can be triggered directly from a visualization or during import/publish processes. While nonadmin users can run scripts, creating them requires access to the System Administration application.

Scripts

To create a new script, navigate to the System Administration tile and choose the SCRIPTS tab.

Choose the SCRIPTS tab.

To create a new script, choose Add.

Complete the Name and Description fields, and select a Purpose.
  • Enter a Name and Description. The Purpose field determines when the script can be triggered:
  • General: Typically used to call the script from another script.
  • Import: Used during data import.
  • Visualization: Used to trigger the script from a visualization's ... button.

A basic script imports core scripting tools, logs a message to the console, and exits. Here's an example:

Code Snippet
123456
import { console, exit, fetch, params } from 'sys:runtime/v1' import { fetchData } from 'sys:data_sources/v1' console.debug(params); exit(true, params)
Screenshot of the sample script.

Execute Script

To run a script, return to the Browse tab and find a visualization. Select the "…" button for the visualization, choose Execute Script..., select the desired script, and choose Execute.

From the menu, select Execute Script.

This action runs the script and logs the input parameters to the console, simplifying future executions.

Rerun Script

After running the script, revisit the Script section in the System Administration app. Select the script and choose Edit and Run. The previous script execution details, including Parameters, Result, and Log Messages, are displayed on the right.

To rerun the script, you can either repeat the Execute Script command from the visualization or copy the parameters from a previous run and paste them into the popup window after choosing the Run.

When executed, the script produces the same results as before. This process streamlines script modification and testing against the same visualization.

The Parameters popup, as described in the preceding text.

General Scripts

A primary use for General scripts is creating utility files containing helper functions. Here's an example of a utility script with a `callDestination` helper function:

Code Snippet
12345
// Utility script with a callDestination function export function callDestination(destinationName) { // Implementation to call a destination console.log('Calling destination: ' + destinationName); }
Screenshot of the general script code.

To use this function in a visualization script, add an import statement:

Code Snippet
1234
// Import the utility script import { callDestination } from 'usr:ipd_450_util' // Call the callDestination function const destResult = await callDestination("SOMEDESTINATION", "SUFFIX_URL_TO_API", "POST", {"SOME":"DATA"});

Once imported, the callDestination function can be called like any other function.

Errors

Errors are displayed in the Messages panel. For example, attempting to access a nonexistent destination triggers an error.

Screenshot of a sample error message.

Visualization API

The Visualization API can be accessed using the fetch command. To retrieve details about a visualization using its ID (passed in the params object), use the following code:

Code Snippet
1234567
// Accessing the Visualization API let url = `visualization:v1/visualizations/${params[0].id}`; console.debug(url); const response = await fetch(url, {method: 'GET'}) const responseJson = await response.json(); console.debug(`${JSON.stringify(responseJson)}`)

This provides access to scene IDs for each visualization version. Using the latest scene ID, you can make more API calls to retrieve the scene hierarchy, access and modify metadata, or change entire structures.

The Visualization API is called and results are displayed.

Summary

Let's Summarize What You've Learned:

  • SAP Integrated Product Development Visualization scripts allow you to automate tasks such as cleaning scenes and adding metadata.
  • Scripts can be triggered from a visualization or during import/publish processes.
  • The System Administration application is used to create and manage scripts.
  • The Visualization API can be accessed using the fetch command to retrieve and modify visualization data.

Further Reading

Configuring Scripts: https://help.sap.com/docs/PLM_EPD/1bfdb8b2f0264b66a818a2a889ee8c31/531f1bd7303e47a78e3c7f1425610a49.html