-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportPNG.FCMacro
30 lines (21 loc) · 1.03 KB
/
ExportPNG.FCMacro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
from datetime import datetime
def exportViewToPNG():
'''Exports the current view to a PNG suitable for printing on A4 or Letter.
The filename will be e.g. MyProject-view.png in the project directory.'''
# Reference: http://www.freecadweb.org/wiki/index.php?title=Std_ViewScreenShot
# Create an image which fits on an A4 or Letter page at 300dpi, landscape
width = 11 * 300 # inside letter
height = int(8.26 * 300) # inside A4
doc = FreeCAD.ActiveDocument
if not doc.FileName:
FreeCAD.Console.PrintError('Must save project first\n')
return
docDir, docFilename = os.path.split(doc.FileName)
filePrefix = os.path.splitext(docFilename)[0]
dt=datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
filename = filePrefix + '-' + dt + '.png'
filePath = os.path.join(docDir, 'img/', filename)
FreeCAD.Console.PrintMessage("Saving view to %s\n" % filePath)
FreeCADGui.ActiveDocument.ActiveView.saveImage(filePath.encode("utf-8"), width, height, 'White')
exportViewToPNG()