-
Notifications
You must be signed in to change notification settings - Fork 140
/
Foto.FCMacro
65 lines (54 loc) · 1.57 KB
/
Foto.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
# (c) microelly 2015
__Name__ = 'Foto'
__Comment__ = 'Creates a real sized 300-dpi foto of the selected part from top view'
__Author__ = 'microelly'
__Version__ = '0.1.0'
__Date__ = ''
__License__ = ''
__Web__ = ''
__Wiki__ = ''
__Icon__ = ''
__Help__ = 'Select an object'
__Status__ = 'alpha'
__Requires__ = ''
__Contact__ = 'https://forum.freecadweb.org/memberlist.php?mode=viewprofile&u=2364'
__Communication__ = ''
__Files__ = ''
import os
import FreeCADGui
def foto(fn='/tmp/fc_camera_out.jpg', width=150, height=100, x=0, y=0, res=300):
if res <= 0:
# TODO: add a warning about wrong res value.
res = 300
dpmm = 11.8110 * res / 300
ppy = int(dpmm * height)
ppx = int(dpmm * width)
y -= 1
cam = '''#Inventor V2.1 ascii
OrthographicCamera {{
viewportMapping ADJUST_CAMERA
orientation 1 0 0 0.001
nearDistance 0
farDistance 1000
aspectRatio 100
focalDistance 1
position {x} {y} 999
height {height}
}}
'''.format(x=x, y=y, height=height)
FreeCADGui.activeDocument().activeView().setCamera(cam)
FreeCADGui.ActiveDocument.update()
FreeCADGui.activeDocument().activeView().saveImage(fn, ppx, ppy, '#ffffff')
fn = "/tmp/fc_photo.jpg"
res = 300
sel = FreeCADGui.Selection.getSelection()
sel0 = sel[0]
sel0.ViewObject.LineWidth = 1
bbox = sel0.Shape.BoundBox
px = 0.5 * (bbox.XMin + bbox.XMax)
py = 0.5 * (bbox.YMin + bbox.YMax)
width = bbox.XMax - bbox.XMin
height = bbox.YMax - bbox.YMin
foto(fn, width, height, px, py, res)
os.system('xdg-open {}'.format(fn))