Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 1dda0dd

Browse files
authored
Merge pull request #2 from ZeissIQS/file-selection-and-filtering
Copied from GOM Connect, updated dialog content format
2 parents 70f6a65 + 99ea8c8 commit 1dda0dd

File tree

8 files changed

+671
-0
lines changed

8 files changed

+671
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# File Selection and Filtering Examples
2+
3+
Examples for selecting and filtering files in ZEISS INSPECT Python scripts.

examples/FileSelectionAndFiltering/license/license.txt

Lines changed: 296 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import gom
4+
import os
5+
6+
7+
RESULT=gom.script.sys.execute_user_defined_dialog (dialog={
8+
"content": [
9+
[
10+
{
11+
"columns": 1,
12+
"default": "",
13+
"file_types": [
14+
],
15+
"file_types_default": "",
16+
"limited": False,
17+
"name": "directory",
18+
"rows": 1,
19+
"selection_type": "directory",
20+
"title": {
21+
"id": "",
22+
"text": "Choose Folder",
23+
"translatable": True
24+
},
25+
"tooltip": {
26+
"id": "",
27+
"text": "Click to select a folder",
28+
"translatable": True
29+
},
30+
"type": "input::file"
31+
}
32+
]
33+
],
34+
"control": {
35+
"id": "OkCancel"
36+
},
37+
"embedding": "",
38+
"position": "",
39+
"size": {
40+
"height": 112,
41+
"width": 271
42+
},
43+
"sizemode": "",
44+
"style": "Standard",
45+
"title": {
46+
"id": "",
47+
"text": "List files in a folder",
48+
"translatable": True
49+
}
50+
})
51+
52+
dir = RESULT.directory
53+
# change working directory to the selected directory
54+
os.chdir(dir)
55+
print('Files in directory', dir + ':')
56+
for filename in os.listdir(dir):
57+
if os.path.isdir(filename):
58+
print(' Folder:', filename)
59+
elif os.path.isfile(filename):
60+
print(' File:', filename)
61+
else:
62+
print(' Other:', filename)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import gom
4+
import os
5+
6+
7+
RESULT=gom.script.sys.execute_user_defined_dialog (dialog={
8+
"content": [
9+
[
10+
{
11+
"columns": 1,
12+
"default": "",
13+
"file_types": [
14+
],
15+
"file_types_default": "",
16+
"limited": False,
17+
"name": "directory",
18+
"rows": 1,
19+
"selection_type": "directory",
20+
"title": {
21+
"id": "",
22+
"text": "Choose Folder",
23+
"translatable": True
24+
},
25+
"tooltip": {
26+
"id": "",
27+
"text": "Click to select a folder",
28+
"translatable": True
29+
},
30+
"type": "input::file"
31+
}
32+
]
33+
],
34+
"control": {
35+
"id": "OkCancel"
36+
},
37+
"embedding": "",
38+
"position": "",
39+
"size": {
40+
"height": 112,
41+
"width": 271
42+
},
43+
"sizemode": "",
44+
"style": "Standard",
45+
"title": {
46+
"id": "",
47+
"text": "List files in a folder",
48+
"translatable": True
49+
}
50+
})
51+
52+
dir = RESULT.directory
53+
print('Files in directory', dir + ':')
54+
for filename in os.listdir(dir):
55+
print(' File:', filename)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import gom
4+
import os
5+
6+
7+
RESULT=gom.script.sys.execute_user_defined_dialog (dialog={
8+
"content": [
9+
[
10+
{
11+
"columns": 1,
12+
"default": "",
13+
"file_types": [
14+
],
15+
"file_types_default": "",
16+
"limited": False,
17+
"name": "directory",
18+
"rows": 1,
19+
"selection_type": "directory",
20+
"title": {
21+
"id": "",
22+
"text": "Choose Folder",
23+
"translatable": True
24+
},
25+
"tooltip": {
26+
"id": "",
27+
"text": "Click to select a folder",
28+
"translatable": True
29+
},
30+
"type": "input::file"
31+
}
32+
]
33+
],
34+
"control": {
35+
"id": "OkCancel"
36+
},
37+
"embedding": "",
38+
"position": "",
39+
"size": {
40+
"height": 112,
41+
"width": 271
42+
},
43+
"sizemode": "",
44+
"style": "Standard",
45+
"title": {
46+
"id": "",
47+
"text": "List files in a folder",
48+
"translatable": True
49+
}
50+
})
51+
52+
dir = RESULT.directory
53+
# change working directory to the selected directory
54+
os.chdir(dir)
55+
print('Files in directory', dir + ':')
56+
for filename in os.listdir(dir):
57+
if os.path.isdir(filename):
58+
print(' Folder:', filename)
59+
elif os.path.isfile(filename):
60+
base, ext = os.path.splitext(filename)
61+
print(' File:', filename, ' Base:', base, ' Extension:', ext)
62+
else:
63+
print(' Other:', filename)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import gom
4+
import os
5+
6+
7+
RESULT=gom.script.sys.execute_user_defined_dialog (dialog={
8+
"content": [
9+
[
10+
{
11+
"columns": 1,
12+
"default": "",
13+
"file_types": [
14+
],
15+
"file_types_default": "",
16+
"limited": False,
17+
"name": "directory",
18+
"rows": 1,
19+
"selection_type": "directory",
20+
"title": {
21+
"id": "",
22+
"text": "Choose Folder",
23+
"translatable": True
24+
},
25+
"tooltip": {
26+
"id": "",
27+
"text": "Click to select a folder",
28+
"translatable": True
29+
},
30+
"type": "input::file"
31+
}
32+
]
33+
],
34+
"control": {
35+
"id": "OkCancel"
36+
},
37+
"embedding": "",
38+
"position": "",
39+
"size": {
40+
"height": 112,
41+
"width": 271
42+
},
43+
"sizemode": "",
44+
"style": "Standard",
45+
"title": {
46+
"id": "",
47+
"text": "List files in a folder",
48+
"translatable": True
49+
}
50+
})
51+
52+
dir = RESULT.directory
53+
print('Files in directory tree below', dir + ':')
54+
for (basepath, subfolders, filenames) in os.walk(dir):
55+
print(' Files in directory', basepath + ':')
56+
for filename in filenames:
57+
base, ext = os.path.splitext(filename)
58+
print(' File:', filename, ' Base:', base, ' Extension:', ext)
59+
print(' -> Full path:', os.path.join(basepath, filename))
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import gom
4+
import os
5+
6+
7+
RESULT=gom.script.sys.execute_user_defined_dialog (dialog={
8+
"content": [
9+
[
10+
{
11+
"columns": 1,
12+
"default": "",
13+
"file_types": [
14+
],
15+
"file_types_default": "",
16+
"limited": False,
17+
"name": "directory",
18+
"rows": 1,
19+
"selection_type": "directory",
20+
"title": {
21+
"id": "",
22+
"text": "Choose Folder",
23+
"translatable": True
24+
},
25+
"tooltip": {
26+
"id": "",
27+
"text": "Klick to select a folder",
28+
"translatable": True
29+
},
30+
"type": "input::file"
31+
}
32+
]
33+
],
34+
"control": {
35+
"id": "OkCancel"
36+
},
37+
"embedding": "",
38+
"position": "",
39+
"size": {
40+
"height": 112,
41+
"width": 271
42+
},
43+
"sizemode": "",
44+
"style": "Standard",
45+
"title": {
46+
"id": "",
47+
"text": "List files in a folder",
48+
"translatable": True
49+
}
50+
})
51+
52+
dir = RESULT.directory
53+
for (basepath, subfolders, filenames) in os.walk(dir):
54+
for filename in filenames:
55+
base, ext = os.path.splitext(filename)
56+
if ext == '.py':
57+
scriptfile = os.path.join(basepath, filename)
58+
basename, _ = os.path.splitext(filename)
59+
gom.script.sys.import_script (
60+
config_level='user',
61+
display_names=[basename],
62+
files=[scriptfile],
63+
names=['test.' + basename],
64+
replace_existing_scripts=True)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import gom
4+
import os
5+
6+
7+
RESULT=gom.script.sys.execute_user_defined_dialog (dialog={
8+
"content": [
9+
[
10+
{
11+
"columns": 1,
12+
"default": "",
13+
"file_types": [
14+
],
15+
"file_types_default": "",
16+
"limited": False,
17+
"name": "directory",
18+
"rows": 1,
19+
"selection_type": "directory",
20+
"title": {
21+
"id": "",
22+
"text": "Choose Folder",
23+
"translatable": True
24+
},
25+
"tooltip": {
26+
"id": "",
27+
"text": "Klick to select a folder",
28+
"translatable": True
29+
},
30+
"type": "input::file"
31+
}
32+
]
33+
],
34+
"control": {
35+
"id": "OkCancel"
36+
},
37+
"embedding": "",
38+
"position": "",
39+
"size": {
40+
"height": 112,
41+
"width": 271
42+
},
43+
"sizemode": "",
44+
"style": "Standard",
45+
"title": {
46+
"id": "",
47+
"text": "List files in a folder",
48+
"translatable": True
49+
}
50+
})
51+
52+
dir = RESULT.directory
53+
for (basepath, subfolders, filenames) in os.walk(dir):
54+
for filename in filenames:
55+
base, ext = os.path.splitext(filename)
56+
if ext == '.stl':
57+
stlfile = os.path.join(basepath, filename)
58+
gom.script.sys.import_stl (
59+
bgr_coding=True,
60+
files=[stlfile],
61+
import_mode='new_elements',
62+
length_unit='mm',
63+
stl_color_bit_set=False,
64+
target_type='mesh')
65+
if ext == '.pol':
66+
polfile = os.path.join(basepath, filename)
67+
gom.script.sys.import_pol (
68+
files=[polfile],
69+
import_mode='new_elements')

0 commit comments

Comments
 (0)