diff --git a/doc/python_examples/scripted_actuals/offset_point_simple.md b/doc/python_examples/scripted_actuals/offset_point_simple.md deleted file mode 100644 index 79e6acf2c5..0000000000 --- a/doc/python_examples/scripted_actuals/offset_point_simple.md +++ /dev/null @@ -1,12 +0,0 @@ -# offset_point_simple - -![](../../howtos/scripted_elements/assets/scripted_actual_explorer.jpg) - -## Short description - -```{note} -This is a basic example meant to introduce you to the concept of scripted actual elements. Therefore, head over to the [How-to: Scripted actuals](../../howtos/scripted_elements/scripted_actuals.md) for the documentation of this example. -``` -## Related - -* [offset_point_v2](offset_point_v2.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/offset_point_v2.jpg b/doc/python_examples/scripted_actuals/offset_point_v2.jpg deleted file mode 100644 index e185df417b..0000000000 Binary files a/doc/python_examples/scripted_actuals/offset_point_v2.jpg and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/offset_point_v2.md b/doc/python_examples/scripted_actuals/offset_point_v2.md deleted file mode 100644 index 48a335a74d..0000000000 --- a/doc/python_examples/scripted_actuals/offset_point_v2.md +++ /dev/null @@ -1,127 +0,0 @@ -# offset_point_v2 (Includes preview calculation) - -![](offset_point_v2.jpg) -## Short description - -This example is an extension of the `offset_point_simple` example, which has been discussed in the general [How-to: Scripted actuals](../../howtos/scripted_elements/scripted_actuals.md#example-simple-offset-point). -It shows how to enhance user experience using preview calculation and error handling. - -## Highlights - -### Preview calculation - -From many of the built-in commands of ZEISS INSPECT, you know the calculation of a preview element during the creation dialog. This means, you can already see the calculation result in the 3D view, while tweaking some parameters in the dialog. - -To achieve this behaviour in a scripted element, you need to set up an event handler for the dialog (see also: [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md)). - - -```{code-block} python ---- -linenos: ---- -def dialog_event_handler (widget): - # No treatment of system events - if str(widget) == 'system': - return - # If preview calculation returned with error - if str(widget) == 'error': - DIALOG.control.status = context.error - return - # If preview calculation was successful - if str(widget) == 'calculated': - DIALOG.control.status = '' - DIALOG.control.ok.enabled = True - return - - # All other changes in the dialog --> calculate preview - params['x'] = DIALOG.i_x.value; - params['y'] = DIALOG.i_y.value; - params['z'] = DIALOG.i_z.value; - params['base'] = DIALOG.point.value - context.name = DIALOG.name.value - DIALOG.control.ok.enabled = False - context.calc(params=params, dialog=DIALOG) - -DIALOG.handler = dialog_event_handler -``` - -The event handler function is to be defined taking one argument. This argument will be a handle to the cause (the event) triggering the handler. This can be a string message or a handle to a specific widget of the dialog. We'll come back to this in a second - -The handler function shown above basically reads the current set of parameters from the `DIALOG` to the `params` array (lines 16-19). In this case, the offset values and base point. Then, the preview calculation is started using the special functional `context.calc`, which is a function handle taking the set of `params` and a reference to the dialog triggering the preview (line 22). - - -```{attention} -Only call `context.calc(...)` from a script dialog's *event handler* function, **NOT** from the scripted element's `dialog` function itself. -``` - -The handler is applied to the dialog in the `dialog` function of the scripted element, just before the dialog is shown to the user (line 23). - -### Status and error handling - -Using the dialog's event handler, we can also make the dialog responsive to successful or failed preview calculations. Therefore, the `DIALOG.control.ok.enabled` can be used to control the enabledness of the dialog's OK button. - -In line 21, the OK button is disabled before preview calculation is started. - -Furthermore, the scripted element framework provides two special event triggers: `error` and `calculated`, which are sent on failing/success of the `calculation` function to the dialog referenced in the `context.calc` call. - -In this case, we set a potential error message of a failed calcualtion to the dialogs error indicator (line 7), or enable the OK button and reset the error indicator in case of a successful calculation (lines 11-12). - - -### Stageful `calculation` and error handling - -Above, we discussed changes applied to the scripted element's `dialog` function. Now, let's take a look at the `calculation` function. - -```{code-block} python ---- -linenos: ---- -def calculation(context, params): - valid_results=False - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - base = params['base'].in_stage[stage].center_coordinate - context.result[stage] = (base.x + params['x'], base.y + params['y'], base.z + params['z']) - context.data[stage] = { "ude_mykey" : 123456 } - except Exception as error: - context.error[stage] = str(error) - else: - valid_results=True - return valid_results -``` - -The first noticeable difference to the *offset_point_simple* example is the calculation over all *stages* of the project, whose indices can be obtained using `context.stages` (line 4). - -```{seealso} -If you are not familiar with the concept of *stages*, get an impression in our [Starter Training](https://training.gom.com/course/277348/module/788965). -``` - -Second, the [access of element properties](../../howtos/python_api_introduction/python_api_introduction.md#access-element-properties) is also respecting the current stage using the `.in_stage` mechanism (line 7). - -Third, you can see that the calculation is surrounded by a `try/except` block that catches potential errors and sets arising error messages to `context.error`. This examples catches all exceptions in a very basic way. In a real-world application, you should distinguish several types of exceptions you'd expect and set meaningful error messages. The `context.error` message is then handled in the dialog as discussed above (see [Status and error handling](#status-and-error-handling)). - -### Storing generic element data - -You can observe an assignment to the `context.data` member (line 9). If you assign a dictionary (map) to this data structure, you can save *user-defined tokens* to the scripted element. These are key/value pairs that can hold generic information you might to retrieve in consecutive scripts or checks that reference the created scripted element. - -```{note} -Keys of *user-defined tokens* need to start with `ude_`. For more information, see the [Scripted elements API documentation](../../python_api/scripted_elements_api.md). -``` - -After element creation of such an offset point with name "Offset point 1", you could access this data again like: -```python -import gom - -print (gom.app.project.actual_elements['Offset point 1'].ude_mykey) -``` -Output: -``` -> 123456 -``` - - -## Related - -* [Example: offset_point_simple](offset_point_simple.md) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_circle.md b/doc/python_examples/scripted_actuals/scripted_actual_circle.md deleted file mode 100644 index 2d5b418b08..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_circle.md +++ /dev/null @@ -1,44 +0,0 @@ -# scripted_actual_circle - -![Scripted circle element example](scripted_actual_circle.png) - -This is an example for a scripted 'circle' element. - -```{note} -Please see [offset_point_v2.md](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - - -## Source code excerpt - -```{code-block} python ---- -linenos: ---- -def dialog(context, params): - #[...] - -def calculation(context, params): - valid_results = False - - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - context.result[stage] = { - 'center': (params['center_x'], params['center_y'], params['center_z']), - 'direction': (params['dir_x'], params['dir_y'], params['dir_z']), - 'radius': params['radius'] - } - context.data[stage] = {"ude_mykey": "Example 2"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - return valid_results -``` - -## Related - -* [Scripted actuals - Circle](../../python_api/scripted_elements_api.md#circle) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_circle.png b/doc/python_examples/scripted_actuals/scripted_actual_circle.png deleted file mode 100644 index 1c010b1319..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_circle.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_actual_cone.md b/doc/python_examples/scripted_actuals/scripted_actual_cone.md deleted file mode 100644 index 46b623335e..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_cone.md +++ /dev/null @@ -1,50 +0,0 @@ -# scripted_actual_cone - -![Scripted cone element example](scripted_actual_cone.png) - -This is an example for a scripted 'cone' element. - -```{caution} -Due to the internal represenstation of a Cone Element, the direction of the vector `point1` -> `point2` is always from the smaller to the larger circle (`radius1` < `radius2`). - -If you specify `radius1` > `radius2` in the creation parameters, [`point1`; `radius1`] and [`point2`; `radius2`] are swapped automatically. -``` - -```{note} -Please see [offset_point_v2.md](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - - -## Source code excerpt - -```{code-block} python ---- -linenos: ---- -def dialog(context, params): - #[...] - -def calculation(context, params): - valid_results = False - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - context.result[stage] = {'default': { - 'point1': gom.Vec3d(params['p1_x'], params['p1_y'], params['p1_z']), - 'radius1': params['radius_1'], - 'point2': gom.Vec3d(params['p2_x'], params['p2_y'], params['p2_z']), - 'radius2': params['radius_2'] - }} - context.data[stage] = {"ude_mykey": "Example 6"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - return valid_results -``` - -## Related - -* [Scripted actuals - Cone](../../python_api/scripted_elements_api.md#cone) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_cone.png b/doc/python_examples/scripted_actuals/scripted_actual_cone.png deleted file mode 100644 index 9c4d50cc9c..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_cone.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_actual_curve.md b/doc/python_examples/scripted_actuals/scripted_actual_curve.md deleted file mode 100644 index 0fb3eec180..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_curve.md +++ /dev/null @@ -1,52 +0,0 @@ -# scripted_actual_curve - -![Scripted curve element example](scripted_actual_curve.png) - -This is an example for a scripted 'curve' element. A parametric function is used to create a 3-dimensional curve - a helix - with a fixed number of points. `np.arange()` is used to iterate from `t_min` to `t_max` with a non-integer step size. - -```{note} -Please see [offset_point_v2.md](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - - -## Source code excerpt - -```{code-block} python ---- -linenos: ---- -import math -import numpy as np - -def dialog(context, params): - #[...] - -def calculation(context, params): - valid_results = False - - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - # Creating a list of points using a parametric curve function: - # P(t) = ( x0 + (j * t + r) * cos(t), y0 + (j * t + r) * cos(t), z0 + k * t ) - # with t in [t_min...t_max], 1000 steps - points = [] - for t in np.arange(params['t_min'], params['t_max'], (params['t_max'] - params['t_min']) / 1000): - points.append((params['x0'] + (params['j'] * t + params['radius']) * math.cos(t), - params['y0'] + (params['j'] * t + params['radius']) * math.sin(t), - params['z0'] + params['k'] * t) - ) - context.result[stage] = [{'points': points}] - context.data[stage] = {"ude_mykey": "Example 3"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - return valid_results -``` - -## Related - -* [Scripted actuals - Curve](../../python_api/scripted_elements_api.md#curve) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_curve.png b/doc/python_examples/scripted_actuals/scripted_actual_curve.png deleted file mode 100644 index eca9cfcbfe..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_curve.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_actual_cylinder.md b/doc/python_examples/scripted_actuals/scripted_actual_cylinder.md deleted file mode 100644 index 93380af7c2..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_cylinder.md +++ /dev/null @@ -1,46 +0,0 @@ -# scripted_actual_cylinder - -![Scripted cylinder element example](scripted_actual_cylinder.png) - -This is an example for a scripted 'cylinder' element. - -```{note} -Please see [offset_point_v2.md](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - - -## Source code excerpt - -```{code-block} python ---- -linenos: ---- -def dialog(context, params): - #[...] - -def calculation(context, params): - valid_results = False - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - # point = gom.Vec3d(params['point_x'], params['point_y'], params['point_z']) - # direction = gom.Vec3d(params['dir_x'], params['dir_y'], params['dir_z']) - context.result[stage] = {'default': { - 'point': gom.Vec3d(params['point_x'], params['point_y'], params['point_z']), - 'radius': params['radius'], - 'direction': gom.Vec3d(params['dir_x'], params['dir_y'], params['dir_z']), - 'inner': params['inner'] - }} - context.data[stage] = {"ude_mykey": "Example 5"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - return valid_results -``` - -## Related - -* [Scripted actuals - Cylinder](../../python_api/scripted_elements_api.md#cylinder) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_cylinder.png b/doc/python_examples/scripted_actuals/scripted_actual_cylinder.png deleted file mode 100644 index 3c5918c777..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_cylinder.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_actual_distance.md b/doc/python_examples/scripted_actuals/scripted_actual_distance.md deleted file mode 100644 index 38811b2148..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_distance.md +++ /dev/null @@ -1,44 +0,0 @@ -# scripted_actual_distance - -![Scripted distance element example](scripted_actual_distance.png) - -This is an example for a scripted 'distance' element. - -```{note} -Please see [offset_point_v2.md](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - - -## Source code excerpt - -```{code-block} python ---- -linenos: ---- -def dialog(context, params): - #[...] - - -def calculation(context, params): - valid_results = False - - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - context.result[stage] = { - 'point1': (params['p1_x'], params['p1_y'], params['p1_z']), - 'point2': (params['p2_x'], params['p2_y'], params['p2_z']) - } - context.data[stage] = {"ude_mykey": "Example 1"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - return valid_results -``` - -## Related - -* [Scripted actuals - Distance](../../python_api/scripted_elements_api.md#distance) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_distance.png b/doc/python_examples/scripted_actuals/scripted_actual_distance.png deleted file mode 100644 index 29437d5bd9..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_distance.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_actual_point_cloud.md b/doc/python_examples/scripted_actuals/scripted_actual_point_cloud.md deleted file mode 100644 index df25f18fc8..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_point_cloud.md +++ /dev/null @@ -1,55 +0,0 @@ -# scripted_actual_point_cloud - -![Scripted point cloud element example](scripted_actual_point_cloud.png) - -This is an example for a scripted 'point cloud' element. A parametric function is used to define the points, in this case the surface points of a torus. `np.arange()` is used to iterate from `u_min` to `u_max` and from `v_min` to `v_max` with non-integer step sizes. The step sizes `u_steps` and `v_steps` define the point density. - -```{note} -Please see [offset_point_v2.md](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - - -## Source code excerpt - -```{code-block} python ---- -linenos: ---- -def dialog(context, params): - #[...] - -def calculation(context, params): - valid_results = False - - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - # Creating a list of points using a parametric curve function: - # / (R+r*cos(v))*cos(u) \ - # P(u, v) = | (R+r*cos(v))*sin(u) | - # \ r*sin(v) / - # with u in [u_min...u_max], v in [v_min...v_max] - points = [] - for u in np.arange(params['u_min'], params['u_max'], (params['u_max'] - params['u_min']) / params['u_steps']): - for v in np.arange(params['v_min'], params['v_max'], (params['v_max'] - params['v_min']) / params['v_steps']): - p = gom.Vec3d( - (params['R'] + params['r'] * math.cos(v * math.pi)) * math.cos(u * math.pi), - (params['R'] + params['r'] * math.cos(v * math.pi)) * math.sin(u * math.pi), - params['r'] * math.sin(v * math.pi) - ) - points.append(p) - - context.result[stage] = {'points': points} - context.data[stage] = {"ude_mykey": "Example 9"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - return valid_results -``` - -## Related - -* [Scripted actuals - Curve](../../python_api/scripted_elements_api.md#curve) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_point_cloud.png b/doc/python_examples/scripted_actuals/scripted_actual_point_cloud.png deleted file mode 100644 index 4f571265e1..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_point_cloud.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_actual_section.md b/doc/python_examples/scripted_actuals/scripted_actual_section.md deleted file mode 100644 index ad614069ea..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_section.md +++ /dev/null @@ -1,118 +0,0 @@ -# scripted_actual_section - -![Scripted section element example](scripted_actual_section.png) - -This is an example for a scripted 'section' element. The dialog allows to select an existing section, which may consist of multiple sub sections. The script creates a new section from the existing one, with the selected filter criterion. - -```{note} -Please see [offset_point_v2.md](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - - -## Functions for calculating the section - -```{code-block} python ---- -linenos: ---- -def calc_section_length(verts, indices=None): - '''Calculate length of (sub-)section''' - if indices is None: - indices = range(len(verts)) - l = 0 - - # Length: Sum of Euclidean distance between each two adjacent vertices of the curve - for i, j in zip(indices, indices[1:]): - l += la.norm(verts[j] - verts[i]) - return l - - -def get_sub_sections(base_curve, stage=0): - """Separate section curve into sub-sections by checking if a point is connected to another point - - Returns: - array of curves - """ - curve_coords = np.array(base_curve.data.coordinate)[stage] - curve_normals = np.array(base_curve.data.normal)[stage] - sub_sections = [] - start_index = 0 - for end_index, conn in enumerate(base_curve.scanline_point_connection): - if conn != "connected": - sub_sections.append((curve_coords[start_index:end_index + 1], curve_normals[start_index:end_index + 1])) - start_index = end_index + 1 - return sub_sections - - -def filter_by_length(sub_sections, mode): - '''Filter an array of curves by length and return the curve matching the filter criterion''' - max_len = 0 - min_len = 0 - r_min = None - r_max = None - - # For all sub-sections, calculate min. and max. length - # and save the vertices and normals of both the shortest/longest curve - for verts, normals in sub_sections: - ssl = calc_section_length(verts) - if max_len < ssl: - max_len = ssl - r_max = verts, normals - if min_len == 0 or min_len > ssl: - min_len = ssl - r_min = verts, normals - if mode.lower() == "max. length": - return r_max - else: - return r_min -``` - -## Dialog and calculation functions - -```{code-block} python ---- -linenos: ---- -def dialog(context, params): - #[...] - -def calculation(context, params): - '''Scripted section calculation function''' - valid_results = False - - # Check if filter mode is defined - if params["i_mode"].lower() in ["min. length", "max. length"]: - f = filter_by_length - else: - raise ValueError(f"Unknown mode: {params['i_mode']}") - - for stage in context.stages: - # Get selected section from stage - section = params["i_elem"].in_stage[stage] - - # Get sub-sections - sub_sections = get_sub_sections(section, stage) - - # Apply filter - sub_section = f(sub_sections, params["i_mode"]) - - # Get vertices and normals of resulting sub-section - verts, normals = sub_section - - data = [{"points": [gom.Vec3d(*v) for v in verts], "normals": [gom.Vec3d(*n) for n in normals]}] - - try: - context.result[stage] = {"curves": data} - context.data[stage] = {"ude_mykey": "Example 10"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - - return valid_results -``` - -## Related - -* [Scripted actuals - Section](../../python_api/scripted_elements_api.md#section) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_section.png b/doc/python_examples/scripted_actuals/scripted_actual_section.png deleted file mode 100644 index 56f7853f4b..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_section.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_actual_surface.md b/doc/python_examples/scripted_actuals/scripted_actual_surface.md deleted file mode 100644 index af85dcc205..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_surface.md +++ /dev/null @@ -1,55 +0,0 @@ -# scripted_actual_surface - -![Scripted surface element example](scripted_actual_surface.png) - -This is an example for a scripted 'surface' element. The dialog allows to specify the coordinates of eight vertices defining a mesh. The triangles for defining the mesh are hard-coded in this example. The resulting body is a cuboid. - -```{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](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - - -## Source code excerpt - -```{code-block} python ---- -linenos: ---- -def dialog(context, params): - #[...] - -def calculation(context, params): - valid_results = False - v0 = gom.Vec3d(params['v0_x'], params['v0_y'], params['v0_z']) - #[...] - v7 = gom.Vec3d(params['v7_x'], params['v7_y'], params['v7_z']) - - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - context.result[stage] = { - 'vertices': [v0, v1, v2, v3, v4, v5, v6, v7], - # two triangles per side of the cuboid - # ----- front ------ , ----- right ------- , ----- top ---------- - 'triangles': [(0, 1, 2), (0, 2, 3), (1, 5, 6), (1, 6, 2), (3, 2, 6), (3, 6, 7), - # ----- bottom ----- , ----- back -------- , ----- left --------- - (0, 1, 5), (0, 5, 4), (4, 5, 6), (4, 6, 7), (0, 4, 7), (0, 7, 3)] - } - context.data[stage] = {"ude_mykey": "Example 8"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - return valid_results -``` - -## Related - -* [Scripted actuals - Surface](../../python_api/scripted_elements_api.md#surface) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_surface.png b/doc/python_examples/scripted_actuals/scripted_actual_surface.png deleted file mode 100644 index 68e956c620..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_surface.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_actual_surface_curve.md b/doc/python_examples/scripted_actuals/scripted_actual_surface_curve.md deleted file mode 100644 index abefbf5a37..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_surface_curve.md +++ /dev/null @@ -1,55 +0,0 @@ -# scripted_actual_surface_curve - -![Scripted surface curve element example](scripted_actual_surface_curve.png) - -This is an example for a scripted 'surface curve' element. A parametric function is used to create a 3-dimensional surface curve - a section of a circle's parallel - with a fixed number of definition points. These point vectors are used as normals, too. `np.arange()` is used to iterate from `phi_min` to `phi_max` with a non-integer step size. - -```{note} -Please see [offset_point_v2.md](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - - -## Source code excerpt - -```{code-block} python ---- -linenos: ---- -def dialog(context, params): - #[...] - -def calculation(context, params): - valid_results = False - - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - # Creating a list of points using a parametric curve function: - # P(t) = ( r * cos(theta) * cos(phi), r * cos(theta) * sin (phi), r * sin(phi) ) - # with - # theta = const - # phi in [phi_min...phi_max], 1000 steps - points = [] - normals = [] - for phi in np.arange(params['phi_min'], params['phi_max'], (params['phi_max'] - params['phi_min']) / 1000): - p = ( - params['r'] * math.cos(params['theta']) * math.cos(phi), - params['r'] * math.cos(params['theta']) * math.sin(phi), - params['r'] * math.sin(params['theta']) - ) - points.append(p) - normals.append(p) - context.result[stage] = [{'points': points, 'normals': normals}] - context.data[stage] = {"ude_mykey": "Example 3b"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - return valid_results -``` - -## Related - -* [Scripted actuals - Surface curve](../../python_api/scripted_elements_api.md#surface-curve) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_surface_curve.png b/doc/python_examples/scripted_actuals/scripted_actual_surface_curve.png deleted file mode 100644 index aab119d3f2..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_surface_curve.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_actual_volume.md b/doc/python_examples/scripted_actuals/scripted_actual_volume.md deleted file mode 100644 index cf2bcb6f65..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_volume.md +++ /dev/null @@ -1,112 +0,0 @@ -# scripted_actual_volume - -![Scripted volume element example](scripted_actual_volume.png) - -This is an example for a scripted 'volume' element. The volume data is created as an np.array of shape 70×70×70. Each element defines a voxel with a default gray value `gv1` (`calculation()`, lines 11&12). The function `set_voxeldata()` changes some of the gray values to `gv2` (line 13). The resulting volume object resembles a die. Finally the volume data is padded in each direction with voxels of the background gray value `gv0`. - -The dialog allows to set the gray values and to apply a transformation to the volume element. - -```{caution} -The voxel (measurement) coordinate system may differ from the CAD coordinate system. -``` - -```{note} -Please see [offset_point_v2.md](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - - -## Function for setting voxel data - -```{code-block} python ---- -linenos: ---- -def set_voxeldata(voxels, gv, e): - """Set the gray value of some voxels - - :param voxels: np.array() of shape (70, 70, 70) - :param gv: gray value to set - :param e: extend around (fixed) nominal voxel coordinate - """ - - # (1) - front - for x in range(-e, e + 1): - for y in range(-e, e + 1): - for z in range(-e, e + 1): - voxels[35 + x, e + y, 35 + z] = gv - - # (6) - back - for x in range(-e, e + 1): - for y in range(-e, e + 1): - for z in range(-e, e + 1): - voxels[15 + x, 69 - e + y, 15 + z] = gv - voxels[15 + x, 69 - e + y, 35 + z] = gv - voxels[15 + x, 69 - e + y, 55 + z] = gv - voxels[55 + x, 69 - e + y, 15 + z] = gv - voxels[55 + x, 69 - e + y, 35 + z] = gv - voxels[55 + x, 69 - e + y, 55 + z] = gv - - # (3) - top - for x in range(-e, e + 1): - for y in range(-e, e + 1): - for z in range(-e, e + 1): - voxels[15 + x, 15 + y, 69 - e + z] = gv - voxels[35 + x, 35 + y, 69 - e + z] = gv - voxels[55 + x, 55 + y, 69 - e + z] = gv - #[...] -``` - -## Dialog and calculation functions - -```{code-block} python ---- -linenos: ---- -def dialog(context, params): - #[...] - -def calculation(context, params): - valid_results = False - - e = 4 - gv0 = params['gv_background'] - gv1 = params['gv_mat1'] - gv2 = params['gv_mat2'] - voxels = np.ones((70, 70, 70), dtype=np.uint16) - voxels = voxels * gv1 - set_voxeldata(voxels, gv2, e) - voxels = np.pad(voxels, 30, 'constant', constant_values=gv0) - - rx = params['rx'] - ry = params['ry'] - rz = params['rz'] - dx = params['dx'] - dy = params['dy'] - dz = params['dz'] - - transformation = gom.Mat4x4([ - cos(rz) * cos(ry), cos(rz) * sin(ry) * sin(rx) - sin(rz) * - cos(rx), cos(rz) * sin(ry) * cos(rx) + sin(rz) * sin(rx), dx - 35, - sin(rz) * cos(ry), sin(rz) * sin(ry) * sin(rx) + cos(rz) * - cos(rx), sin(rz) * sin(ry) * sin(rx) - cos(rz) * sin(rx), dy - 35, - -sin(ry), cos(ry) * sin(rx), cos(ry) * cos(rx), dz - 35, - 0, 0, 0, 1 - ]) - - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - context.result[stage] = {'voxel_data': voxels, 'transformation': transformation} - context.data[stage] = {"ude_mykey": "Example 11"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - return valid_results -``` - -## Related - -* [Scripted actuals - Section](../../python_api/scripted_elements_api.md#volume) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_volume.png b/doc/python_examples/scripted_actuals/scripted_actual_volume.png deleted file mode 100644 index 68b9f55d78..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_volume.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_actual_volume_defects.md b/doc/python_examples/scripted_actuals/scripted_actual_volume_defects.md deleted file mode 100644 index 0e7b696884..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_volume_defects.md +++ /dev/null @@ -1,56 +0,0 @@ -# scripted_actual_volume_defects - -![Scripted volume defects element example](scripted_actual_volume_defects.png) - -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](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - - -## Source code excerpt - -```{code-block} python ---- -linenos: ---- -def dialog(context, params): - #[...] - -def calculation(context, params): - valid_results = False - v0 = (params['v0_x'], params['v0_y'], params['v0_z']) - v1 = (params['v1_x'], params['v1_y'], params['v1_z']) - v2 = (params['v2_x'], params['v2_y'], params['v2_z']) - v3 = (params['v3_x'], params['v3_y'], params['v3_z']) - - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - context.result[stage] = { - 'vertices': [np.array([v0, v1, v2, v3])], - # Note: - # Triangles are defined by indices into the array of vertices. - # The vertices defining a triangle must be specified in counter-clockwise - # order, otherwise the resulting surface would be inverted, i.e. invisible! - 'triangles': [np.array([(0, 1, 2), (1, 0, 3), (0, 2, 3), (2, 1, 3)])] - } - context.data[stage] = {"ude_mykey": "Example 12"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - return valid_results -``` - -## Related - -* [Scripted actuals - Volume defects](../../python_api/scripted_elements_api.md#volume-defects) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_volume_defects.png b/doc/python_examples/scripted_actuals/scripted_actual_volume_defects.png deleted file mode 100644 index d03098b6bc..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_volume_defects.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_actual_volume_region.md b/doc/python_examples/scripted_actuals/scripted_actual_volume_region.md deleted file mode 100644 index 3af91090cd..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_volume_region.md +++ /dev/null @@ -1,56 +0,0 @@ -# scripted_actual_volume_region - -![Scripted volume region example](scripted_actual_volume_region.png) - -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](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - - -## Source code excerpt - -```{code-block} python ---- -linenos: ---- -def dialog(context, params): - #[...] - -def calculation(context, params): - valid_results = False - - x0 = params['x0'] - y0 = params['y0'] - z0 = params['z0'] - - dx = int(params['dx'] / params['volume_ele'].voxel_size.x) - dy = int(params['dy'] / params['volume_ele'].voxel_size.y) - dz = int(params['dz'] / params['volume_ele'].voxel_size.z) - - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - context.result[stage] = { - 'volume_element': params['volume_ele'], - 'offset': gom.Vec3d(x0, y0, z0), - 'voxel_data': np.ones((dx, dy, dz), dtype=np.uint8) - } - context.data[stage] = {"ude_mykey": "Example 13"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - return valid_results -``` - -## Related - -* [Scripted actuals - Volume region](../../python_api/scripted_elements_api.md#volume-region) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_volume_region.png b/doc/python_examples/scripted_actuals/scripted_actual_volume_region.png deleted file mode 100644 index 4448577dbb..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_volume_region.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_actual_volume_section.md b/doc/python_examples/scripted_actuals/scripted_actual_volume_section.md deleted file mode 100644 index 1dbe9285b1..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_actual_volume_section.md +++ /dev/null @@ -1,88 +0,0 @@ -# scripted_actual_volume_section - -![Scripted volume section element example](scripted_actual_volume_section.png) - -This is an example for a scripted 'volume section' element. The dialog allows to select an image file, which is converted to a grayscale image (`calculation()`, line 30) and then to an `np.array()` (line 32). Further, a transformation is applied to the image. - -```{note} -Please see [offset_point_v2.md](offset_point_v2.md) for a complete scripted elements example with detailed description. -``` - -## Source code excerpt - -```{code-block} python ---- -linenos: ---- -import numpy as np -from math import sin, cos -from PIL import Image -from io import BytesIO - -def dialog(context, params): - #[...] - -def calculation(context, params): - valid_results = False - - file = params['file'] - - # if filename starts with ':', it is an app resource used for testing, - # e.g. ':ScriptedElementsExamples/Grayscale_8bits_palette.png' - if file and file[0] == ':': - # read resource - test_image_resource = gom.Resource(file) - test_image = test_image_resource.open().read() - - # convert resource to file object - file = BytesIO(test_image) - - try: - image = Image.open(file) - except AttributeError: - return False - - # convert image to grayscale - image = image.convert('L') - # print (image) - img_array = np.array(image, dtype=np.float32) - # print(f"img_array: {img_array}") - # print(f"img_array.shape: {img_array.shape}") - - rx = params['rx'] - ry = params['ry'] - rz = params['rz'] - dx = params['dx'] - dy = params['dy'] - dz = params['dz'] - - transformation = gom.Mat4x4([ - cos(rz) * cos(ry), cos(rz) * sin(ry) * sin(rx) - sin(rz) * - cos(rx), cos(rz) * sin(ry) * cos(rx) + sin(rz) * sin(rx), dx, - sin(rz) * cos(ry), sin(rz) * sin(ry) * sin(rx) + cos(rz) * - cos(rx), sin(rz) * sin(ry) * sin(rx) - cos(rz) * sin(rx), dy, - -sin(ry), cos(ry) * sin(rx), cos(ry) * cos(rx), dz, - 0, 0, 0, 1 - ]) - # print(transformation) - - # Calculating all available stages - for stage in context.stages: - # Access element properties with error handling - try: - context.result[stage] = { - 'pixel_data': img_array, - 'transformation': transformation - } - context.data[stage] = {"ude_mykey": "Example 14"} - except Exception as error: - context.error[stage] = str(error) - else: - valid_results = True - return valid_results -``` - -## Related - -* [Scripted actuals - Volume section](../../python_api/scripted_elements_api.md#volume-section) -* [How-to: User-defined dialogs](../../howtos/python_api_introduction/user_defined_dialogs.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_actual_volume_section.png b/doc/python_examples/scripted_actuals/scripted_actual_volume_section.png deleted file mode 100644 index 0c7b71672d..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_actual_volume_section.png and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_element_progress.md b/doc/python_examples/scripted_actuals/scripted_element_progress.md deleted file mode 100644 index 36c0eaf715..0000000000 --- a/doc/python_examples/scripted_actuals/scripted_element_progress.md +++ /dev/null @@ -1,27 +0,0 @@ -# scripted_element_progress - -![](scripted_element_progress_preview.jpg) - -![](scripted_element_progress_computation.jpg) -## Short description - -This examples demonstrates how to show progress information to the user while calcualting a scripted element. -## Highlights - -The scripted element itself is not of interest here, as it is rather meaningless: a point that will always be created at *(1,0,0)*. -To showcase the display of calculation progress, a loop with 100 steps containing a `sleep` call to simulate computation are performed in the `calculation` function: - -```python -def calculation (context, params): - context.progress_stages_total = limit - for i in range(limit): - context.progress_stages_computing = i - time.sleep (0.1) - - # [...] -``` -To indicate progress, you need to set `context.progress_stages_total` to the amount of steps you expect to compute. This can but not has to be the number of stages in trend projects. You can also set any arbitrary number. As soon as you set `context.progress_stages_computing`, the progress will be indicated in the bottom are of the application (see top screenshot). - -## Related - -* How-to: [Scripted actuals](../../howtos/scripted_elements/scripted_actuals.md) \ No newline at end of file diff --git a/doc/python_examples/scripted_actuals/scripted_element_progress_computation.jpg b/doc/python_examples/scripted_actuals/scripted_element_progress_computation.jpg deleted file mode 100644 index 9a0df20133..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_element_progress_computation.jpg and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/scripted_element_progress_preview.jpg b/doc/python_examples/scripted_actuals/scripted_element_progress_preview.jpg deleted file mode 100644 index ebbb816516..0000000000 Binary files a/doc/python_examples/scripted_actuals/scripted_element_progress_preview.jpg and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/trimesh_deform_mesh.jpg b/doc/python_examples/scripted_actuals/trimesh_deform_mesh.jpg deleted file mode 100644 index a389a8850d..0000000000 Binary files a/doc/python_examples/scripted_actuals/trimesh_deform_mesh.jpg and /dev/null differ diff --git a/doc/python_examples/scripted_actuals/trimesh_deform_mesh.md b/doc/python_examples/scripted_actuals/trimesh_deform_mesh.md deleted file mode 100644 index a690500aa3..0000000000 --- a/doc/python_examples/scripted_actuals/trimesh_deform_mesh.md +++ /dev/null @@ -1,67 +0,0 @@ -# trimesh_deform_mesh - -![](trimesh_deform_mesh.jpg) -## Short description - -This example demonstrates how to generate a custom surface element using a scripted element. The example script accesses mesh information from an existing mesh in the project and adds a random deformation to each point. - -Finally, the result is transfered back to the ZEISS INSPECT Software, where an actual surface element is created. - -## Highlights - -The dialog was created using the script dialog editor and contains an "Element selection" widget to let the user choose which mesh to deform. - -### Dialog: Element filter - -In the script, a filter function is implemented to populate the "Element selection" widget only with elements of a certain type. To this end, the widget's type property is first set to "User-defined script function". - -![](trimesh_deform_mesh_dialog.jpg) - -Then, in the script, the filter property is set to the following function: - -```python -def element_filter(element): - try: - if element.type in ['mesh','cad_body']: - return True - except Exception as e: - pass - return False - - DIALOG.selected_element.filter = element_filter -``` - -Furthermore, the dialog contains a name widget with a default name set for the result element and a decimal widget to let the user choose the magnitude of deformation. - - -### Calculation: Mesh deformation with `trimesh` - -The logic of mesh deformation happens in the calculation function. Here, the stored parameters are read from the 'params' array and used to perform the calculation. - -The access to the mesh data is done via numpy arrays that can be retrieved by an elements data interface. This interface is accessible by the `.data` property and yields the results usually for all stages. Using `[s]` as a subscript gives the data for stage `s`. - -```python - vertices = np.array (selected_element.data.coordinate)[s] - triangles = np.array (selected_element.data.triangle)[s] - - # Creating a mesh in 3rd party library "trimesh" - mesh = trimesh.Trimesh (vertices, triangles) - - # Using the deformation algorithm of trimesh - deformed = trimesh.permutate.noise (mesh, deformation) - - # Converting to target dtypes - deformed_vertices = deformed.vertices - deformed_faces = np.array (deformed.faces, dtype=np.int32) - - # Setting the result to transfer back to the GOM Software - context.result[s] = { 'vertices': deformed_vertices, 'triangles': deformed_faces } -``` - -In this case, we retrieve the vertices and triangles of the selected mesh. -To deform the mesh, we then apply some noise to the data using [trimesh's noise permutator](https://trimsh.org/trimesh.permutate.html#trimesh.permutate.noise). We finally transform our results into the supported formats and set the results of this stage in the `context.result[s]` variable. - - -## Related - -* How-to: [Python API introduction - Element data interfaces](../../howtos/python_api_introduction/python_api_introduction.md#element-data-interfaces) diff --git a/doc/python_examples/scripted_actuals/trimesh_deform_mesh_dialog.jpg b/doc/python_examples/scripted_actuals/trimesh_deform_mesh_dialog.jpg deleted file mode 100644 index b517b34541..0000000000 Binary files a/doc/python_examples/scripted_actuals/trimesh_deform_mesh_dialog.jpg and /dev/null differ