Browse Source

Amélioration du script d'export step

Youen 2 years ago
parent
commit
334b3c5762
  1. 2
      .gitignore
  2. 41
      tools/export-all-parts.py
  3. 10
      tools/export-all-parts.sh

2
.gitignore vendored

@ -1,3 +1,3 @@
*.FCStd1 *.FCStd1
_local _local
__pycache__/

41
tools/export-all-parts.py

@ -5,8 +5,6 @@ import FreeCAD as App
import Import import Import
import ImportGui import ImportGui
#script_folder = os.path.dirname(__file__)
#project_folder = os.path.realpath(script_folder + '/..')
project_folder = os.getcwd() project_folder = os.getcwd()
output_folder = project_folder + '-STEP' output_folder = project_folder + '-STEP'
@ -56,7 +54,11 @@ def convert_file(file_name, output_format):
if not os.path.exists(output_dir): if not os.path.exists(output_dir):
os.makedirs(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 # close all documents
while len(FreeCAD.listDocuments().values()) > 0: while len(FreeCAD.listDocuments().values()) > 0:
@ -99,26 +101,33 @@ def convert_assembly(file_name, output_format):
if not os.path.exists(output_dir): if not os.path.exists(output_dir):
os.makedirs(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 # close all documents
while len(FreeCAD.listDocuments().values()) > 0: while len(FreeCAD.listDocuments().values()) > 0:
FreeCAD.closeDocument(list(FreeCAD.listDocuments().values())[0].Name) FreeCAD.closeDocument(list(FreeCAD.listDocuments().values())[0].Name)
folders = [ try:
'chaudronnerie', folders = [
'tubes' 'chaudronnerie',
] 'tubes'
]
for folder in folders: for folder in folders:
files = os.listdir(project_folder + '/' + folder) files = os.listdir(project_folder + '/' + folder)
for source_file in files: for source_file in files:
if not source_file.endswith('.FCStd'): continue if not source_file.endswith('.FCStd'): continue
source_path = folder + '/' + source_file source_path = folder + '/' + source_file
print(source_path) print(source_path)
convert_file(source_path, 'step') convert_file(source_path, 'step')
convert_assembly('vheliotech.FCStd', 'step') convert_assembly('vheliotech.FCStd', 'step')
except:
pass
# exit FreeCAD # exit FreeCAD
FreeCADGui.getMainWindow().close() FreeCADGui.getMainWindow().close()

10
tools/export-all-parts.sh

@ -1,4 +1,12 @@
#!/bin/bash #!/bin/bash
set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR/.. 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

Loading…
Cancel
Save