4
The module can be used from another module with:
6
from make_snapshot import make_snapshot
7
make_snapshot("file.stl", "image.png")
9
This other module then can be used with:
11
FreeCAD -c make_snapshot_from_file.py
15
FreeCADCmd make_snapshot_from_file.py
23
from PySide2 import QtGui
28
FreeCADGui.setupWithoutGUI()
29
except Exception as e:
33
def make_snapshot(input_file, output_file, size=48):
36
ext = os.path.splitext(input_file)[1][1:]
37
mod = FreeCAD.getImportType(ext)
39
print("Cannot load file {}".format(input_file))
43
module = importlib.import_module(mod[0])
44
module.open(input_file)
46
doc = FreeCAD.ActiveDocument
48
print("No active document")
52
nodes = [FreeCADGui.subgraphFromObject(obj) for obj in doc.Objects]
55
root = coin.SoSeparator()
56
light = coin.SoDirectionalLight()
57
cam = coin.SoOrthographicCamera()
64
axo = coin.SbRotation(-0.353553, -0.146447, -0.353553, -0.853553)
67
viewport = coin.SbViewportRegion(width, height)
68
cam.orientation.setValue(axo)
69
cam.viewAll(root, viewport)
70
off = FreeCADGui.SoQtOffscreenRenderer(width, height)
71
off.setBackgroundColor(1, 1, 1)
75
if QtGui.QGuiApplication.instance() is None:
76
app = QtGui.QGuiApplication(sys.argv)
79
off.writeToImage(output_file)