Python scripting - Technology callbacks

PostTechInitAttributes

Previous  Chapter  Next

 

The callback PostTechInitAttributes(CENPyOlpTech_AttribInitOperator) is called just after the kernel initializes the technology attributes.

 

It can be used to:

- initialize attributes

- get attribute values

- set attribute values

- access OlpController

- output to the log

 

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

 

PostTechInitAttributes

 

 

[Example]

 

def PostTechInitAttributes(techAttribInitOperator):

 

# Create attributes

   attribCreator = techAttribInitOperator.GetAttribCreator()   # get object of CENPyOlpAttribCreator class

   attribCreator.AddInteger('MyIntAttribute', 0, -100, 0, USER_ATTRIBUTE | PROCESS_ATTRIBUTE | GLOBAL_ATTRIBUTE, 'MyIntAttribute')

   attribCreator.AddDouble('MyDoubleAttribute', 55.5, 0, 100, 0.5, USER_ATTRIBUTE | PROCESS_ATTRIBUTE | GLOBAL_ATTRIBUTE, ATTRIB_STANDARD, 'MyDoubleAttribute')

   attribCreator.AddString('MyStringAttribute', 'Hello World', USER_ATTRIBUTE | PROCESS_ATTRIBUTE | GLOBAL_ATTRIBUTE, 'MyStringAttribute')

   attribCreator.AddBool('MyBoolAttribute', True, USER_ATTRIBUTE | PROCESS_ATTRIBUTE | GLOBAL_ATTRIBUTE, 'MyBoolAttribute') 

   myLiterals = ["earth", "revolves", "around"]   # list of three literals

   myLiterals.insert(0,"The")                     # insert a new literal at first list position

   myLiterals.append("sun")                       # append a new literal at last list position

   attribCreator.AddEnum('MyEnumAttribute', myLiterals, 'earth', USER_ATTRIBUTE | PROCESS_ATTRIBUTE | GLOBAL_ATTRIBUTE, 'MyEnumAttribute')    

 

# Get values from attributes

   attribGetter = techAttribInitOperator.GetAttribGetter()

   valOfMyIntAttrib = attribGetter.GetInteger('MyIntAttribute')

   valOfMyDoubleAttrib = attribGetter.GetDouble('MyDoubleAttribute')   

   valOfMyStrAttrib = attribGetter.GetString('MyStringAttribute')

   valOfMyBoolAttrib = attribGetter.GetBool('MyBoolAttribute')

   indexOfMyEnumAttrib = attribGetter.GetEnumIndex('MyEnumAttribute')

 

# Set values to the attributes

   attribSetter = techAttribInitOperator.GetAttribSetter()

   attribSetter.SetInteger('MyIntAttribute', 15)

   attribSetter.SetDouble('MyDoubleAttribute', 15.8)

   attribSetter.SetString('MyStringAttribute', 'This is new string')

   attribSetter.SetBool('MyBoolAttribute', False)

   attribSetter.SetEnumIndex('MyEnumAttribute', 4)   

   

# Output attribute value to the log

   logOperator = techAttribInitOperator.GetLoggerOperator()

   logOperator.LogDebug('indexOfMyEnumAttrib = ' + str(indexOfMyEnumAttrib))

 

# Create system attributes  

   sysAttribCreator = attribCreator.GetSystemAttribCreator()

   min_radius = sysAttribCreator.AddMinRadius(0.01, USER_ATTRIBUTE | PROCESS_ATTRIBUTE | GLOBAL_ATTRIBUTE | OPERATION_ATTRIBUTE)

   max_radius = sysAttribCreator.AddMaxRadius(9.9, USER_ATTRIBUTE | PROCESS_ATTRIBUTE | GLOBAL_ATTRIBUTE | OPERATION_ATTRIBUTE)

 

 

As a result, new attributes appear on the user interface:

 

CENPyOlpSystemAttribCreator_Result

 

 


 

PostTechInitAttributes_Ex

 


Previous
Previous page
Chapter
Chapter page
Next
Next page