View Full Version : storing whats in ctrl C as a string?

04 April 2009, 02:00 PM
anyone know if this is possible, i want to strore what has been copyed (Ctrl C) as a string variable, ive had a look though the docs and couldnt see anything, idealy i'd like to do this with mel :)

Robert Bateman
04 April 2009, 02:36 PM
The only way i'd know is to drop to the API to query standard Win32 clipboard funcs, and return the result via an MPxCommand. I'd doubt maya has any method to do this directly (though i may be wrong).

05 May 2009, 03:45 PM
I found a way to do access the clipboard using python, although you do need to install the pythonWin32 ( extensions which tie it to windows.

Once you've got them installed you can use this mel to put something on the clipboard:

string $text = "Whatever you want to copy to the clipboard";
python( "import win32clipboard" );
python( "win32clipboard.OpenClipboard()\nwin32clipboard.EmptyClipboard()\nwin32clipboard.SetClipboardText('" + $text + "')\nwin32clipboard.CloseClipboard()" );

and this mel to retrieve the data from the clipboard:

python( "import win32clipboard" );
python( "win32clipboard.OpenClipboard()\nd = win32clipboard.GetClipboardData(win32clipboard.CF_TEXT)\nwin32clipboard.CloseClipboard()" );
string $clipboardText = python( "d" );

*EDIT* For some reason there are spaces being added into the code! They're not there when I write the post though :( EmptyClipboard shouldn't have spaces, and CF_TEXT shouldn't have spaces.

CGTalk Moderation
05 May 2009, 03:45 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.