Create a translator

Create a custom specific derivation

Previous  Chapter  Next

 

Introduction


It has a huge advantage to build a derived translator. It will use the complete (base) parent translator with the only exception that new content will be added here and redefined existing functions will override the base ones. In this case the base translator remains intact. But also that (major) changes made to the base translator are being applied automatically to any derived translator.



Steps


1

Derived translator

1.1

In Visual Studio Code open the CustomTranslator.py from the example plugin, that has been implemented during the preparation.

1.2

At the beginning is again the class definition of the translator. Since we want to derive from HelloWorld, we must specify it inside the brackets.

 

Translator_CreateDerived_1

 

For this example the hierarchic structure looks like:

 

Translator_CreateDerived_2

1.3

Furthermore, it is important to add the following line at the beginning of each downloader.

 

Translator_CreateDerived_3

 

These lines will add the current path to the Python path. This is important for using further deviations.

 

2

Override functions

2.1

In the controller of the workcell, change the used translator to CustomTranslator.py.

 

Translator_CreateDerived_4

2.2

In the parent class HelloWorld.py we output all attributes with the property PROCESS_ATTRIBUTE.

 

Translator_CreateDerived_5

 

In CustomTranslator.py we override the function with an custom implementation.

Add the following lines to the OperationStart() function.

 

 

Translator_CreateDerived_6

 

Overriding the function means that the previous output of the operations attributes in HelloWorld.py will no longer occur.

 

Output of HelloWorld.py

Translator_CreateDerived_7

 

Output of CustomTranslator.py

Translator_CreateDerived_8

2.3

However, it is also possible to call the OperationStart() function of the parent class at the end.

Add the following line to the function.

 

    super().OperationStart(operator, operation)

 

Translator_CreateDerived_9

 

Output:

Translator_CreateDerived_10

2.4

This also allows you to decide whether the parent function should be called at the beginning or the end.

Call the OperationStart() implementation of the parent class at the start.

Remove the previously added line at the end and place it at the beginning, according the picture below.

 

Translator_CreateDerived_11

 

Output:

Translator_CreateDerived_12


3

Event output

3.1

In your workcell, add a Text event to a toolpath element by opening the event panel.

 

Translator_CreateDerived_13

3.2

Implement the text event output.

Add the following lines to the HandleEvent() function.

 

 

Translator_CreateDerived_14

 

Output

Translator_CreateDerived_15


Previous
Previous page
Chapter
Chapter page
Next
Next page