Skip to main content
Version: 8.1

system.sfc.getVariables

This function is used in Python Scripting.

Description​

Get the variables in a chart instance's scope. Commonly used to check the value of a Chart Parameter, or determine how long the chart has been running for.

Client Permission Restrictions​

This scripting function has no Client Permission restrictions.

Syntax​

system.sfc.getVariables(instanceId)

Parameters​

TypeParameterDescription
StringinstanceIdThe instance identifier of the chart.

Returns​

PyChartScope - Effectively a Python dictionary of variables, Step scopes for active steps are found under the "activeSteps" key. In addition to those keys, Chart Parameters will also be included in the dictionary as keys. More information on this object can be found in our Javadocs.

Scope​

Gateway, Vision Client, Perspective Session

Keys in the PyChartScope​

The following keys are in the PyChartScope object.

KeyDescriptionValue Type
parentIf the chart is enclosed in another chart, this Dictionary returns information on the parent chart. Otherwise, returns None. The keys returned by the parent dictionary is identical to calling system.sec.getVariables() directly on an instance of the parent chart.Dictionary
instanceIdThe instance identifier of the chart.Unicode
startTimeA date object representing when the chart started.Date
runningTimeA long representing the amount of time the chart has been running.Long
chartPathA path (as shown in the Project Browser) leading to the chart.String
activeStepsA dictionary of all active steps in the chart. The keys in this dictionary are UUID values representing the individual steps. The value of each key, is another dictionary, with the following keys:
  • id: The step's ID.
  • name: The name of the active step.
  • runningTime: The amount of time (as a long) that the step has been active.
  • Dictionary
    Chart ParamsIn addition to the built-in keys mentioned above, each configured chart parameter will be represented as a key:value pair in the PyChartScope.Varies, based on the value of the chart parameter

    Code Examples​

    Example #1 - Show Chart Data to the User
    # This example will show the chart path and start time of a single chart in a messageBox.
    # We can make use of the SFC Monitor component to give the users the ability to pick a single running chart

    # Fetch the ID of a running chart. In this case, we used the Instance ID property on a SFC Monitor component
    id = event.source.parent.getComponent('SFC Monitor').instanceId

    # Retrieve the variables from the chart
    chartVars = system.sfc.getVariables(id)

    # Show the path and starttime of the chart in a messageBox
    system.gui.messageBox("Chart Path: %s has been running since %s" % (chartVars["chartPath"], chartVars["startTime"]))
    Example #2 - Print the Name and Running Time for All Active Steps
    # Get the name and running time for each step in each running chart.

    # Return data for running instances at a specific path. "folder/myChart" should be replaced with a valid path.
    data = system.sfc.getRunningCharts("folder/myChart")

    # Initialize a list to contain all instance Ids
    chartIds = []
    # Iterate through each chart, and fetch the instanceId
    for row in range(data.rowCount):
    chartIds.append(data.getValueAt(row, "instanceId"))

    # Now that we have the ID for all active charts, pull variables out of each.
    for id in chartIds:
    chartVars = system.sfc.getVariables(id)

    # Prints the chart instance ID. In the context of this example, this line is used to delineate
    # between all our print statements.
    print "Details for Chart ID: %s" % chartVars["instanceId"]


    # Create a variable that references the activeSteps dictionary. Creating a variable here
    # makes the syntax below a bit cleaner.
    allSteps = chartVars["activeSteps"]


    # Iterate through the active steps. A "step" represents the key of each step
    # in the activeSteps ("allSteps") dictionary
    for step in allSteps:

    # store the value of the current step dictionary in a variable. This is simply to keep
    # the syntax below clean. Equivalent to: chartVars["activeSteps"][step]
    currStep = allSteps[step]

    # Print out the name and running time of each step.
    print "Step %s has been running for %i seconds" % (currStep['name'], currStep['runningTime'])