forked from FreeCAD/FreeCAD-macros
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFoto.FCMacro
More file actions
66 lines (53 loc) · 1.41 KB
/
Foto.FCMacro
File metadata and controls
66 lines (53 loc) · 1.41 KB
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
66
# -*- coding: utf-8 -*-
# (c) microelly 2015
__Comment__ = ' creates a realsized 300 dpi foto of the selected part from top view'
__Web__ = ""
__Wiki__ = ""
__Icon__ = "AppHomePath/Mod/plugins/icons/camera-photo.png"
__Help__ = "select an object"
__Author__ = "microelly"
__Version__ = 0.1
__Status__ = 'alpha'
__Requires__ = ''
import FreeCAD
import FreeCADGui
def foto(fn='/tmp/fc_camera_out.jpg',width=150,height=100,x=0,y=0,res=300):
hi=height
dpi=300
dpmm=11.8110
if res <> 300:
dpmm *= 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
'''
cam += '\nposition ' +str(x) + ' ' + str(y) + ' 999\n '
cam += '\nheight ' + str(height) + '\n}\n\n'
FreeCADGui.activeDocument().activeView().setCamera(cam)
print(FreeCADGui.activeDocument().activeView().getCamera())
print ppx
print ppy
FreeCADGui.ActiveDocument.update()
FreeCADGui.activeDocument().activeView().saveImage(fn,ppx,ppy,'#ffffff')
import os
fn="/tmp/fc_foto6.jpg"
res=300
s=FreeCADGui.Selection.getSelection()
s0=s[0]
s0.ViewObject.LineWidth=1
b=s[0].Shape.BoundBox
px=0.5*(b.XMin+b.XMax)
py=0.5*(b.YMin+b.YMax)
width=b.XMax-b.XMin
height=b.YMax-b.YMin
foto(fn,width,height,px,py,res)
FreeCADGui.ActiveDocument.update()
os.system("eog "+ fn + "&")