Skip to content
On this page

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.

Max script

MaxScript
-- reset state of previously set parameters
    sgsdk_Reset()

    -- select objects in scene
    select $*

    -- create a reduction Pipeline using the sgsdk_CreatePipeline function
    reductionPipeline = sgsdk_CreatePipeline "ReductionPipeline"

    -- set the reduction Pipeline's triangle ratio to 50%
    sgsdk_SetSetting reductionPipeline "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio" 0.5

    -- execute Simplygon with the given Pipeline
    sgsdk_RunPipelineOnSelection reductionPipeline

    -- clear all Pipelines that resides in memory
    sgsdk_ClearPipelines()

Max scripting window (MaxScript)

Run Simplygon through MaxScript.

Python

python
from pymxs import runtime as rt

# reset state of previously set parameters
rt.sgsdk_Reset()

# select objects in scene
rt.select(rt.objects)

# create a reduction Pipeline using the sgsdk_CreatePipeline function
reductionPipeline = rt.sgsdk_CreatePipeline('ReductionPipeline')

# set the reduction Pipeline's triangle ratio to 50%
rt.sgsdk_SetSetting(reductionPipeline, 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio', 0.5)

# execute Simplygon with the given Pipeline
rt.sgsdk_RunPipelineOnSelection(reductionPipeline)

# clear all Pipelines that resides in memory
rt.sgsdk_ClearPipelines()

Max scripting window (Python)

Run Simplygon through Python-script.

Accessing Simplygon UI through UIAccessor

The Simplygon UI exposes a set of functions that can be accessed through script. 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:

FunctionArgumentDescription
LoadPipelineFromFilestring filePathLoads specified pipeline into Simplygon UI
SavePipelineToFilestring filePathSaves pipeline loaded in the Simplygon UI to specified file

Script examples:

MaxScript
-- create UIAccessor object
    ui = dotNetObject "SimplygonUI.UIAccessor"

    -- use UIAccessor to call a function
    bPipelineLoaded = ui.LoadPipelineFromFile "D:/Pipelines/ReductionPipeline.json"
    bPipelineSaved = ui.SavePipelineToFile "D:/Pipelines/ReductionPipeline_Copy.json"

```Py
from pymxs import runtime as rt

# create UIAccessor object
ui = rt.dotNetObject('SimplygonUI.UIAccessor')

# use UIAccessor to call a function
bPipelineLoaded = ui.LoadPipelineFromFile('D:/Pipelines/ReductionPipeline.json')
bPipelineSaved = ui.SavePipelineToFile('D:/Pipelines/ReductionPipeline_Copy.json')

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: