Code :
import os
import hou
#Get HIP
hipdir = hou.expandString("$HIP")
#Get frame range
totalFrameRange = 50000
# check if it is in Project Path
def isInProjectPath(projPath , filePath ):
absProject = os.path.abspath(projPath)
absFilePath = os.path.abspath(filePath)
return os.path.commonprefix([absProject,absFilePath])==absProject
# run my custom prefligth
def chrysl666_PF():
#empty list
compressList = []
messages = ""
# list all parm and paths
for parm , path in hou.fileReferences():
#expand path to absolute paths in all frames
for i in range(totalFrameRange):
try:
filePath = parm.evalAsStringAtFrame(i)
#check if file is inside Main Project
if not isInProjectPath(hipdir, filePath):
messages += ( "---->filePath = "+filePath + " is not in $HIP\n" )
break
#check if exists in disk
if(os.path.exists(filePath) == True ):
# if True add into the list
compressList.append(filePath)
except:
pass
# remove duplicate paths from list
compressList = list(dict.fromkeys(compressList))
# sort
compressList.sort()
#not used
#for each in compressList:
# print each + "\n"
if(messages>1):
hou.ui.displayMessage( messages , title ="NOT IN THE PROJECT PATH")
return compressList
# ARCHIVE FUNC
def archive(list):
from zipfile import ZipFile
import os
# gets scene file
scene = hou.expandString("$HIPFILE")
sceneName = hou.expandString("$HIPNAME")
# gets HIP Projct folder
hipdir = hou.expandString("$HIP")
zipNameAndPath = os.path.join(hipdir,sceneName)+".zip"
# opens zip to write
finalZip = ZipFile(zipNameAndPath,"w")
# write dependence files
finalZip.write(scene)
for each in list:
finalZip.write(each)
# closes zip
finalZip.close()
hou.ui.displayMessage(zipNameAndPath , title = "DONE")
archive(chrysl666_PF())