vcScript

vcScript allows you to publish and execute a Python script.

Inherits: vcBehaviour

Properties

Name Type Access Description
Application vcApplication R Gets the application object.
Component vcComponent R Gets the component of script.
IsRunning Boolean R Indicates if code of script is being executed.
Node vcNode R Gets the node containing script.
Script String RW Defines the executable Python code of script.
Simulation vcSimulation R Gets the simulation object.

Methods

Name Return Type Parameters Description
condition Boolean Function expression_function, [Real timeout] Delays the execution of script until a given function returns a True value or timeout period.

The first evaluation of the function is immediate, and then each subsequent test is triggered, for example, by signal connected to script. The default timeout period is zero.

Returns a True value if condition is True before timeout, otherwise returns a False value.

NOTE: implementation is different in vcPythonProcessHandler

convertToByteCode None None Converts the code of script to bytecode.

Generally, this method is used to encrypt the code of script.

delay None Real time Delays the execution of script for a given amount of time.
evaluateCondition None None Triggers the evaluation of an active condition() or triggerCondition() function in the script.
getApplication vcApplication None Returns the application object.
getComponent vcComponent None Returns the component of script.
getNode vcNode None Returns the node containing script.
getPythonDllPath String None Returns the Uri of Python DLL folder as a formatted string.
getSimulation vcSimulation None Returns the simulation object.
getTrigger vcBehaviour None Returns an object that acts as a trigger in script, for example a signal connected to script.

Generally, this method is called in a condition() or triggerCondition() expression to evaluate a trigger.

resumeRun None [Real timeout] Resumes the execution of OnRun, the main program of script, that was placed in suspended state.
suspendRun None None Suspends the execution of OnRun, the main program of script.
triggerCondition Boolean Function expression_function, [Real timeout] Delays the execution of script until a given function returns a True value or timeout period.

The evaluation of the function is triggered, for example, by signal connected to script. The default timeout period is zero.

Returns a True value if condition is True before timeout, otherwise returns a False value.

NOTE: implementation is different in vcPythonProcessHandler

Events

The following event handlers are functions that can be defined and used in a script. In most cases, you use the OnRun event to define the main program/loop of script which is executed while a simulation is running.

Name Parameters Description
OnAction vcAction action Triggered when an Action Container connected to script handles an action.
OnContinue None Triggered when a simulation resumes after being halted.
OnDestroy None Triggered when an object is destroyed, for example a node.
OnFinalize None Triggered when layout or component is being loaded in 3D world.

The event occurs, for example, when copying a component, or loading a layout of components. The event is triggered before the needed components are attached to the 3D world.

OnRebuild None Triggered when component geometry is rebuilt.
OnReset None Triggered when simulation is reset to its initial state and simulation clock is set at zero.
OnRun None Triggered at the start of a simulation and is used as the main function/loop of script.
OnSignal vcSignal signal Triggered when a signal connected to script signals its value.
OnSimulationUpdate Real time Triggered when simulation and scene are updated.
OnSimulationLevelChanged Enumerator

Triggered when the simulation level is changed.

See Component Constants for more information.

Refers to SimulationLevel Property in vcComponent.

OnStart None Triggered at the immediate start of simulation.
OnStop None Triggered when a simulation is halted.

Examples

Example. Use condition() and triggerCondition() methods

#A condition calls the function test_func() immediately w/o waiting for a trigger
#A triggerCondition calls the function when a trigger is received
#Use this script as an example for executing a condition and/or a triggerCondition
 
from vcScript import *
import vcMatrix
 
finalizing = True
comp = getComponent()
pathxx = comp.findBehaviour("One-WayPath__HIDE__")
pathxx.Enabled = True
preSensorSgnl = comp.findBehaviour("PreSignal")
postSensorSgnl = comp.findBehaviour("BooleanSignal")
 
 
def test_func():
  triggerer = getTrigger()
  print '-'*99 # print a line
  print '- triggerer:',triggerer
  print '- postSensorSgnl value:',postSensorSgnl.Value
  if triggerer == postSensorSgnl:
    if postSensorSgnl.Value == False:
      print 'TEST PASSED'
      return True # return true which makes condition test to pass
    else:
      print 'TEST FAILED because postSensorSgnl.Value is not False'
      return False # return false which makes condition test to fail
  else:
    print 'TEST FAILED because triggerer is not postSensorSgnl'
    return False # return false which makes condition test to fail
 
def OnRun():
  ## condition
  #condition(lambda: test_func() ) # case1
  
  ## triggerCondition
  #triggerCondition(lambda: test_func() ) # case2
  
  pathxx.Enabled = False  
  print '< test passed and path disabled >'
  print ''