Global Functions
Global functions are called with the prefix sim_server
AddPythonScript(script_name string, method_name string)
This function allows the user to add any scripts that are in the same folder as the calling script. A typical use would be to add user defined scripts in a Model.OnBegin type script so they can be scheduled by the ScheduleCustomEvent function. Note that the function does not define a script type so it will not work to add a specific type (such as Event or Rule type scripts).
Debug()
trace (level int, data string, filename string)
This function will write information to the <ModelName>_NetSimData folder if the level argument is less than or equal to the current trace level. You set the trace level using the Scripting Debug Level option on the General tab in Simulation options. The data must be in a string format. In Python 2.6, the str() function converts most items to string.
The filename is an optional argument. If no file is specified, the information is output to the scriptlog.txt file in the <ModelName>_NetSimData folder. If a filename is specified, output is written to the specified filename in the <ModelName>_NetSimData folder. The file is created if it does not already exist.
logerror(data string)
This function will write information to the error log and display it in the Error Log output table in Supply Chain Guru X. The information is prefixed with "Python:" followed by the data string.
CalculateDistance(<SiteLocation Object>, <SiteLocation Object>) as Real
This function calculates the distance between two locations.
CalculateFutureDemand(<CustomerProduct Object>, startTime real, endTime real) as Real
This function provides the total units of expected future demand for a customer product. Expected input is the customer product to review, the startTime as days from 'now' to start counting and endTime as the days from 'now' to stop calculation. In the example, after defining the customer product, the calculation is for demand between 7 ½ days from 'now' to 14 ½ days from 'now'.
CBoolean(string) as Boolean
This function converts the string "TRUE" or "FALSE" into a Boolean data type.
CDate(string) as Date
This function converts a string date into a Date data type. After converting to a Date type, you can use any functions available in Python library datetime.
CInteger(string) as Integer
This function converts a numeric string input into an Integer data type. The function only converts numbers such as 1, 10, and 100 and does not convert words such as one, ten or one hundred.
CReal(string) as Real
This function converts a numeric string input into a Real data type.
CreateOrder(product string, quantity real, destination name string) as Object
This function creates a new <Order Object> object for the destination for the quantity of product specified. The order is sourced using the normal sourcing rules already provided in the model for the specified product ordered by the destination name.
If the function succeeds, then the new <Order Object> object is returned. If the order cannot be sourced then a Null reference is returned. Otherwise an exception is raised.
CreateOrder(product string, quantity real, destination name string, source name string) as Object
This function creates a new <Order Object> object for the destination from the designated source for the quantity of product specified. Because the source is identified, this effectively becomes a pushed shipment.
If the function succeeds, then the new <Order Object> object is returned. If the order cannot be sourced then a Null reference is returned. Otherwise an exception is raised.
CreateProductionOrder(product string, quantity real, site name string) as Object
This function creates a new <Order Object> object that leads to production at the designated site for the quantity of product specified. For the function to be successful, the designated site should have a Make policy for the product.
If the function succeeds, then the new <Order Object> object is returned. If the order cannot be sourced then a Null reference is returned. Otherwise an exception is raised.
InvokeScript(script name string, scheduled time string, occurrences string, interval string) as Boolean
This function allows you to schedule another named script.
Scheduled time accepts date or date times as well as standard Supply Chain Guru X inputs ("1/15/2022", "1/15/2022 01:05:01", "14", "15 MIN", "2.3 DAY"). The default time interval is DAY.
Occurrences sets the number of times the script should repeat. If there is only one occurrence, enter "1". If you want the script to continue throughout the model, enter "INF".
Interval sets the interval between Occurrences if there are more than one occurrence. Interval accepts the standard Supply Chain Guru X inputs (i.e. "1 DAY", "5 SEC", "15 MIN", etc.). The default time interval is DAY.
If the script is scheduled, the function returns True.
IsNull(<object>) as Boolean
Returns TRUE if the object returns a NULL reference. Otherwise the function returns FALSE.
MoveIdleAssetUnit(<AssetUnit Object> , <Site Object>, travel time in days real) as Boolean
This function moves an idle asset unit from its current location to the designated site. If you provide travel time greater than 0, the designated travel time is used. Otherwise, if the travel time is equal to or less than 0, Supply Chain Guru X calculates a travel time based on calculated distance and asset speed.
Now() as Integer
This function returns the 'now' time of the model in seconds. Import the Python datetime library to perform standard date/time functions on this value.
NowAsString() as String
Returns the 'now' time of the model as a string. Note that there is no need to import the Python datetime library in this case.
ProcessQueuedLot(<WorkProcess Object> OR <WorkCenter Object>, <ProcessLot Object>) as Boolean
This function moves a lot queued at a process or work center. If the function succeeds, the lot is removed from the queue, moved to the next step and the function returns TRUE. This function is primarily used in conjunction with the custom Script types after the next step for a lot is defined.
ProcessQueuedOrder(<Site Object>, <Order Object>) as Boolean
This function moves an order queued at a site before processing for fulfillment. If the order is not queued at the site, the function returns FALSE. If the function succeeds, the order is removed from the queue, processed for fulfillment and the function returns TRUE. This function is primarily used in conjunction with the custom Script types.
ReleaseAllWorkResources(<Shipment Object>) as Boolean
If a shipment is utilizing resources (typically for loading or unloading), this function releases any active work resources. The function returns TRUE to indicate success.
ScheduleCustomEvent(script_name string, schedule_date string, (optional) args list) as Boolean
This function allows you to schedule the execution of any script identified in the Simulation Scripts menu. Time is entered as a Python datetime object in string format that sets an event trigger on the simulation calendar. (Optional) If any arguments are expected by the triggered script, you can pass them in a Python list.
SelectTransportationMode(<Lane Object>, <ShippingItem Object>, mode name string) as Boolean
Shipping items are assigned a mode using the lane's mode selection policy. If no mode is assigned, the shipping item is queued at the lane pending mode selection. Use this function to select a transportation mode for a queued shipping item. This function can also be used inside a custom Transportation Policy. If the shipping item is not queued at the lane or the chosen mode is not a valid mode, the function fails and returns FALSE. If the function succeeds, the shipping item is assigned to the mode, removed from the queue and the function returns TRUE.
SplitQueuedShippingItem(<ConsignmentList Object>, <ShippingItem Object>, split quantity real) as Object
This function splits a shipping item queued at a lane pending mode assignment. A new shipping item object is created and added to the queue. The quantity of the new item is set to the split quantity specified and the quantity of the original shipping item object will be adjusted accordingly. If the specified shipping item is not a part of the consignment list provided, the function will fail. Upon success, the function will return the new shipping item. This function is used primarily in conjunction with a custom Script types.
Last modified: Wednesday May 15, 2024