scripted_scalar_check

Short description

This example shows how to create a scalar check by script. A scalar check is the most basic check, as it assigns a scalar value to an element. Nearly all elements you can find in the software can be checked like this.

Note

A scripted check has a lot in common with the scripted actual elements. Therefore, the identical mechanisms and concepts will not be explained here. See How-to: Scripted actuals if you are not already familiar with the concept of scripted elements.

Highlights

First of all, we need to check if the element selected by the user by the DIALOG.slct_element widget is suitable for being checked with a scalar check. You can implement your own filter for that, but you can also use the API convenience function for that purpose:

DIALOG.slct_element.filter = gom.api.scripted_checks_util.is_scalar_checkable

As you can assign a scalar value to all common element types, this filter allows all element types available in the element explorer.

Furthermore, as described in the How-to: Scripted checks, the special parameters for scripted checks are also assigned in the dialog function. For ease of use, the respective dialog widgets are used, so we only need to assign the widgets’ values to the parameters array.

def dialog (context, params):
  # [...]
  params['tolerance']     = DIALOG.tolerances.value
  params['unit']          = DIALOG.unit.value
  params['abbreviation']  = 'ScrSca'

In the calculation function, there is not much calculation but just an exemplary assignment of scalar values to the result. For the scripted Scalar check, the result dictionary needs to contain "nominal" and "actual" members, as well as a reference to the element which is checked.

def calculation (context, params):
  # [...]
  for s in context.stages:
    actual_result  = 1.0
    nominal_result = 2.0
    
    context.result[s] = {"nominal" : nominal_result, 
              "actual" : actual_result, 
              "reference" : element }
  return True