using houdini`s timeline callback , just create a new shelf tool and copy and paste my code
this tool works as toggle mode . click to activate , click again to deactivate
Code :
import hou
chrysl666BG_padding = 0
#CREATE BG
def updateBG(event_type,frame):
#create initial vars
imagePath=""
strFrame = str(frame)
#get editor and BGimage infos
editorHolder = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)
BGLIST = editorHolder.backgroundImages()
#if BG image is not created -- do create
if(len(BGLIST) < 1 ):
#start holders
imageHolder = hou.NetworkImage()
imagePath = hou.ui.selectFile(start_directory="HIP" , title = "SELECT FRAMES ")
# check padzeros
pathParse = imagePath.rsplit(".",2)
if( len(pathParse[1]) > 2 ):
global chrysl666BG_padding
chrysl666BG_padding = int(pathParse[1][2])
strFrame = str(frame).zfill(chrysl666BG_padding) # apply padding
# build path string
newPath = pathParse[0]+"."+strFrame+"."+pathParse[2]
# apply Background Image
imageHolder.setPath(newPath)
imageHolder.setRect(hou.BoundingRect(0, 0, 5, 5))
editorHolder.setBackgroundImages([imageHolder])
else: # BG image is already created
#starts holders
imageHolder = BGLIST[0]
imagePath = imageHolder.path()
#chack padzeros
pathParse = imagePath.rsplit(".",2)
#padding = len(pathParse[1])
global chrysl666BG_padding
strFrame = str(frame).zfill(chrysl666BG_padding) # apply padding
# build path string
newPath = pathParse[0]+"."+strFrame+"."+pathParse[2]
# apply Background Image
imageHolder.setPath(newPath)
editorHolder.setBackgroundImages([imageHolder])
#check for playbar events when tool is clicked
events = hou.playbar.eventCallbacks()
if(len(events) <1):
#if not events, create it
updateBG(0,hou.intFrame())
hou.ui.displayMessage("BG IMAGE CREATED")
hou.playbar.addEventCallback(updateBG)
else:
# events exist delete it
hou.playbar.clearEventCallbacks()
hou.ui.displayMessage("BG IMAGE EVENT DELETED")
Nenhum comentário:
Postar um comentário