top of page

Save to Gallery Shelf Tool

  • 作家相片: Admin
    Admin
  • 2021年4月9日
  • 讀畢需時 2 分鐘

This tool is used to save the selected node to gallery quickly with username, category, and name. It also allows you to overwrite the existing gallery entry.


import os, time

def globalUser():
 if os.getenv("USERNAME").lower() == "jonnyw":
 return "JYW"
 else:
 return os.getenv("USER").upper()

def galleryFilePath():
 # Create the file path
    hpath   = os.getenv("HOUDINI_USER_PREF_DIR")
    filename= "%s_gallery.gal" % globalUser()
    path    = "%s/gallery/%s" % ( hpath, filename )
 print path
 return path

def reloadGallery():
 # Reload the gallery file
 try:
        entryInfoPath   = galleryFilePath()
        hou.galleries.installGallery( entryInfoPath )
 except:
 print "Unable to reload gallery."

def setWatermark( node ):
    wmParmName  = "___watermark___"
    parmGroup   = node.parmTemplateGroup()
 if not parmGroup.find(wmParmName):
        wmParm  = hou.StringParmTemplate( wmParmName, "Watermark", 1 )
        wmParm.setHelp("Feel free to use this node. %s :)" % globalUser())
        wmParm.hide(1)
        parmGroup.append( wmParm )
        node.setParmTemplateGroup( parmGroup )
    wmMessage   = "Latest Update By : %s, %s" % (globalUser(), time.ctime())
    node.parm(wmParmName).set(wmMessage)
    node.parm(wmParmName).hide(1)
 return

def setGalleryEntry( node ):
    comment     = node.comment().split("\n")[0]
 type        = node.type()
    category    = type.category().typeName().upper()
 
 # Extract Comment
 try:
        comment = comment.split(": ")[1]
        galleryUser = comment.split(" ")[0]
        galleryCat  = comment.split(" ")[1]
        galleryName = " ".join(comment.split(" ")[2:])
 except:
        galleryUser = globalUser()
        galleryName = "New Gallery"
 if galleryUser == "JYW" or galleryUser == globalUser():
        isOverwrite = 1
        entryName   = "%s %s %s" % ( globalUser(), category, galleryName )
 else:
        entryName   = "%s %s New Gallery" % ( globalUser(), category )
 
 # Create Entry Data from Entry Name
    entryData   = [ globalUser(), category, galleryName ]
 
 # Overwrite Entry Data manually
    uiMessage   = "Save the selected node to gallery.                    "
 if isOverwrite: uiMessage += "\n\nCAUTION : This will overwrite the old gallery if not updating the Name"
    uiLabels    = [ "User Name : ", "Category : ", "Gallery Name : " ]
    uiButtons   = [ "OK", "Cancel" ]
    uiInitials  = entryData
    uiData  = hou.ui.readMultiInput( uiMessage, uiLabels, initial_contents=uiInitials, buttons=uiButtons, default_choice=1 )
 if uiData[0] == 1:
 return
    entryData   = uiData[1]
 
 # Set Watermark
    setWatermark( node )
 
 # Construct the Entry Info
    entryInfoName   = "%s_%s_%s" % ( entryData[0], entryData[1], entryData[2].replace(" ","") )
    entryInfoLabel  = "%s %s %s" % entryData
    entryInfoPath   = galleryFilePath()
    entryInfoCat    = globalUser()
 
 # Create and set the gallery
    entryObject = hou.galleries.createGalleryEntry( entryInfoPath, entryInfoName, node )
    entryObject.setLabel( entryInfoLabel )
    entryObject.setCategories( [globalUser()] )
 
 # Print Message
    prttime = str( time.ctime( time.time() ) )
    message = "\n-------\n%s\nGallery : %s\nSaved to : %s\n-------\n" % ( prttime, entryInfoLabel, entryInfoPath )
 
 print message





def __main__():
    reloadGallery()
 if hou.selectedNodes():
        node    = hou.selectedNodes()[0]
        setGalleryEntry( node )

__main__()

 
 
 

最新文章

查看全部
Dual Rest Based Heat Distortion

This is a simple idea to create the fake heat distortion. The purpose is to distort the background image according to the flame/fire...

 
 
 

Comments


bottom of page