How to create a statement which type of 'TestProcess'

About the Program Edit Panel.
I can get the executor for getting all statements, but I can’t find the method to create a statement which type of ‘TestProcess’.
And I can’t get the selected statement of Program Edit Panel or its index, I want to create a new statement behind the selected statement and bind it to a created python scrip.

As the picture shows, I want to realize that when I selected the second statement and click a button, it will create a ‘TestProcess’ statement at the third index.

Create 'Test Process' Statement

I have only the Professional version. What do you mean with TestProcess?
Do you want to react on a input? If this is the case, use the Wait statement.

Another component or a PLC can set the signal.

Ok, you came from here: Frame array and offset
I’m sorry, I can’t find the .NET component of RaycastVolumeSensor. In Python it’s just the attribute TestParent, TestSiblings and SampleTime if UseSampling is True.

(cool, this forum supports back-refrerences to topics)

That statement and its UI button have probably been created dynamically through Python or .NET API. Could be an add-on or possibly even some script in a layout file that adds the statement.

Thanks for your reply, it is a python scrip.
Now I want to realize that when I selected the second statement and click a button, it will create a ‘TestProcess’ statement at the third index.I can’t find any api or event for the selected statement, even in .NET event or ISelectionManagement.

from vcApplication import *

from vcCommand import *

from vcHelpers.Selection import *

from vcHelpers.Application import *

import vcMatrix

app = getApplication()

cmd = getCommand()

comp = None

executor = None

controller = None

cmd_manager = findCommand(‘netCommand’)

#================ ON CLICK ================

def OnButtonClick():

#---------------- ROBOT -----------------

global executor, controller, comp

if app.TeachContext != None and \

        app.TeachContext.ActiveRobot != None:

    comp = app.TeachContext.ActiveRobot

    controllers = comp.getBehavioursByType('rSimRobotController')

    executors = comp.getBehavioursByType('rRobotExecutor')

    if len(controllers):

        controller = controllers[0]

    if len(executors):

        executor = executors[0]


if comp == None or executor == None or controller == None:

    print 'Please select a robot.'


#---------------- PROCESS HANDLER -----------------

process_handler = comp.getBehaviour('TestProcessHandler')

if process_handler != None:

    if process_handler.Script != GET_PROCESS_HANDLER_SCRIPT() :

        process_handler.Process = 'Test'

        process_handler.Script = GET_PROCESS_HANDLER_SCRIPT()

        print 'Updated "TestProcessHandler" behavior.'

if process_handler == None:

    process_handler = comp.createBehaviour('rPythonProcessHandler', 'TestProcessHandler')

    process_handler.Process = 'Test'

    process_handler.Script = GET_PROCESS_HANDLER_SCRIPT()

    print 'Created "TestProcessHandler" behavior.'

# ---------------- CREATE STATEMENT -------------------

#target = controller.createTarget()

stat = executor.Program.MainRoutine.addStatement(VC_STATEMENT_PROCESS)

stat.Process = process_handler

#pos = stat.createPosition("PTEST")

#stat.Base = target.BaseName

#stat.Tool = target.ToolName

#pos.PositionInReference = target.Target

#================ PROCESS HANDLER SCRIPT ================


return """

from vcRslProcessHandler import *

from vcBehaviour import *

import vcMatrix

app = getApplication()

comp = getComponent()

#---------------- SETUP NEW STATEMENT -----------------

def OnStatementAdd(stat):


#---------------- UNSETUP STATEMENT -----------------

def OnStatementRemove(stat):


#---------------- STATEMENT EXECUTION -----------------

def OnStatementExecute(executor, stat):

controller = executor.Controller


target = controller.createTarget()




if stat.Base == None:

    target.BaseName = ""


    target.BaseName = stat.Base.Name

if stat.Tool == None:

    target.ToolName = ""


    target.ToolName = stat.Tool.Name


positions = stat.Positions

if len(positions) > 0:

    target.Target = positions[0].PositionInReference

print "Testing, testing..."



#---------------- INIT -----------------


Ok, now I understand your problem is how to know the currently selected statement.

The currently selected robot program statement information is available from ITeachContext in the .NET API.
You can do something like this:

var teachContext = IoC.Get<ITeachContext>();
teachContext.ActiveScope.AddStatement<IDelayStatement>(teachContext.ActiveStatementIndex + 1);

Similarly in the Python API the selected statement information is available from vcTeachContext properties ActiveScope and ActiveStatementIndex. See the example code in the VC help file page for vcTeachContext.

1 Like

Thanks, it works!
I can use ‘IoC.Get().ActiveScope.AddStatement(IoC.Get().ActiveStatementIndex + 1);’ add any existed statement by changing the content of ‘<>’, but I want to create a blank panel and add properties by myself. In general, I want to design a new panel by adding a blank panel or create new model as interface. Now I do it by create a ‘ISetPropertyStatement’ and delete existed property to create a blank panel, have any way to optimize it?

I don’t know about Python but with .NET you can create your own statement type by deriving from the CustomStatementBase class.

See this thread.

1 Like

It’s cool!
I think the example it’s not completely correct, it should use the Method ‘Execute’ of the new class instead of calling event. Now I want to initial some properties in the class instead of calling ‘AddProperty’, how to code it?

public class IVisibleControllerStatement : CustomStatementBase
public string ComponentList { get; set; }//not create
public bool Visible { get; set; }//not create
public IVisibleControllerStatement()


    public override void Execute(IExecutor statement)
        var componentArray = Statement.GetProperty("ComponentList").Value.ToString().Split(',');
        foreach (var componentName in componentArray)
            var componentModel = IoC.Get<IApplication>().World.Components.FirstOrDefault(x => x.Name == componentName);
            if (componentModel != null)
                componentModel.IsVisible = Convert.ToBoolean(Statement.GetProperty("Visible").Value.ToString());

    public override void ExecuteImmediate(IExecutor executor)


I just can create by coding:
statement.CreateProperty(typeof(string), PropertyConstraintType.AllValuesAllowed, “ComponentList”);
statement.CreateProperty(typeof(bool), PropertyConstraintType.AllValuesAllowed, “Visible”);

        statement.Name += "ForVisibleChanged";
        statement.GetProperty("ComponentList").Value = GetSelectedComponentArray("Normal");
        statement.GetProperty("Visible").Value = isVisible;

Internally VC uses “property objects” that in the .NET API appear as implementations of the IProperty interface. These are completely separate from your C# class member properties, so you’ll need to use CreateProperty in your custom statement constructor and store the returned IProperty objects in some class members for easy access.

If you then want to have class member properties for convenience, you need to create property getter and setter code to read / write the IProperty.Value

Also don’t name a class with a name starting with “I”. Its a common best practice to only name C# interfaces starting with I. (I stands for Interface)

1 Like

I had tried.
Put the ‘Create’ code to the constructor, it doesn’t intialize totally which lead to Statement is null and even can’t set the Name of the class.
Put to the override 'Initialize ', it never triggers.
I can’t find more suitable method.

And I want to set the statement icon in Program Edit Pannel(also Name).
set Program Edit Name and icon