Macro Copy3DViewToClipboard: Difference between revisions

From FreeCAD Documentation
(new icon)
No edit summary
 
(20 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=Macro_Copy3DViewToClipboard|Name=Macro Copy3DViewToClipboard|Description=Copy contents of 3DView to clipboard|Author=Mario52}}
|Name=Macro Copy3DViewToClipboard
|Icon=Macro_Copy3DViewToClipboard.png
|Description=Macro will copy the contents of the 3D view to the clipboard in bitmap (BMP) image.<br/>Copying in Gimp is not possible. Gimp uses its own method for the copy function.
|Author=Mario52
|Version=00.01
|Date=2016-09-14
|FCVersion= <=0.17
|Download=[https://www.freecadweb.org/wiki/images/8/84/Macro_Copy3DViewToClipboard.png ToolBar Icon]
|Shortcut=G, Q
|SeeAlso=[[Macro_Snip|Macro Snip]] [[Image:Snip.png|24px]]<br/>[[Macro Screen Wiki|Macro Screen Wiki]] [[Image:Macro_Screen_Wiki.png|24px]]
}}


==Description== <!--T:2-->
==Description== <!--T:2-->


<!--T:6-->
Macro will copy the contents of the 3D view to the clipboard
Macro will copy the contents of the 3D view to the clipboard in bitmap (BMP) image. Copying in Gimp is not possible. Gimp uses its own method for the copy function.

</translate>
{{Codeextralink|https://gist.githubusercontent.com/mario52a/f5c3738f858f7b058897c6c235232cbe/raw/a10bc3b8789badc1e405541d4697d7286d9f0fd3/Macro_Copy3DViewToClipboard.FCMacro}}
<translate>


==How To Use== <!--T:3-->
==How To Use== <!--T:3-->


<!--T:7-->
*Run once to activate macro (the macro is loaded resident into the memory of the PC).
*Run once to activate macro (the macro is loaded resident into the memory of the PC).
*Press {{KEY|G}} to grab the contents of the 3d view and copy them to the clipboard.
*Press {{KEY|G}} to grab the contents of the 3d view and copy them to the clipboard.
*Press {{KEY|Q}} to quit.
*Press {{KEY|Q}} to quit.


==Discussion==<!--T:4-->
<!--T:13-->
PS: if you want other formats, modify the values of the line number 33 ex:
</translate>

line 33 : '''''glw.resize(640, 480) # reduce the SubWindow'''''

<translate>
<!--T:14-->
to
</translate>

line 33 : '''''glw.resize(800, 600) # reduce the SubWindow'''''

<translate>
==Discussion== <!--T:4-->


<!--T:8-->
See [http://forum.freecadweb.org/viewtopic.php?f=3&t=16731 forum-thread here].
See [http://forum.freecadweb.org/viewtopic.php?f=3&t=16731 forum-thread here].


==Code== <!--T:5-->
==Code== <!--T:5-->


<!--T:9-->
The icon for you toolbar [[File:Macro_Copy3DViewToClipboard.png]]
The icon for you toolbar [[File:Macro_Copy3DViewToClipboard.png]]


</translate>
'''Macro_Copy3DViewToClipboard.FCMacro'''


'''Macro_Copy3DViewToClipboard.FCMacro'''
{{Code|code=

{{MacroCode|code=
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import PySide
import PySide
Line 30: Line 66:
from PySide import QtOpenGL
from PySide import QtOpenGL
#from gimpfu import *
#from gimpfu import *

__title__ = "Macro_Copy3DViewToClipboard"
__title__ = "Macro_Copy3DViewToClipboard"
__author__ = "Mario52"
__author__ = "Mario52"
Line 74: Line 110:
v=Gui.activeDocument().activeView()
v=Gui.activeDocument().activeView()
o = ViewObserver()
o = ViewObserver()
c = v.addEventCallback("SoKeyboardEvent",o.logPosition)}}
c = v.addEventCallback("SoKeyboardEvent",o.logPosition)


}}

</translate>
{{clear}}
{{clear}}
<languages/>

Latest revision as of 12:20, 15 October 2022

Other languages:

Macro Copy3DViewToClipboard

Description
Macro will copy the contents of the 3D view to the clipboard in bitmap (BMP) image.
Copying in Gimp is not possible. Gimp uses its own method for the copy function.

Macro version: 00.01
Last modified: 2016-09-14
FreeCAD version: <=0.17
Download: ToolBar Icon
Author: Mario52
Author
Mario52
Download
ToolBar Icon
Links
Macro Version
00.01
Date last modified
2016-09-14
FreeCAD Version(s)
<=0.17
Default shortcut
G, Q
See also
Macro Snip
Macro Screen Wiki

Description

Macro will copy the contents of the 3D view to the clipboard in bitmap (BMP) image. Copying in Gimp is not possible. Gimp uses its own method for the copy function.

Temporary code for external macro link. Do not use this code. This code is used exclusively by Addon Manager. Link for optional manual installation: Macro


# This code is copied instead of the original macro code
# to guide the user to the online download page.
# Use it if the code of the macro is larger than 64 KB and cannot be included in the wiki
# or if the RAW code URL is somewhere else in the wiki.

from PySide import QtGui, QtCore

diag = QtGui.QMessageBox(QtGui.QMessageBox.Information,
    "Information",
    "This macro must be downloaded from this link\n"
    "\n"
    "https://gist.githubusercontent.com/mario52a/f5c3738f858f7b058897c6c235232cbe/raw/a10bc3b8789badc1e405541d4697d7286d9f0fd3/Macro_Copy3DViewToClipboard.FCMacro" + "\n"
    "\n"
    "Quit this window to access the download page")

diag.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
diag.setWindowModality(QtCore.Qt.ApplicationModal)
diag.exec_()

import webbrowser 
webbrowser.open("https://gist.githubusercontent.com/mario52a/f5c3738f858f7b058897c6c235232cbe/raw/a10bc3b8789badc1e405541d4697d7286d9f0fd3/Macro_Copy3DViewToClipboard.FCMacro")


How To Use

  • Run once to activate macro (the macro is loaded resident into the memory of the PC).
  • Press G to grab the contents of the 3d view and copy them to the clipboard.
  • Press Q to quit.

PS: if you want other formats, modify the values of the line number 33 ex:

line 33 : glw.resize(640, 480) # reduce the SubWindow

to

line 33 : glw.resize(800, 600) # reduce the SubWindow

Discussion

See forum-thread here.

Code

The icon for you toolbar


Macro_Copy3DViewToClipboard.FCMacro

# -*- 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)