Browse Source

Amélioration du script d'export step

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

2
.gitignore vendored

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

21
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,6 +54,10 @@ 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)
if output_format.lower() == 'stpz':
import stepZ
stepZ.export([main_object], output_path)
else:
Import.export([main_object], output_path) Import.export([main_object], output_path)
# close all documents # close all documents
@ -99,18 +101,23 @@ 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)
if output_format.lower() == 'stpz':
import stepZ
stepZ.export([main_object], output_path)
else:
ImportGui.export([main_object], output_path) 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:
folders = [
'chaudronnerie', 'chaudronnerie',
'tubes' '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
@ -118,7 +125,9 @@ for folder in folders:
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