I'm very excited to see that they have included a similar script in the latest TVP 11 version. it really makes me love this software, as it seems that tvpaint really takes these forums into account.
i've tweaked their script a bit for optimization. it doesn't export unnecessary blank frames at the end of the sequence for layers that end early, and i've changed the naming conventions a bit so it is easier to import these images into another compositing software and keep everything in order.
Be careful not to include backslashes or any weird symbols in your layer names, it might have a hard time making the directories.
so here's the script:
Code: Select all
#param none
tv_getpath "home" //path par defaut
srcFolder=result
tv_readuserstring "ExportDigital" "folder" srcFolder
srcFolder=result
//Ouverture du file requester
requester = FileRequester("<Select a folder to save in...",srcFolder,srcFile,"*.txt")
IF ( requester!=1 )
EXIT
END
tv_SaveMode "PNG" "b32"
tv_AlphaSaveMode NoPreMultiply
tv_layercurrentid
InitLayer = result
tv_layergetimage
InitImage = result
tv_firstimage
startingFrame= result
CurrentImage = startingFrame
tv_lastimage
LastImage = result
tv_clipcurrentid
ClipID = result
//tv_clipname ClipID
//ClipName = result
//these two lines above have been turned off, they identify the export by clip names.
//i've changed to project name below
tv_ProjectCurrentID
projectID = result
//tv_GetProjectName projectID
//ClipName = result
//tv_warn ClipName
tv_ReqString "hold up, what are we calling this? (ex: shot 1 = 'SH0010')."
ClipName=result
//run pre export sequence to create folders, folder paths and determine post behaviors ----------------------------------->
tv_LockDisplay "Initiating..."
layerRun = 1
layerCount = 0
WHILE ( layerRun == 1 )
tv_LayerGetID layerCount
layerID = result
IF ( CMP( layerID, "NONE" ) != 0 )
layerRun = 0
ELSE
//tv_Warn "layer " layerCount+1 " exists"
tv_LayerSet layerID
tv_LayerInfo
PARSE result layerDisplay a2 a3 layerName a5 imagePos imageEnd a7 a8 a9 dummy
IF ( CMP( layerDisplay, "OFF" ) == 0 )
// postBehavior test
tv_layerpostbehavior layerID
endBehavior = result
//tv_Warn "Layer" layerCount+1 "end behavior is " endBehavior"."
test = CMP(endBehavior, "none")
IF (test == 1)
layerBehavior[layerCount] = 0
ELSE
layerBehavior[layerCount] = 1
END //end endbehavior test
//-------------------------create folder,
numlayer = layerCount+1
foldername = pathname
IF ( numlayer < 10 )
foldername = foldername"L0"numlayer"_"layerName
folderpath[layerCount] = foldername"/"ClipName"_L0"numlayer"_"layerName
ELSE
foldername = foldername"L"numlayer"_"layerName
folderpath[layerCount] = foldername"/"ClipName"_L"numlayer"_"layerName
END
//tv_Warn "The folder path is " foldername
tv_WriteTextFile "Exists" '"'foldername'"'
exist = result
IF ( CMP( exist, "0" ) != 0 ) //Si le dossier n'existe pas
tv_WriteTextFile "MkDir" '"'foldername'"'
ELSE
END
// ---------------------end create folder
ELSE
END
layerCount = layerCount + 1
END
END
tv_UnLockDisplay
//end pre export sequence to create folders, folder paths and determine post behaviors ----------------------------------->
layerRun = 1
layerPos = 0
WHILE ( layerRun == 1 )
tv_LayerGetID layerPos
layerID = result
IF ( CMP( layerID, "NONE" ) == 0 )
//tv_Warn "layer " layerPos " is being run"
v3=layerPos+1
//v1 = layerPos+1+layerCount*CurrentImage
//v2 = layerCount*(LastImage+1)
tv_LayerSet layerID
tv_LayerInfo
PARSE result layerDisplay a2 a3 layerName a5 imagePos imageEnd a7 a8 a9 dummy
//tv_Warn "layer " layerPos " ending frame is" imageEnd
IF ( CMP( layerDisplay, "OFF" ) == 0 )
IF (layerBehavior[layerPos]==0)
endingFrame=imageEnd
ELSE
endingFrame= LastImage
END //end endbehavior test
CurrentImage = startingFrame
FOR CurrentImage = startingFrame TO endingFrame
exportImage=CurrentImage+1
tv_LockDisplay "Exporting... (layer "v3", image "exportImage" )"
tv_layerImage CurrentImage
IF ( exportImage < 10 )
finalPath = folderPath[layerPos]"_000"exportImage
ELSE
IF ( exportImage < 100 )
finalPath = folderPath[layerPos]"_00"exportImage
ELSE
IF ( exportImage < 1000 )
finalPath = folderPath[layerPos]"_0"exportImage
ELSE
finalPath = folderpath[layerPos]"_"exportImage
END // if<1000
END //if <100
END //if<10
tv_saveimage finalPath
//CurrentImage=CurrentImage+1
tv_UnLockDisplay
END //For current image
END // if layer is displayed
layerPos = layerPos + 1
ELSE //the layer doesn't exist
layerRun = 0
END // if layer exists
END //while layerRun=1
tv_layerSet InitLayer
tv_layerImage InitImage
//------------------------------------------
//
// FileRequester
//
// Function: open a file requester
//
// Call: FileRequester(title,path,file,pattern)
//
// Arguments:
// title = requester title
// path = default directory
// file = default filename
// pattern = default pattern
//
// Return: 0 if user clicks on Cancel
// 1 if user chooses a file. This
// function creates three global
// variables: fullpath ( path+name+
// extension ), pathname (path
// to choosen file), filename
// (name of choosen file without
// extension) and extension
// (extension of choosen file)
//
//------------------------------------------
FUNCTION FileRequester(title,path,file,pattern)
LOCAL point slash size titre
fullname = ""
fullpath = ""
pathname = ""
filename = ""
extension = ""
IF (CMP(pattern,0) == 1)
titre = "|"
ELSE
titre = "|"pattern
extension = CUT( pattern, 2, LEN( pattern ) )
END
IF (CMP(file,0) == 1)
titre = "|"titre
ELSE
titre = "|"file""titre
END
IF (CMP(path,0) == 1)
titre = "|"titre
ELSE
titre = "|"path""titre
END
IF (CMP(title,0) == 1)
titre = "Choose a file"titre
ELSE
titre = title""titre
END
tv_ReqFile titre
fullname = Result
size = LEN(fullname)
fullname = Replace(fullname,"\","/")
IF (CMP(fullname,"Cancel") == 1)
RETURN 0
END
fullpath = CUT( fullname, LEN(fullname) - LEN( extension ) + 1, LEN(fullname) )
IF ( CMP( fullpath, extension ) == 1 )
fullpath = fullname
fullname = CUT( fullname, 1, LEN(fullname) - LEN( extension ) )
ELSE
fullpath = fullname""extension
END
start = 1
stop = 1
WHILE ( start > 0 )
start = Find( fullname, "/", stop )
IF ( start > 0 )
stop = start +1
END
END
pathname = CUT( fullpath, 1, stop - 1 )
filename = CUT( fullname, stop + 1, LEN( fullname ) )
RETURN 1
END
//------------------------------------------
//
// Replace
//
// Function: replace each occurence of a
// substring into a string with
// another string
//
// Call: Replace(string,search,repl)
//
// Arguments:
// string = characters string
// search = substring to look for
// repl = replacement substring
//
// Return: result string after replacement
//
//------------------------------------------
FUNCTION Replace(string,search,repl)
LOCAL pos workstr str1 str2 size
pos = 1
workstr = string
size = LEN(search)
WHILE ((pos = FindString(workstr,search,pos)) > 0)
IF (pos == 1)
str1 = CUT(workstr,size+1,LEN(workstr))
workstr = repl""str1
pos = 0
ELSE
str1 = CUT(workstr,1,pos-1)
IF ((pos+size) < LEN(workstr))
str2 = CUT(workstr,pos+size,LEN(workstr))
workstr = str1""repl""str2
ELSE
workstr = str1""repl
END
END
pos = pos+LEN(repl)
END
RETURN workstr
END
//------------------------------------------
//
// FindString
//
// Function: find a substring into a string
// from a specified start position
//
// Call: FindString(string,search,start)
//
// Arguments:
// string = characters string
// search = substring to look for
// start = start position in string
// Return: start position of substring
// 0 if substring does not exist
// into string
// -1 if invalid start position
// (negative, null or higher
// than string length) or if
// substring is empty
//
//------------------------------------------
FUNCTION FindString(string,search,start)
LOCAL found j pos lastpos lstr lsrch
found = 0
lastpos = start
lstr = LEN(string)
lsrch = LEN(search)
IF (CMP(search,"") == 1)
RETURN -1
END
WHILE ((pos = Find(string,CHAR(search,1),lastpos)) > 0)
j = 1
found = 1
IF (j == lsrch)
RETURN pos
END
WHILE ((j < lsrch) && (found == 1))
IF ((pos+j) > lstr)
RETURN 0
ELSE
IF (CMP(CHAR(search,j+1),CHAR(string,pos+j)) == 0)
lastpos = pos+j
found = 0
END
END
j = j+1
END
IF (found == 1)
RETURN pos
END
END
RETURN pos
END
//------------------------------------------
//
// Find
//
// Function: find a character into a string
// from a specified start position
//
// Call: Find(string,car,start)
//
// Arguments:
// string = characters string
// car = character to look for
// start = start position in string
//
// Return: position of character
// 0 if character does not exist
// into string
// -1 if invalid position
// (negative, null or higher
// than string length)
//
//------------------------------------------
FUNCTION Find(string,car,start)
LOCAL i size
i = start
size = LEN(string)
IF ((start <= 0) || (start > size) || (CMP(car,"") == 1))
RETURN -1
END
DO
IF (CMP(CHAR(string,i),car) == 1)
RETURN i
END
UNTIL ((i=i+1) > size)
RETURN 0
END