Created
September 15, 2016 10:21
-
-
Save mario52a/9ac9d51d0d419b7fce41f569ef59c75a to your computer and use it in GitHub Desktop.
Macro will copy the contents of the 3D view to the clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import PySide | |
from PySide.QtGui import * | |
from PySide import QtGui ,QtCore | |
from PySide import QtOpenGL | |
#from gimpfu import * | |
__title__ = "Macro_Copy3DViewToClipboard" | |
__author__ = "Mario52" | |
__url__ = "http://www.freecadweb.org/index-fr.html" | |
__version__ = "00.01" | |
__date__ = "14/09/2016" | |
class ViewObserver: | |
print "run FCGrab .." | |
def logPosition(self, info): | |
import tempfile | |
import os | |
from PySide import QtGui | |
pos = info["Key"] | |
if pos.upper() == "G": | |
pos = "" | |
mw=Gui.getMainWindow() | |
gl=mw.findChildren(QtOpenGL.QGLWidget) | |
glw=gl[0] # just use the first element | |
originalsize = glw.size() # originalsize SubWindow | |
print "originalsize : ",originalsize.width(),", ", originalsize.height() | |
glw.resize(640, 480) # reduce the SubWindow | |
glw.show() | |
Gui.SendMsgToActiveView("ViewFit") | |
print "resize in : ",glw.frameGeometry().width()," ",glw.frameGeometry().height() | |
i=glw.grabFrameBuffer() | |
cb=QtGui.qApp.clipboard() | |
cb.setImage(i) | |
glw.resize(originalsize.width(), originalsize.height()) # restore originalsize SubWindow | |
print "Grab" | |
if (pos.upper() == "Q"): | |
v.removeEventCallback("SoKeyboardEvent",c) | |
print "End FCGrab" | |
v=Gui.activeDocument().activeView() | |
o = ViewObserver() | |
c = v.addEventCallback("SoKeyboardEvent",o.logPosition) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This macro utility is intended for the use of the program FreeCAD http://www.freecadweb.org/
The icon for your toolbar, it is to place in your macros directory (in the same location of the macro)
rename the image in Macro_Copy3DViewToClipboard.png