Python scripting - Technology callbacks

PostTechUpdate

 

The callback PostTechUpdate(CENPyOlpTech_UpdateOperator) is called from the kernel when a technology update should be processed.

When loading the project file, the current version of the technology python script, defined in the same script by the GetPythonTechnologyVersion() parameter, is compared to the technology python script, that was saved during the last E2 session. The Update callback is called only when the current version of the technology python script is higher than the previous script version. The minimum and default GetPythonTechnologyVersion() script version parameter is 0.

 

It can be used to:

- get attribute values

- set attribute values

- create new attributes

- output to the log

- access OlpController

- access program components: OlpProgram, OlpOperationGroup, OlpOperation, OlpEvent, OlpEventRule

- access OlpTech_RuleUpdateOperator, OlpWM_RuleUpdateOperator

 

The callback may return a boolean value. There is no need to return False, because the default value is anyway False:

- True: if it is necessary to perform a full program recompute after the callback ends

- False: otherwise

 

The callback is defined in the %TechnologyName%.py file that is located in the scripts folder of the plugin.

 

PostTechUpdate

 

[Example]

 

def GetPythonTechnologyVersion():

   return 1

 

# PostTechUpdate callback executes only if the current GetPythonTechnologyVersion() version is higher than the previously saved script version

def PostTechUpdate(Operator):

   logging = Operator.GetLoggerOperator()

   logging.LogInfo('####################################################')

   logging.LogDebug("(Debug) Post tech update started.")

   

   # Test GetLastSavedPythonTechnologyVersion()

   lastVersion = Operator.GetLastSavedPythonTechnologyVersion()

   currentVersion = GetPythonTechnologyVersion()

   logging.LogInfo('Last script version: ' + str(lastVersion) + '. Current script version: ' + str(currentVersion))

   

   # Test GetOlpProgram() and GetChildComponents()

   program = Operator.GetOlpProgram()

   attribGetter = Operator.GetAttribGetter(program)

   attribSetter = Operator.GetAttribSetter(program)

   

   # Test GetChildComponents()

   componentsList = program.GetChildComponents()

   logging.LogInfo("Total number of components: " + str(len(componentsList)))

   for component in componentsList:

      # Test GetType(), GetParentComponent() and GetCreatorName()

      componentType = component.GetType()

      parentComponent = component.GetParentComponent()

      componentCreatorName = component.GetCreatorName()

      logging.LogInfo("Component creator name: " + str(componentCreatorName))

      if componentType is OLPPROGRAMCOMPONENTTYPE_PROGRAM:

         logging.LogInfo("Component type: PROGRAM")

      if componentType is OLPPROGRAMCOMPONENTTYPE_OPERATIONGROUP:

         logging.LogInfo("Component type: OPERATIONGROUP")

         # Test GetAttribGetter and GetAttribSetter

         attribGetter = Operator.GetAttribGetter(component)

         attribSetter = Operator.GetAttribSetter(component)

         materialIndex = attribGetter.GetEnumIndex(SW_MATERIAL)

         if materialIndex == 0:

            attribSetter.SetBool('SW_ROTATE_WW_FORCE_CONTROL', False)

            logging.LogInfo("Material index: 0")

         if materialIndex == 1:

            attribSetter.SetBool('SW_ROTATE_WW_FORCE_CONTROL', True)

            logging.LogInfo("Material Index is 1")

         # Test GetAttribCreator() and RemoveAttribute()

         attribCreator = Operator.GetAttribCreator(component)

         att = attribCreator.AddString("TestAttrib", '0', OPERATION_GROUP_ATTRIBUTE | USER_ATTRIBUTE, "TestAttrib")

         logging.LogInfo("TestAttrib was created")

         Operator.RemoveAttribute(component, "TestAttrib")

         logging.LogInfo("TestAttrib was removed")

      if componentType is OLPPROGRAMCOMPONENTTYPE_OPERATION:

         logging.LogInfo("Component type: OPERATION")

      if componentType is OLPPROGRAMCOMPONENTTYPE_EVENT:

         logging.LogInfo("Component type: EVENT")

      if componentType is OLPPROGRAMCOMPONENTTYPE_EVENTRULE:

         logging.LogInfo("Component type: EVENTRULE")

         techEventRule = Operator.GetTechEventRuleUpdateOperator(component)

         if techEventRule is not None:

            ruleName = techEventRule.GetRuleName()

            logging.LogInfo("TECH rule name: " + str(ruleName))

            if ruleName == "ApproachRule":

               techEventRule.SetActiveEvent("OnePointApproach")

               logging.LogInfo("TECH active event was set to name: OnePointApproach")

            activeEventName = techEventRule.GetActiveEventName()

            logging.LogInfo("TECH active event name: " + str(activeEventName))

         wmEventRule = Operator.GetWmEventRuleUpdateOperator(component)

         if wmEventRule is not None:

            wmRuleName = wmEventRule.GetRuleName()

            logging.LogInfo("WM rule name: " + str(wmRuleName))

            if wmRuleName == "ApproachRule":

               wmEventRule.SetActiveEvent("OnePointApproach")

               logging.LogInfo("WM active event was set to name: OnePointApproach")

            wmActiveEventName = wmEventRule.GetActiveEventName()

            logging.LogInfo("WM active event name: " + str(wmActiveEventName))

 

   # Test GetController()

   olpController = Operator.GetController()

   toolIndex = olpController.GetActiveToolFrameIndex()

   baseIndex = olpController.GetActiveBaseFrameIndex()

   logging.LogInfo("Controller active tool index: " + str(toolIndex) + "; base index: " + str(baseIndex))

   

   # Set to True when a complete recompute is required

   completeRecomputeNeeded = True

   

   logging.LogDebug("(Debug) Post tech update ended.")

   logging.LogInfo('####################################################')

   return completeRecomputeNeeded

   

   # PostTechUpdate END

 


PostTechUpdate_Ex

 



Previous
Page précédente
Chapter
Page principale du chapitre
Next
Page suivante