Cut and Paste IDL Graphics Windows
QUESTION: In very old Windows versions of IDL you used to be able to cut and paste graphics windows from IDL into Powerpoint. This is no longer available, it appears. Is there some other way to do this?
ANSWER: Yes, it is possible. Here is a solution that uses the IDLgrClipboard object for the cutting and pasting operation. The program is named Clipboard. It accepts a single argument, which is the window index number of the graphics window you wish to copy to the clipboard. If you don't supply an argument, the current graphics window will be used. So, for example, you could write code like this:
IDL> Window, XSize=400, YSize=400 IDL> Plot, Findgen(11) IDL> Clipboard
Now the contents of the clipboard can be pasted into another application. I have successfully pasted the contents of IDL graphics windows into Framemaker, Powerpoint, Photoshop, Excel, and Word documents.
The code is very simple, as I show you below.
PRO Clipboard, windowIndex ; This procedure copies the window identified by the ; window index number (or the current window if an index ; number is not provided) to the clipboard. IF N_Elements(windowIndex) EQ 0 THEN windowIndex = !D.Window ; Is this a valid window? IF windowIndex LT 0 THEN BEGIN ok = Dialog_Message('No current window to copy. Returning...') RETURN ENDIF ; Catch window setting errors. Catch, error IF error NE 0 THEN BEGIN Catch, /Cancel ok = Dialog_Message('Specified window is unavailable: ' + $ StrTrim(windowIndex, 2) + '. Returning...') WSet, thisWindow RETURN ENDIF ; Set active window. thisWindow = !D.Window WSet, windowIndex Catch, /Cancel ; Take a snapshot of window. Pay attention to visual depth. Device, Get_Visual_Depth=thisDepth IF thisDepth GT 8 THEN BEGIN snapshot = TVRD(True=1) snapshot = Color_Quan(snapshot, 1, r, g, b) ENDIF ELSE BEGIN snapshot = TVRD() TVLCT, r, g, b, /Get ENDELSE s = Size(snapshot, /Dimensions) ; Create an object graphics image and hierarchy. palette = Obj_New('IDLgrPalette', r, g, b) image = Obj_New('IDLgrImage', snapshot, Palette=palette) model = Obj_New('IDLgrModel') model->Add, image thisView = Obj_New('IDLgrView', ViewPlane_Rect=[0,0,s,s]) thisView->Add, model ; Create a clipboard theClipboard = Obj_New('IDLgrClipboard', Color_Model=1, $ Dimensions=[s, s], N_Colors=!D.Table_Size, $ Resolution=[1.0/!D.X_PX_CM, 1.0/!D.Y_PX_CM], $ Palette=palette) ; Copy the snapshot to the clipboard. theClipboard->Draw, thisView ; Destroy the objects. Obj_Destroy, palette Obj_Destroy, model Obj_Destroy, thisView Obj_Destroy, theClipboard ; Restore the current window. IF thisWindow NE -1 THEN WSet, thisWindow END
Last Updated 24 October 2001