ex12_volume_defects
This is an example for a scripted ‘volume defects’ element. Each defect is defined by a mesh. In this example, a single defect is created by setting the coordinates of four vertices from a dialog. The mesh triangles are hard-coded in the calculation()
function. The resulting element has the shape of a tetrahedron.
Note
The mesh triangles are defined by indices into the array of vertices. The vertices defining a triangle must be specified in counter-clockwise order (as viewed from outside).
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 v0 = (params['v0_x'], params['v0_y'], params['v0_z'])
7 v1 = (params['v1_x'], params['v1_y'], params['v1_z'])
8 v2 = (params['v2_x'], params['v2_y'], params['v2_z'])
9 v3 = (params['v3_x'], params['v3_y'], params['v3_z'])
10
11 # Calculating all available stages
12 for stage in context.stages:
13 # Access element properties with error handling
14 try:
15 context.result[stage] = {
16 'vertices': [np.array([v0, v1, v2, v3])],
17 # Note:
18 # Triangles are defined by indices into the array of vertices.
19 # The vertices defining a triangle must be specified in counter-clockwise
20 # order, otherwise the resulting surface would be inverted, i.e. invisible!
21 'triangles': [np.array([(0, 1, 2), (1, 0, 3), (0, 2, 3), (2, 1, 3)])]
22 }
23 context.data[stage] = {"ude_mykey": "Example 12"}
24 except Exception as error:
25 context.error[stage] = str(error)
26 else:
27 valid_results = True
28 return valid_results