Créez une dérivation spécifique personnalisée
Introduction
Il y a un énorme avantage de construire un traducteur dérivé. Il utilisera le traducteur parent complet (de base), à l’exception que du nouveau contenu sera ajouté ici, et les fonctions existantes redéfinies supplanteront celles de base. Dans ce cas, le traducteur de base reste intact. Mais aussi que les changements (majeurs) apportés au traducteur de base sont appliqués automatiquement à tout traducteur dérivé.
Étapes
1. Traducteur dérivé
In Visual Studio Code open CustomTranslator.py from the example plugin, that has been implemented during the preparation.
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.

For this example the hierarchic structure looks like:

Furthermore, it is important to add the following line at the beginning of each downloader.
![]()
These lines will add the current path to the Python path. This is important for using further deviations.
2. Fonctions de dérogation
In the controller of the workcell, change the used translator to CustomTranslator.py.

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

In CustomTranslator.py we override the function with a custom implementation. Add the following lines to the OperationStart() function.
# get log operator
logger = operator.GetLogOperator()
logger.LogInfo("Default OperationStart called")
# get the operation name
operationName = operation.GetName()
# iterate through all operation attributes
self.ProgramContent.append('Operation name: %s' % operationName)
Overriding the function means that the previous output of the operations attributes in HelloWorld.py will no longer occur.
Output of HelloWorld.py:
![]()
Output of CustomTranslator.py:
![]()
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)
Output:
![]()
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.

Output:
![]()
3. Sortie d’événements
Dans votre cellule de travail, ajoutez un événement Texte à un élément de trajectoire d’outil en ouvrant le panneau d’événements.

Implement the text event output. Add the following lines to the HandleEvent() function.
# get all attributes
attributes = event.GetAttributes()
# initialize variables
text = ''
isComment = True
# iterate through attributes
for attribute in attributes:
# get text
if attribute.GetName() == 'Text':
text = attribute.GetValue()
# get flag is text is a comment (True) or command (False)
elif attribute.GetName() == 'IsComment':
isComment = attribute.GetValue()
# check if comment
if isComment:
# create string and add it to source string array
self.ProgramContent.append('Comment: %s' % text)
else:
self.ProgramContent.append('Command: %s' % text)
Output:
![]()