From 334b3c5762517e89e4ba9cb147aacd61e937495b Mon Sep 17 00:00:00 2001 From: Youen Date: Wed, 3 May 2023 15:33:43 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20du=20script=20d'export=20st?= =?UTF-8?q?ep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- tools/export-all-parts.py | 41 ++++++++++++++++++++++++--------------- tools/export-all-parts.sh | 10 +++++++++- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 6f80546..1c19a3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.FCStd1 _local - +__pycache__/ diff --git a/tools/export-all-parts.py b/tools/export-all-parts.py index ca6c16a..30a18ed 100644 --- a/tools/export-all-parts.py +++ b/tools/export-all-parts.py @@ -5,8 +5,6 @@ import FreeCAD as App import Import import ImportGui -#script_folder = os.path.dirname(__file__) -#project_folder = os.path.realpath(script_folder + '/..') project_folder = os.getcwd() output_folder = project_folder + '-STEP' @@ -56,7 +54,11 @@ def convert_file(file_name, output_format): if not os.path.exists(output_dir): os.makedirs(output_dir) - Import.export([main_object], output_path) + if output_format.lower() == 'stpz': + import stepZ + stepZ.export([main_object], output_path) + else: + Import.export([main_object], output_path) # close all documents while len(FreeCAD.listDocuments().values()) > 0: @@ -99,26 +101,33 @@ def convert_assembly(file_name, output_format): if not os.path.exists(output_dir): os.makedirs(output_dir) - ImportGui.export([main_object], output_path) + if output_format.lower() == 'stpz': + import stepZ + stepZ.export([main_object], output_path) + else: + ImportGui.export([main_object], output_path) # close all documents while len(FreeCAD.listDocuments().values()) > 0: FreeCAD.closeDocument(list(FreeCAD.listDocuments().values())[0].Name) -folders = [ - 'chaudronnerie', - 'tubes' -] +try: + folders = [ + 'chaudronnerie', + 'tubes' + ] -for folder in folders: - files = os.listdir(project_folder + '/' + folder) - for source_file in files: - if not source_file.endswith('.FCStd'): continue - source_path = folder + '/' + source_file - print(source_path) - convert_file(source_path, 'step') + for folder in folders: + files = os.listdir(project_folder + '/' + folder) + for source_file in files: + if not source_file.endswith('.FCStd'): continue + source_path = folder + '/' + source_file + print(source_path) + convert_file(source_path, 'step') -convert_assembly('vheliotech.FCStd', 'step') + convert_assembly('vheliotech.FCStd', 'step') +except: + pass # exit FreeCAD FreeCADGui.getMainWindow().close() diff --git a/tools/export-all-parts.sh b/tools/export-all-parts.sh index 58b1494..7b6d334 100755 --- a/tools/export-all-parts.sh +++ b/tools/export-all-parts.sh @@ -1,4 +1,12 @@ #!/bin/bash + +set -e + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) cd $SCRIPT_DIR/.. -~/dev/FreeCAD-asm3-Daily-Conda-Py3.10-20221128-glibc2.12-x86_64.AppImage tools/export-all-parts.py + +# Check script syntax before starting freecad +python3 -m py_compile tools/export-all-parts.py + +# Start freecad to run the script. We must start freecad with GUI (otherwise we can't export colors). We start it hidden in a virtual framebuffer (xvfb) so that it can run cleanly in the background. +xvfb-run ~/dev/FreeCAD-asm3-Daily-Conda-Py3.10-20221128-glibc2.12-x86_64.AppImage tools/export-all-parts.py