-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ZeissIQS/file-selection-and-filtering
Copied from GOM Connect, updated dialog content format
- Loading branch information
Showing
8 changed files
with
671 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# File Selection and Filtering Examples | ||
|
||
Examples for selecting and filtering files in ZEISS INSPECT Python scripts. |
Large diffs are not rendered by default.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
examples/FileSelectionAndFiltering/scripts/listdir_categories.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import gom | ||
import os | ||
|
||
|
||
RESULT=gom.script.sys.execute_user_defined_dialog (dialog={ | ||
"content": [ | ||
[ | ||
{ | ||
"columns": 1, | ||
"default": "", | ||
"file_types": [ | ||
], | ||
"file_types_default": "", | ||
"limited": False, | ||
"name": "directory", | ||
"rows": 1, | ||
"selection_type": "directory", | ||
"title": { | ||
"id": "", | ||
"text": "Choose Folder", | ||
"translatable": True | ||
}, | ||
"tooltip": { | ||
"id": "", | ||
"text": "Click to select a folder", | ||
"translatable": True | ||
}, | ||
"type": "input::file" | ||
} | ||
] | ||
], | ||
"control": { | ||
"id": "OkCancel" | ||
}, | ||
"embedding": "", | ||
"position": "", | ||
"size": { | ||
"height": 112, | ||
"width": 271 | ||
}, | ||
"sizemode": "", | ||
"style": "Standard", | ||
"title": { | ||
"id": "", | ||
"text": "List files in a folder", | ||
"translatable": True | ||
} | ||
}) | ||
|
||
dir = RESULT.directory | ||
# change working directory to the selected directory | ||
os.chdir(dir) | ||
print('Files in directory', dir + ':') | ||
for filename in os.listdir(dir): | ||
if os.path.isdir(filename): | ||
print(' Folder:', filename) | ||
elif os.path.isfile(filename): | ||
print(' File:', filename) | ||
else: | ||
print(' Other:', filename) |
55 changes: 55 additions & 0 deletions
55
examples/FileSelectionAndFiltering/scripts/listdir_dialog.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import gom | ||
import os | ||
|
||
|
||
RESULT=gom.script.sys.execute_user_defined_dialog (dialog={ | ||
"content": [ | ||
[ | ||
{ | ||
"columns": 1, | ||
"default": "", | ||
"file_types": [ | ||
], | ||
"file_types_default": "", | ||
"limited": False, | ||
"name": "directory", | ||
"rows": 1, | ||
"selection_type": "directory", | ||
"title": { | ||
"id": "", | ||
"text": "Choose Folder", | ||
"translatable": True | ||
}, | ||
"tooltip": { | ||
"id": "", | ||
"text": "Click to select a folder", | ||
"translatable": True | ||
}, | ||
"type": "input::file" | ||
} | ||
] | ||
], | ||
"control": { | ||
"id": "OkCancel" | ||
}, | ||
"embedding": "", | ||
"position": "", | ||
"size": { | ||
"height": 112, | ||
"width": 271 | ||
}, | ||
"sizemode": "", | ||
"style": "Standard", | ||
"title": { | ||
"id": "", | ||
"text": "List files in a folder", | ||
"translatable": True | ||
} | ||
}) | ||
|
||
dir = RESULT.directory | ||
print('Files in directory', dir + ':') | ||
for filename in os.listdir(dir): | ||
print(' File:', filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import gom | ||
import os | ||
|
||
|
||
RESULT=gom.script.sys.execute_user_defined_dialog (dialog={ | ||
"content": [ | ||
[ | ||
{ | ||
"columns": 1, | ||
"default": "", | ||
"file_types": [ | ||
], | ||
"file_types_default": "", | ||
"limited": False, | ||
"name": "directory", | ||
"rows": 1, | ||
"selection_type": "directory", | ||
"title": { | ||
"id": "", | ||
"text": "Choose Folder", | ||
"translatable": True | ||
}, | ||
"tooltip": { | ||
"id": "", | ||
"text": "Click to select a folder", | ||
"translatable": True | ||
}, | ||
"type": "input::file" | ||
} | ||
] | ||
], | ||
"control": { | ||
"id": "OkCancel" | ||
}, | ||
"embedding": "", | ||
"position": "", | ||
"size": { | ||
"height": 112, | ||
"width": 271 | ||
}, | ||
"sizemode": "", | ||
"style": "Standard", | ||
"title": { | ||
"id": "", | ||
"text": "List files in a folder", | ||
"translatable": True | ||
} | ||
}) | ||
|
||
dir = RESULT.directory | ||
# change working directory to the selected directory | ||
os.chdir(dir) | ||
print('Files in directory', dir + ':') | ||
for filename in os.listdir(dir): | ||
if os.path.isdir(filename): | ||
print(' Folder:', filename) | ||
elif os.path.isfile(filename): | ||
base, ext = os.path.splitext(filename) | ||
print(' File:', filename, ' Base:', base, ' Extension:', ext) | ||
else: | ||
print(' Other:', filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import gom | ||
import os | ||
|
||
|
||
RESULT=gom.script.sys.execute_user_defined_dialog (dialog={ | ||
"content": [ | ||
[ | ||
{ | ||
"columns": 1, | ||
"default": "", | ||
"file_types": [ | ||
], | ||
"file_types_default": "", | ||
"limited": False, | ||
"name": "directory", | ||
"rows": 1, | ||
"selection_type": "directory", | ||
"title": { | ||
"id": "", | ||
"text": "Choose Folder", | ||
"translatable": True | ||
}, | ||
"tooltip": { | ||
"id": "", | ||
"text": "Click to select a folder", | ||
"translatable": True | ||
}, | ||
"type": "input::file" | ||
} | ||
] | ||
], | ||
"control": { | ||
"id": "OkCancel" | ||
}, | ||
"embedding": "", | ||
"position": "", | ||
"size": { | ||
"height": 112, | ||
"width": 271 | ||
}, | ||
"sizemode": "", | ||
"style": "Standard", | ||
"title": { | ||
"id": "", | ||
"text": "List files in a folder", | ||
"translatable": True | ||
} | ||
}) | ||
|
||
dir = RESULT.directory | ||
print('Files in directory tree below', dir + ':') | ||
for (basepath, subfolders, filenames) in os.walk(dir): | ||
print(' Files in directory', basepath + ':') | ||
for filename in filenames: | ||
base, ext = os.path.splitext(filename) | ||
print(' File:', filename, ' Base:', base, ' Extension:', ext) | ||
print(' -> Full path:', os.path.join(basepath, filename)) |
64 changes: 64 additions & 0 deletions
64
examples/FileSelectionAndFiltering/scripts/walkdir_import_scripts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import gom | ||
import os | ||
|
||
|
||
RESULT=gom.script.sys.execute_user_defined_dialog (dialog={ | ||
"content": [ | ||
[ | ||
{ | ||
"columns": 1, | ||
"default": "", | ||
"file_types": [ | ||
], | ||
"file_types_default": "", | ||
"limited": False, | ||
"name": "directory", | ||
"rows": 1, | ||
"selection_type": "directory", | ||
"title": { | ||
"id": "", | ||
"text": "Choose Folder", | ||
"translatable": True | ||
}, | ||
"tooltip": { | ||
"id": "", | ||
"text": "Klick to select a folder", | ||
"translatable": True | ||
}, | ||
"type": "input::file" | ||
} | ||
] | ||
], | ||
"control": { | ||
"id": "OkCancel" | ||
}, | ||
"embedding": "", | ||
"position": "", | ||
"size": { | ||
"height": 112, | ||
"width": 271 | ||
}, | ||
"sizemode": "", | ||
"style": "Standard", | ||
"title": { | ||
"id": "", | ||
"text": "List files in a folder", | ||
"translatable": True | ||
} | ||
}) | ||
|
||
dir = RESULT.directory | ||
for (basepath, subfolders, filenames) in os.walk(dir): | ||
for filename in filenames: | ||
base, ext = os.path.splitext(filename) | ||
if ext == '.py': | ||
scriptfile = os.path.join(basepath, filename) | ||
basename, _ = os.path.splitext(filename) | ||
gom.script.sys.import_script ( | ||
config_level='user', | ||
display_names=[basename], | ||
files=[scriptfile], | ||
names=['test.' + basename], | ||
replace_existing_scripts=True) |
69 changes: 69 additions & 0 deletions
69
examples/FileSelectionAndFiltering/scripts/walkdir_import_stl_pol.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import gom | ||
import os | ||
|
||
|
||
RESULT=gom.script.sys.execute_user_defined_dialog (dialog={ | ||
"content": [ | ||
[ | ||
{ | ||
"columns": 1, | ||
"default": "", | ||
"file_types": [ | ||
], | ||
"file_types_default": "", | ||
"limited": False, | ||
"name": "directory", | ||
"rows": 1, | ||
"selection_type": "directory", | ||
"title": { | ||
"id": "", | ||
"text": "Choose Folder", | ||
"translatable": True | ||
}, | ||
"tooltip": { | ||
"id": "", | ||
"text": "Klick to select a folder", | ||
"translatable": True | ||
}, | ||
"type": "input::file" | ||
} | ||
] | ||
], | ||
"control": { | ||
"id": "OkCancel" | ||
}, | ||
"embedding": "", | ||
"position": "", | ||
"size": { | ||
"height": 112, | ||
"width": 271 | ||
}, | ||
"sizemode": "", | ||
"style": "Standard", | ||
"title": { | ||
"id": "", | ||
"text": "List files in a folder", | ||
"translatable": True | ||
} | ||
}) | ||
|
||
dir = RESULT.directory | ||
for (basepath, subfolders, filenames) in os.walk(dir): | ||
for filename in filenames: | ||
base, ext = os.path.splitext(filename) | ||
if ext == '.stl': | ||
stlfile = os.path.join(basepath, filename) | ||
gom.script.sys.import_stl ( | ||
bgr_coding=True, | ||
files=[stlfile], | ||
import_mode='new_elements', | ||
length_unit='mm', | ||
stl_color_bit_set=False, | ||
target_type='mesh') | ||
if ext == '.pol': | ||
polfile = os.path.join(basepath, filename) | ||
gom.script.sys.import_pol ( | ||
files=[polfile], | ||
import_mode='new_elements') |