Copy Text to Clipboard example
This example I make a dictionary and copy to clipboard. I also gather a frame range from files on disk.
#needed: name, path, start, end
import hou, os
from pathlib import Path
def getinfo():
pathname = hou.ui.selectFile(collapse_sequences=True)
filename = Path(pathname.split(".")[0])
parent = filename.parent
#get frame range
filenames = [file.name.split(".")[-2] for file in parent.iterdir() if file.is_file()]
start = min(int(i) for i in filenames)
end = max(int(i) for i in filenames)
#reformatting stuff
name = str(filename).split("/")[-1]
path = str(filename)+"."
return name, path, start, end
def wrangle():
wranglenode = hou.selectedNodes[0]
#assign variables to function so we can use them globally
name, path, start, end = getinfo()
#format stuff
q = '"'
textForWrangle = f'dict {name}; \n {name}[\'name\'] = {q}{name}{q}; \n {name}[\'path\'] = {q}{path}{q}; \n {name}[\'startFrame\'] = {start}; \n {name}[\'endFrame\'] = {end}; \n append(chars,{name}); '
print(textForWrangle)
#copy to clipboard
hou.ui.copyTextToClipboard(textForWrangle)
hou.ui.displayMessage(title="Copied", text=f"Here is what was copied to clipboard: {textForWrangle} \n")
No Comments