{"id":114,"date":"2009-10-20T14:04:45","date_gmt":"2009-10-20T13:04:45","guid":{"rendered":"http:\/\/david.buttress.me.uk\/blog\/?p=114"},"modified":"2009-10-22T12:52:09","modified_gmt":"2009-10-22T11:52:09","slug":"scripted-clipboard-access-in-maya","status":"publish","type":"post","link":"http:\/\/david.buttress.me.uk\/blog\/?p=114","title":{"rendered":"Scripted Clipboard Access in Maya"},"content":{"rendered":"<p>I recently had a situation where we needed to access the data in the clipboard from within a Mel script; in straight mel\/python there is no way to access this data (I guess because Maya is cross platform, and clipboard support is OS specific). But by using the <a href=\"http:\/\/david.buttress.me.uk\/blog\/?p=122\">pyWin32 extensions<\/a> we can get access to the clipboard in Windows.<\/p>\n<p>I&#8217;ve written two very simple mel functions that allow you to copy and paste a string to the clipboard directly.<\/p>\n<p><strong>clipboardCopy( string )<\/strong> will put the string onto the clipboard.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nglobal proc clipboardCopy( string $text )\r\n{\r\n\t\/\/install pyWin32Extensions, needed to access the clipboard\r\n\tpyWin32Extensions();\r\n\r\n\tpython( &quot;import win32clipboard&quot; );\r\n\r\n\tpython( &quot;win32clipboard.OpenClipboard()\\nwin32clipboard.EmptyClipboard()\\nwin32clipboard.SetClipboardText('&quot; + $text + &quot;')\\nwin32clipboard.CloseClipboard()&quot; );\r\n}\r\n<\/pre>\n<p><strong>clipboardPaste()<\/strong> will return the conents of the clipboard.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nglobal proc string clipboardPaste()\r\n{\r\n\t\/\/install pyWin32Extensions, needed to access the clipboard\r\n\tpyWin32Extensions();\r\n\r\n\tpython( &quot;import win32clipboard&quot; );\r\n\r\n\tpython( &quot;win32clipboard.OpenClipboard()\\nd = win32clipboard.GetClipboardData( win32clipboard.CF_TEXT )\\nwin32clipboard.CloseClipboard()&quot; );\r\n\tstring $clipboardText = python( &quot;d&quot; );\r\n\r\n\treturn $clipboardText;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I recently had a situation where we needed to access the data in the clipboard from within a Mel script; in straight mel\/python there is no way to access this data (I guess because Maya is cross platform, and clipboard support is OS specific). But by using the pyWin32 extensions we can get access to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,12],"tags":[],"_links":{"self":[{"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/114"}],"collection":[{"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=114"}],"version-history":[{"count":7,"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions"}],"predecessor-version":[{"id":184,"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions\/184"}],"wp:attachment":[{"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}