Skip to content

Commit

Permalink
Merge pull request #2 from ZeissIQS/file-selection-and-filtering
Browse files Browse the repository at this point in the history
Copied from GOM Connect, updated dialog content format
  • Loading branch information
mprinkezs authored Feb 5, 2024
2 parents 70f6a65 + 99ea8c8 commit 1dda0dd
Show file tree
Hide file tree
Showing 8 changed files with 671 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/FileSelectionAndFiltering/doc/README.md
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.
296 changes: 296 additions & 0 deletions examples/FileSelectionAndFiltering/license/license.txt

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions examples/FileSelectionAndFiltering/scripts/listdir_categories.py
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 examples/FileSelectionAndFiltering/scripts/listdir_dialog.py
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)
63 changes: 63 additions & 0 deletions examples/FileSelectionAndFiltering/scripts/listdir_ext.py
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)
59 changes: 59 additions & 0 deletions examples/FileSelectionAndFiltering/scripts/walkdir_ext.py
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))
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)
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')

0 comments on commit 1dda0dd

Please sign in to comment.