Read binary data off Windows clipboard, in Blender (python) -
edit: figured part out, see 2nd post below question.
(a little backstory here, skip ahead tldr :) )
i'm trying write few scripts blender help improve level creation workflow game play (natural selection 2). currently, move geometry level editor blender, have 1) save file editor .obj 2) import obj blender, , create changes. 3) export game's level format using exporter script wrote, , 4) re-open file in new instance of editor. 5) re-create level info new instance. 6) paste main level file. quite pain do, , quite discourages using tool @ major edits. thought improved workflow: 1) re-create info clipboard in editor 2) run importer script in blender load data. 3) run exporter script in blender save data. 4) paste original file. not cuts out 2 whole steps in tedious process, eliminates need files cluttering desktop. though, haven't found way read in clipboard info windows clipboard blender... @ to the lowest degree not without having go through elaborate installation steps (eg install python 3.1, install pywin32, move x,y,z blender directory, uninstall python 3.1... etc...)
tldr
i need help finding way write/read binary info to/from clipboard in blender. i'm not concerned cross-platform capability -- game tools windows only.
ideally -- though beggars can't choosers here -- solution not create hard install script layman. i'm (hopefully) not person going using this, i'd maintain installation instructions simple possible. if there's solution available in python standard library, that'd awesome!
things i've looked @ already/am looking @ now
pyperclip -- plaintext only. need able read binary info off clipboard.
pywin32 -- kept getting missing dll file errors, i'm sure i'm doing wrong. need take stab @ this, steps had take pretty involved (see lastly sentence above tldr section :) )
tkinter -- didn't read far 1 seemed read plain-text.
ctypes -- discovered in process of writing post. looks scary hell, i'll give shot.
welp... new record me (posting question , finding answer).
for interested, found this: how read text (windows) clipboard python?
it's i'm after... sort of. used code jumping-off point.
instead of cf_text = 1
i used cf_spark = user32.registerclipboardformatw("application/spark editor")
here's got function name from: http://msdn.microsoft.com/en-us/library/windows/desktop/ms649049(v=vs.85).aspx
the 'w' there because whatever reason, blender doesn't see plain-old "registerclipboardformat" function, have utilize "...formatw" or "...formata". not sure why is. if knows, i'd love hear it! :)
anyways, haven't gotten working yet: still need find way break "data" object bytes can work it, shouldn't hard.
scratch that, it's giving me quite bit of difficulty.
here's code
from ctypes import * binascii import hexlify kernel32 = windll.kernel32 user32 = windll.user32 user32.openclipboard(0) cf_spark = user32.registerclipboardformatw("application/spark editor") if user32.isclipboardformatavailable(cf_spark): info = user32.getclipboarddata(cf_spark) data_locked = kernel32.globallock(data) print(data_locked) text = c_char_p(data_locked) print(text) print(hexlify(text)) kernel32.globalunlock(data_locked) else: print('no spark info in clipboard!') user32.closeclipboard() there aren't errors, output wrong. line print(hexlify(text)) yields b'e0cb0c1100000000', when should getting that's 946 bytes long, first 4 of should 01 00 00 00. (here's clipboard data, saved out insideclipboard .bin file: https://www.dropbox.com/s/bf8yhi1h5z5xvzv/testlevel.bin?dl=1 )
python windows binary clipboard blender
No comments:
Post a Comment