diff --git a/.gitignore b/.gitignore index 1c19a3a..9705b9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.FCStd1 _local __pycache__/ +/dist/ diff --git a/tools/export-all-parts.py b/tools/export-all-parts.py index 30a18ed..c819107 100644 --- a/tools/export-all-parts.py +++ b/tools/export-all-parts.py @@ -6,7 +6,12 @@ import Import import ImportGui project_folder = os.getcwd() -output_folder = project_folder + '-STEP' +output_folder = project_folder + '/dist/STEP' +assemblies_output_folder = project_folder + '/dist/FCStd' + +def close_all_docs(): + while len(FreeCAD.listDocuments().values()) > 0: + FreeCAD.closeDocument(list(FreeCAD.listDocuments().values())[0].Name) def convert_file(file_name, output_format): doc = App.open(project_folder + '/' + file_name) @@ -60,12 +65,10 @@ def convert_file(file_name, output_format): else: Import.export([main_object], output_path) - # close all documents - while len(FreeCAD.listDocuments().values()) > 0: - FreeCAD.closeDocument(list(FreeCAD.listDocuments().values())[0].Name) + close_all_docs() def convert_assembly(file_name, output_format): - print(file_name) + print("Exporting assembly " + file_name + "...") doc = App.open(project_folder + '/' + file_name) @@ -107,9 +110,17 @@ def convert_assembly(file_name, output_format): else: ImportGui.export([main_object], output_path) - # close all documents - while len(FreeCAD.listDocuments().values()) > 0: - FreeCAD.closeDocument(list(FreeCAD.listDocuments().values())[0].Name) + close_all_docs() + +def export_configuration(doc, config_name, output_filename): + print('Generating assembly for configuration '+config_name+'...') + + Gui.Selection.clearSelection() + Gui.Selection.addSelection('vheliotech','Model','Configurations.'+doc.getObjectsByLabel(config_name)[0].Name+'.') + Gui.runCommand('Asm4_applyConfiguration') + Gui.Selection.clearSelection() + + doc.saveAs(assemblies_output_folder + '/' + output_filename + '.FCStd') try: folders = [ @@ -126,9 +137,18 @@ try: convert_file(source_path, 'step') convert_assembly('vheliotech.FCStd', 'step') -except: - pass + + '''doc = App.open(project_folder + '/vheliotech.FCStd') + export_configuration(doc, 'Config_Integrale', 'vheliotech-config-integrale') + export_configuration(doc, 'Config_Solaire', 'vheliotech-config-solaire') + export_configuration(doc, 'Config_Motorisee', 'vheliotech-config-motorisee') + export_configuration(doc, 'Config_Basique', 'vheliotech-config-basique') + close_all_docs()''' + +except Exception as e: + print(e) # exit FreeCAD +close_all_docs() FreeCADGui.getMainWindow().close() diff --git a/tools/export-all-parts.sh b/tools/export-all-parts.sh index 7b6d334..cc116e8 100755 --- a/tools/export-all-parts.sh +++ b/tools/export-all-parts.sh @@ -2,11 +2,20 @@ set -e +# Set the path to your FreeCAD executable here +FREECAD=~/dev/FreeCAD-asm3-Daily-Conda-Py3.10-20221128-glibc2.12-x86_64.AppImage + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) cd $SCRIPT_DIR/.. +rm -rf ./dist + # Check script syntax before starting freecad python3 -m py_compile tools/export-all-parts.py +# Export all versioned files +mkdir -p dist/FCStd +git archive HEAD . | tar -x -C dist/FCStd + # 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 +xvfb-run $FREECAD tools/export-all-parts.py diff --git a/vheliotech.FCStd b/vheliotech.FCStd index 759fa80..2e3b33d 100644 Binary files a/vheliotech.FCStd and b/vheliotech.FCStd differ