From a883c20376d52fe7de5b89f98c3808415fb3a3f4 Mon Sep 17 00:00:00 2001 From: Youen Date: Fri, 3 Nov 2023 18:30:43 +0100 Subject: [PATCH] Ajout de l'export PDF des fichiers contenant un dessin TechDraw --- tools/export-all-parts.py | 13 +++++++++++++ tools/generate-2d-drawings.py | 3 +++ 2 files changed, 16 insertions(+) diff --git a/tools/export-all-parts.py b/tools/export-all-parts.py index 3521202..0245503 100644 --- a/tools/export-all-parts.py +++ b/tools/export-all-parts.py @@ -8,10 +8,12 @@ import vspt_freecad import FreeCAD as App import Import import ImportGui +import TechDrawGui project_folder = os.getcwd() output_folder = project_folder + '/dist/STEP' assemblies_output_folder = project_folder + '/dist/FCStd' +drawings_output_folder = project_folder + '/dist/PDF' def convert_file(file_name, output_format): doc = App.open(project_folder + '/' + file_name) @@ -70,6 +72,17 @@ def convert_file(file_name, output_format): else: Import.export([main_object], output_path) + # Export 2D drawing + page_name = doc.Name + '_Drawing' + drawing_page = doc.getObject(page_name) + if drawing_page is not None: + drawing_output_path = drawings_output_folder + '/' + os.path.dirname(file_name) + '/' + Path(file_name).stem + '.pdf' + drawing_output_dir = os.path.dirname(drawing_output_path) + if not os.path.exists(drawing_output_dir): + os.makedirs(drawing_output_dir) + drawing_page.ViewObject.Visibility = True + TechDrawGui.export([drawing_page], drawing_output_path) + vspt_freecad.close_all_docs() def export_assembly(doc, file_name, output_format): diff --git a/tools/generate-2d-drawings.py b/tools/generate-2d-drawings.py index 9a1550b..e6cd381 100644 --- a/tools/generate-2d-drawings.py +++ b/tools/generate-2d-drawings.py @@ -203,6 +203,7 @@ async def generate_2d_drawing(file_name): def addDimension(edgeA, edgeB, posY): dim = doc.addObject('TechDraw::DrawViewDimension','Dimension') dim.Type = 'DistanceX' + dim.FormatSpec = '%.1f' dim.References2D = [(view, (getFeatureName(edgeA), getFeatureName(edgeB)))] visibleEdgeA = visibleEdges[edges.index(edgeA)] visibleEdgeB = visibleEdges[edges.index(edgeB)] @@ -214,6 +215,7 @@ async def generate_2d_drawing(file_name): if abs(edgeB.BoundBox.XLength - 6.5) > 0.01: dim = doc.addObject('TechDraw::DrawViewDimension','Dimension') dim.Type = 'Diameter' + dim.FormatSpec = '%.1f' dim.References2D = [(view, ('Edge'+str(edges.index(edgeB)),))] dim.X = visibleEdgeB.BoundBox.Center.x + 6.0 dim.Y = -6.0 @@ -222,6 +224,7 @@ async def generate_2d_drawing(file_name): if abs(edgeB.BoundBox.Center.y) > 0.01 and lowestEdgeName != '': dim = doc.addObject('TechDraw::DrawViewDimension','Dimension') dim.Type = 'DistanceY' + dim.FormatSpec = '%.1f' dim.References2D = [(view, (getFeatureName(edgeB),lowestEdgeName))] dim.X = visibleEdgeB.BoundBox.Center.x + 2.0 dim.Y = -6.0