Skip to content

Commit

Permalink
Merge pull request #24 from ZEISS/20240806-change-markdown-style
Browse files Browse the repository at this point in the history
20240806 change markdown style from Sphinx to GitHub
  • Loading branch information
mprinkezs authored Aug 8, 2024
2 parents f067241 + faa0c3f commit a5e310f
Show file tree
Hide file tree
Showing 30 changed files with 202 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@ This example demonstrates two ways of accessing result data from checks using th

## Highlights

Basically, if you have obtained an `gom.Reference` element reference, e.g. by selecting an element by name (`gom.app.project.inspection['Surface comparison 1']`), you can access the results of the check:
Basically, if you have obtained an `gom.Reference` element reference, e.g. by selecting an element by name (`gom.app.project.inspection['Surface comparison 1']`), you can access the results of the check.

1. **By evaluating an expression**
### 1. Accessing element results by evaluating an expression

`single_scalar_value = element.get ('result_dimension[0].deviation')`
```python
single_scalar_value = element.get ('result_dimension[0].deviation')
```

* simple for single values
* works without using `numpy` library

2. **By the data interface of this element using the `.data` token**
### 2. Accessing element results by the data interface using the `.data` token

`scalars = np.array (element.data.result_dimension.deviation)`
```python
scalars = np.array (element.data.result_dimension.deviation)
```

* gets large datasets of all stages very efficiently

## Related

* How-to: [Access element properties and data](https://zeissiqs.github.io/zeiss-inspect-addon-api/2025/howtos/python_api_introduction/python_api_introduction.html#access-element-properties)
* How-to: [Access element properties and data](https://zeissiqs.github.io/zeiss-inspect-addon-api/2025/howtos/python_api_introduction/python_api_introduction.html#access-element-properties)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Index 1
Index 2
: Coordinate [x, y, z]

```{code-block} python
```python
reference_points = np.array (gom.app.project.measurement_series[MEASUREMENT_SERIES].results['points'].data.coordinate)
```

Expand All @@ -49,7 +49,7 @@ reference_points = np.array (gom.app.project.measurement_series[MEASUREMENT_SERI

This can be used as input parameter to a script for creating a point cloud element:

```{code-block} python
```python
create_point_cloud = gom.script.sys.create_element_by_script (
check_type='none',
element_type='point_cloud',
Expand Down Expand Up @@ -82,7 +82,7 @@ Index 1
Index 2
: Coordinate [x, y, z]

```{code-block} python
```python
part_points = np.array (gom.app.project.parts[PART].actual.data.coordinate)
```

Expand All @@ -100,7 +100,7 @@ Example:

Numpy-arrays can be handled very efficiently. The following code example creates a copy of the original mesh vertex points and shifts all points in Z direction by 200mm:

```{code-block} python
```python
shifted_part_points = part_points.copy()
shifted_part_points[0, :, 2] += 200
```
Expand All @@ -118,7 +118,7 @@ Index 1
Index 2
: Indices into array of vertex points [indexA, indexB, indexC], which define the points A, B, C of each triangle.

```{code-block} python
```python
part_triangles = np.array (gom.app.project.parts[PART].actual.data.triangle)
```

Expand Down Expand Up @@ -146,7 +146,7 @@ C = [-260.18363995 -54.31011231 -29.50854346]

The arrays of vertex points and triangles can be used as input parameters to a script for creating a surface element:

```{code-block} python
```python
create_surface = gom.script.sys.create_element_by_script (
check_type='none',
element_type='surface',
Expand All @@ -167,26 +167,26 @@ Since no user interaction is required, the `dialog()` function shown in [Introdu

![Create Surface - Script Properties](create_surface_script_properties.png)

```{code-block} python
:caption: create_surface.py
**`create_surface.py`**:

```python
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] = {
'vertices': params['vertices'],
'triangles': params['triangles']
}
except Exception as error:
context.error[stage] = str(error)
else:
valid_results=True
return valid_results
```
valid_results=False

# Calculating all available stages
for stage in context.stages:
# Access element properties with error handling
try:
context.result[stage] = {
'vertices': params['vertices'],
'triangles': params['triangles']
}
except Exception as error:
context.error[stage] = str(error)
else:
valid_results=True
return valid_results
```

## Related

Expand Down
18 changes: 9 additions & 9 deletions AppExamples/misc/CSVExample/doc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ For demonstration purposes, project keywords are read from or written to a CSV f

Both example scripts check if a project has been opened and quit with an error message dialog if this is not the case:

```{code-block} python
```python
if not hasattr(gom.app, 'project'):
gom.script.sys.execute_user_defined_dialog (file='no_project.gdlg')
quit(0)
Expand All @@ -24,27 +24,27 @@ if not hasattr(gom.app, 'project'):

The CSV module is imported:

```{code-block} python
```python
import csv
```

The current project keywords and their values are listed:

```{code-block} python
```python
print("-- Current keywords --")
for k in gom.app.project.project_keywords:
print(f"{k}='{gom.app.project.get(k)}'")
```

A dialog is used to request the CSV file to be opened:

```{code-block} python
```python
RESULT=gom.script.sys.execute_user_defined_dialog (file='import_file.gdlg')
```

The CSV file is opened and a `csv_reader` object for accessing its content is created:

```{code-block} python
```python
with open(RESULT.file) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=';')
```
Expand All @@ -53,7 +53,7 @@ The class `csv.reader` allows some configurations, such as the column delimiter.

The scripts reads the CSV file line by line. Each line is provided as an array with the columns as its array elements. The first line is expected to contain a specific table header (`Project Keyword;Description;Value`). The remaining lines are used to create or change project keywords:

```{code-block} python
```python
with open(RESULT.file) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=';')
line_count = 0
Expand Down Expand Up @@ -83,7 +83,7 @@ The script distinguishes the following cases:
3. The keyword in the Excel file already exists, but its description has changed
4. The keyword in the Excel file already exists and remains unchanged

```{code-block} python
```python
ukw = "user_" + key
if not ukw in gom.app.project.project_keywords:
print(f"New keyword {key}='{val}' added")
Expand All @@ -104,7 +104,7 @@ else:

Finally, the updated project keywords are listed:

```{code-block} python
```python
print("\n-- Updated keywords --")
for k in gom.app.project.project_keywords:
print(f"{k}='{gom.app.project.get(k)}'")
Expand All @@ -116,7 +116,7 @@ As in `csv_import.py`, the module `csv` is imported, the presence of an open pro

The file is opened and the `keywords_writer` object is created. Some configuration settings are passed to the constructor. First, the header row is written using the method `writerow()` with an array containing the column headings. Next, a loop iterates over all project keywords and writes them to the CSV file using `writerow()`:

```{code-block} python
```python
with open(RESULT.file, mode='w', newline='') as keywords_file:
keywords_writer = csv.writer(
keywords_file,
Expand Down
13 changes: 5 additions & 8 deletions AppExamples/misc/DialogReopenExample/doc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

This examples demonstrates, how a dialog can be closed from its own handler, just to be opened again.

```{warning}
There are very rare occasions, where you should need this. Use this approach only, if you know what you are doing.
```
> [!WARNING]
> There are very rare occasions, where you should need this. Use this approach only if you know what you are doing.
## Highlights

Expand Down Expand Up @@ -36,11 +35,9 @@ def dialog_event_handler (widget):
reopen = True
```

```{warning}
Never reopen the dialog directly from its own handler to prevent getting undefined behaviour.
```

> [!WARNING]
> Never reopen the dialog directly from its own handler to prevent getting undefined behaviour.
## Related

* How-to: [User-defined Dialogs](https://zeissiqs.github.io/zeiss-inspect-addon-api/2025/howtos/python_api_introduction/user_defined_dialogs.md)
* How-to: [User-defined Dialogs](https://zeissiqs.github.io/zeiss-inspect-addon-api/2025/howtos/python_api_introduction/user_defined_dialogs.md)
32 changes: 16 additions & 16 deletions AppExamples/misc/ExcelExample/doc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For demonstration purposes, project keywords are read from or written to an Exce

Both example scripts check if a project has been opened and quit with an error message dialog if this is not the case:

```{code-block} python
```python
if not hasattr(gom.app, 'project'):
gom.script.sys.execute_user_defined_dialog (file='no_project.gdlg')
quit(0)
Expand All @@ -26,36 +26,36 @@ if not hasattr(gom.app, 'project'):

Two packages are imported from `openpyxl`:

```{code-block} python
```python
from openpyxl import load_workbook
from openpyxl.utils.cell import coordinate_from_string, column_index_from_string
```

The current project keywords and their values are listed with:

```{code-block} python
```python
print("-- Current keywords --")
for k in gom.app.project.project_keywords:
print(f"{k}='{gom.app.project.get(k)}'")
```

A dialog is used to request the Excel file to be opened:

```{code-block} python
```python
RESULT=gom.script.sys.execute_user_defined_dialog (file='dialog.gdlg')
print("\nOpening", RESULT.file)
```

The workbook is opened from the Excel file and a worksheet object `ws` is created:

```{code-block} python
```python
wb = load_workbook(filename = RESULT.file)
ws = wb['Sheet']
```

As a tradeoff between simplicity and flexibility, the script allows to configure the cells which contain keywords, but assumes that the keyword descriptions and values are located at fixed positions in the adjacent cells:

```{code-block} python
```python
# Cells containing the keywords
# - descriptions are expected in column+1
# - values are expected in column+2
Expand All @@ -70,7 +70,7 @@ layout = [
Cells can be accessed by their coordinates (e.g. "A1") or by row and column. The method `coordinate_from_string()` splits the coordinate into row and column (e.g. `coordinate_from_string("A1") => ("A", 1)`). The method `column_index_from_string()` converts a column name into
a column index (e.g. `column_index_from_string("A") => 1`).

```{code-block} python
```python
# Get keyword by cell name, e.g. cell="A1"
key = ws[cell].value

Expand All @@ -95,7 +95,7 @@ The script distinguishes the following cases:
3. The keyword in the Excel file already exists, but its description has changed
4. The keyword in the Excel file already exists and remains unchanged

```{code-block} python
```python
ukw = "user_" + key
if not ukw in gom.app.project.project_keywords:
print(f"New keyword {key}='{val}' added")
Expand All @@ -116,7 +116,7 @@ else:

The steps described above are repeated for all Excel cells listed in `layout[]`:

```{code-block} python
```python
for cell in layout:
# Get keyword, description and value
#...
Expand All @@ -130,7 +130,7 @@ for cell in layout:

Finally, the updated project keywords are listed:

```{code-block} python
```python
print("\n-- Updated keywords --")
for k in gom.app.project.project_keywords:
print(f"{k}='{gom.app.project.get(k)}'")
Expand All @@ -140,14 +140,14 @@ for k in gom.app.project.project_keywords:

Two packages are imported from `openpyxl`:

```{code-block} python
```python
from openpyxl import Workbook
from openpyxl.styles import Font
```

The following code creates a workbook and writes text into three cells of the worksheet as a table header:

```{code-block} python
```python
# Create a workbook
wb = Workbook()

Expand All @@ -162,7 +162,7 @@ ws['C1'] = "Value"

Next, the table header is formatted and the column widths are adjusted:

```{code-block} python
```python
# Change table header layout
for cell in ['A1', 'B1', 'C1']:
ws[cell].font = Font(bold=True, size=16)
Expand All @@ -173,7 +173,7 @@ for cell in ['A1', 'B1', 'C1']:

The script iterates over all project keywords and gets the values and keyword descriptions. A type conversion has been implemented for date entries. The method `ws.append([key, val, desc])` writes the variables `key`, `val` and `desc` - which are combined into an array - to the next three cells of the worksheet.

```{code-block} python
```python
for key in gom.app.project.project_keywords:
val = gom.app.project.get(key)
desc = gom.app.project.get(f'description({key})')
Expand All @@ -200,13 +200,13 @@ Specific cells can be selected with `ws.cell(row=<row>, column=<column>)`. This

Finally the prepared spreadsheet is written to a file. The file path has been requested previously with a dialog.

```{code-block} python
```python
wb.save(RESULT1.file)
```

To handle the common case that the Excel file cannot been written by the script, because it it currently opened in the Excel software, a loop with exception handling has been implemented:

```{code-block} python
```python
# Repeat until file was written successfully or
# user has cancelled.
while True:
Expand Down
Loading

0 comments on commit a5e310f

Please sign in to comment.