Introduction to Python scripting

You can interact with parts of the simulation object model, policies and events and manipulate them through Python®. Review the Generic event hierarchy to gain a high-level overview of the potential interaction points within Supply Chain Guru X simulation. You will find additional detail about the actual script types, their outputs and expected return values in the Script types section. The Model object tree provides a high-level look at some of the main relationships between objects. More detail including the individual attributes, attribute data types and whether attributes are settable is available in the Model object dictionary. This document describes the parts available to Python and how to interact with simulation but does not cover Python documentation.

You can use one of a number of publicly available Python script editors to develop your scripts.

Python script import

You can set up a Python file as a script for use with Simulation using the Simulation Scripts tool.

Python script editors

There are a number of python editors available for use in editing your Simulation scripts. Coupa recommends the following editors:

PyCharm Community Edition:

https://www.jetbrains.com/pycharm/download/#section=windows

PyDev:

http://www.pydev.org

This editor is a plug-in for Eclipse (https://eclipse.org).

Python scripts and SupplyChainGuru.com

At this time, Python scripts are not supported when uploading to or solving on the Cloud.

Notation

Data types are in italics.

Objects are enclosed in brackets <...>.

Custom attributes

Each object in the object model accepts custom attributes. Custom attributes can be of any Python data type. This functionality allows you to add integer, string, float, and other data type attributes to any object. Because any Python data type is allowed, you can also add lists, tuples or arrays to any object. For example, you can attach a transportation cost grid with weight bands in columns and distance bands in rows to the Model object, Lane object or TransportationMode object. This grid will be available to calculate a rate based on a shipment's weight and lane distance.

Methods

<object>.setcustomattribute(attributename as string, attributedata as Python type)

Sets the custom attribute named 'attributename'

<object>.getcustomattribute(attributename as string)

Returns the value of the custom attribute named 'attributename'

Last modified: Wednesday May 15, 2024

Is this useful?