ex13_volume_region

Scripted volume region example

This is an example for a scripted ‘volume region’ element. The dialog allows to select a linked volume element and to set offset (in the global coordinate system) as well as the dimensions (in the voxel coordinate system) of the volume region. In this example, the volume region is shown in light green.

Caution

The voxel (measurement) coordinate system may differ from the CAD coordinate system.

Note

Please see offset_point_v2.md for a complete scripted elements example with detailed description.

Source code excerpt

 1def dialog(context, params):
 2    #[...]
 3
 4def calculation(context, params):
 5    valid_results = False
 6
 7    x0 = params['x0']
 8    y0 = params['y0']
 9    z0 = params['z0']
10
11    dx = int(params['dx'] / params['volume_ele'].voxel_size.x)
12    dy = int(params['dy'] / params['volume_ele'].voxel_size.y)
13    dz = int(params['dz'] / params['volume_ele'].voxel_size.z)
14
15    # Calculating all available stages
16    for stage in context.stages:
17        # Access element properties with error handling
18        try:
19            context.result[stage] = {
20                'volume_element': params['volume_ele'],
21                'offset': gom.Vec3d(x0, y0, z0),
22                'voxel_data': np.ones((dx, dy, dz), dtype=np.uint8)
23            }
24            context.data[stage] = {"ude_mykey": "Example 13"}
25        except Exception as error:
26            context.error[stage] = str(error)
27        else:
28            valid_results = True
29    return valid_results