# Getting started - Scripting

Simplygon will start the optimization once the sgsdk_RunPipelineOnSelection function is executed in combination with a Pipeline object or a Pipeline file-path.

To execute a script in Max we need to open up a new script window, go to Utility panel -> MaxScript -> New script. In the new window, go to language and select MaxScript or Python. Now, copy either the MaxScript or the Python script below into the new script window. To start the script, go to the Tools-menu and select Evaluate All or simply press press CTRL + E. The optimized result will be returned to Max automatically once the processing has completed. If an error occurred it will show up in the MaxScript Listener.

    # Accessing Simplygon UI through UIAccessor

    Later versions of Simplygon 9 enable script access to a set of functions provided by the Simplygon UI. These functions are revealed through our proprietary UIAccessor interface and can be accessed through MaxScript and Python using dotnetobject (these are not exposed as regular script functions).

    Function table:

    Function Argument Description
    LoadPipelineFromFile string filePath Loads specified pipeline into Simplygon UI
    SavePipelineToFile string filePath Saves pipeline loaded in the Simplygon UI to specified file

    Script examples:

      IMPORTANT NOTE - Scripting and UI modules

      The Simplygon Max scripting- and UI modules are separate plug-ins. The scripting module encapsulates the import and export logic as well as scripting capabilities. The UI module is a separate layer that communicates with the scripting layer. Communication between these modules require both modules to be loaded.

      Dependencies:

      • The scripting module can be used without other dependencies (through script functions)
      • The scripting module with calls to UIAccessor requires the UI module
      • The UI module must be used in combination with the scripting module

      # Next steps

      Get to know how to use the Simplygon Max plug-in: