| |
|
| |
|
| |
|
| |
|
| |
|
| | """
|
| | The module can be executed with:
|
| | FreeCAD -P <path_to_file> Automation.py
|
| | FreeCADCmd -P <path_to_file> Automation.py
|
| | """
|
| |
|
| | import FreeCAD, Part
|
| | import os
|
| | import tempfile
|
| |
|
| | def makeSnapshotWithGui():
|
| | from PySide import QtGui
|
| | import FreeCADGui
|
| |
|
| | def getMainWindow():
|
| | toplevel = QtGui.QApplication.topLevelWidgets()
|
| | for i in toplevel:
|
| | if i.metaObject().className() == "Gui::MainWindow":
|
| | return i
|
| | raise RuntimeError("No main window found")
|
| |
|
| | mw=getMainWindow()
|
| | mw.hide()
|
| |
|
| |
|
| |
|
| | obj=Part.makeCone(10,8,10)
|
| | doc = FreeCAD.newDocument()
|
| | Part.show(obj)
|
| |
|
| |
|
| | view = FreeCADGui.getDocument(doc.Name).activeView()
|
| | view.setAnimationEnabled(False)
|
| | view.viewAxometric()
|
| | view.fitAll()
|
| | view.saveImage('crystal.png',800,600,'Current')
|
| | FreeCAD.closeDocument(doc.Name)
|
| |
|
| | QtGui.QApplication.quit()
|
| |
|
| | def makeSnapshotWithoutGui():
|
| | from pivy import coin
|
| |
|
| |
|
| | box=Part.makeCone(10,8,10)
|
| | iv=box.writeInventor()
|
| |
|
| |
|
| | inp=coin.SoInput()
|
| | try:
|
| | inp.setBuffer(iv)
|
| | except Exception:
|
| | tempPath = tempfile.gettempdir()
|
| | fileName = tempPath + os.sep + "cone.iv"
|
| | file = open(fileName, "w")
|
| | file.write(iv)
|
| | file.close()
|
| | inp.openFile(fileName)
|
| |
|
| |
|
| | data = coin.SoDB.readAll(inp)
|
| | base = coin.SoBaseColor()
|
| | base.rgb.setValue(0.6,0.7,1.0)
|
| | data.insertChild(base,0)
|
| |
|
| |
|
| | root = coin.SoSeparator()
|
| | light = coin.SoDirectionalLight()
|
| | cam = coin.SoOrthographicCamera()
|
| | root.addChild(cam)
|
| | root.addChild(light)
|
| | root.addChild(data)
|
| |
|
| |
|
| | axo = coin.SbRotation(-0.353553, -0.146447, -0.353553, -0.853553)
|
| | viewport=coin.SbViewportRegion(400,400)
|
| | cam.orientation.setValue(axo)
|
| | cam.viewAll(root,viewport)
|
| | off=coin.SoOffscreenRenderer(viewport)
|
| | root.ref()
|
| | off.render(root)
|
| | root.unref()
|
| |
|
| |
|
| | off.writeToPostScript("crystal.ps")
|
| |
|
| |
|
| | if off.isWriteSupported("PNG"):
|
| | print("Save as PNG")
|
| | off.writeToFile("crystal.png","PNG")
|
| |
|
| | if FreeCAD.GuiUp:
|
| | makeSnapshotWithGui()
|
| | else:
|
| | makeSnapshotWithoutGui()
|
| |
|