Browse Source

Ajout de l'export PDF des fichiers contenant un dessin TechDraw

master
Youen 1 year ago
parent
commit
a883c20376
  1. 13
      tools/export-all-parts.py
  2. 3
      tools/generate-2d-drawings.py

13
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):

3
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

Loading…
Cancel
Save