From e1ff6d83e7dea61331e7061071249b338a034a95 Mon Sep 17 00:00:00 2001 From: Youen Date: Fri, 20 Jan 2023 18:55:38 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20d'un=20script=20permettant=20d'exporter?= =?UTF-8?q?=20toutes=20les=20pi=C3=A8ces=20au=20format=20STEP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/export-all-parts.py | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tools/export-all-parts.py diff --git a/tools/export-all-parts.py b/tools/export-all-parts.py new file mode 100644 index 0000000..84e53f4 --- /dev/null +++ b/tools/export-all-parts.py @@ -0,0 +1,72 @@ +freecad_install_path = '/home/youen/dev/FreeCAD-asm3-Daily-Conda-Py3.10-20221128-glibc2.12-x86_64' + +import sys +sys.path.insert(0,freecad_install_path + '/usr/lib') + +from pathlib import Path + +import FreeCAD as App +import Import + +script_folder = os.path.dirname(__file__) +project_folder = os.path.realpath(script_folder + '/..') +output_folder = project_folder + '-STEP' + +def convert_file(file_name, output_format): + doc = App.open(project_folder + '/' + file_name) + + root_objects = [] + main_object = None + + for obj in doc.Objects: + if len(obj.Parents) == 0: + root_objects.append(obj) + if obj.Label == doc.Name: + main_object = obj + + if main_object is None and len(root_objects) == 1: + main_object = root_objects[0] + + if main_object is None: + raise Exception("Can't find main object in file " + file_name) + + secondary_objects = [] + code_obj = doc.getObjectsByLabel('Code_Tube_Draft') + if len(code_obj) == 1: + code_obj = code_obj[0] + #code_obj.Label = 'Code_Tube' + #secondary_objects.append(code_obj) + + # engrave code on tube + code_pocket = main_object.newObjectAt('PartDesign::Pocket','Pocket', [code_obj]) + code_pocket.Profile = code_obj + code_pocket.Length = 0.2 + code_pocket.recompute() + main_object.recompute() + + if len(secondary_objects) > 0: + group = doc.addObject('App::Part', 'Groupe') + group.addObject(main_object) + for obj in secondary_objects: + group.addObject(obj) + main_object = group + + output_path = output_folder + '/' + os.path.dirname(file_name) + '/' + Path(file_name).stem + '.' + output_format + output_dir = os.path.dirname(output_path) + if not os.path.exists(output_dir): + os.makedirs(output_dir) + + Import.export([main_object], output_path) + +folders = [ + 'chaudronnerie', + 'tubes' +] + +for folder in folders: + files = os.listdir(project_folder + '/' + folder) + for source_file in files: + source_path = folder + '/' + source_file + print(source_path) + convert_file(source_path, 'step') +