Wednesday 27 October 2021

I fixed it.......for now

After putting the original script through the production pipeline I noticed a few errors. These had been fine when working off one max file, but once I used the loop to go through multiple max files the issues started to creep in. 
3DS Max stores variables once they are assigned and this is something I need to get used to when debugging. If I ran the script once and stepped through to solve an issue, any variables I had manually set during this would be locked in place till overwritten or Max was closed. This led to a variable not being set correctly in the loops and this only became apparent once I got the final results back, the files had rendered out correctly but not in the right folders. My first clue was that each image sequence was begin stored in the previous folder according o the order of the main loop.

The issue was with the render output filename and path, with the variable "verShotFolder" This variable was being set inside of an 'if' loop and not being stored outside of it afterwards. 
The solution was to create this variable at the beginning of the whole script as verShotFolder = ""

I also split some of that loop up as the...
if (doesfileexist verShotFolder) != true do
(makeDir verShotFolder)
...was being called the same no matter the result of the first loop.

----------------------------------------------------------------------------------------------------------------------

Debugging this code was a bit of a mission, but I feel I've learned a significant flag to watch out for in future coding exercises. If a variable from inside a loop is being called outside of it, that variable must be declared first, outside of the loop, so that the loop can fill it in, otherwise the variable from the loop will only hold the value assigned to it for the duration of the loop.

----------------------------------------------------------------------------------------------------------------------

maxFiles = getfiles @"O:\VirtualTour_VR\3D\Projects\Scenes\ScriptBackup\*.max"
::filein @"O:VirtualTour_VR\Scripts\DeadlineSubmitter_v01.ms"
mergeFileName = @"O:\VirtualTour_VR\3D\Projects\Scenes\ScriptTest\NovartisUpdatedHead01.max"
verShotFolder = ""
for i = 1 to maxFiles.count do
(
loadMaxFile (maxfiles[i])
verShotFolder = ""
---------------------------------------------------------------------------
----------- Update geo and texture

oldHeadGeo = $Char_Head
headParent = $Char_CTRL_Main
bandRemove = $Char_HeadStrip
innerHead = $Char_InnerHead

mergeMAXFile mergeFileName  #useMergedMtlDups
newHeadGeo = $NovartisUpdatedHead01
newHeadGeo.transform = oldHeadGeo.transform
newHeadGeo.parent = headParent
innerHead.parent = headParent
delete oldHeadGeo
delete bandRemove
viewport.setCamera $PhysCamera001
meditMaterials[1] = sceneMaterials["Head_Body"]
$Char_Body.material = meditMaterials[1]

---------------------------------------------------------------------------
----------- Make new folder for v2.2

renderSceneDialog.close()
rc=renderers.current
rc.output_saveRawFile=true
rendTimeType = 2
ogOutput = rc.output_rawFileName
verFolder = pathConfig.removePathLeaf ogOutput
verFolderTest = (filterstring (verFolder) "\\")[(filterstring (verFolder) "\\").count]

rendFileOuputSplit = (filterstring (ogOutput) "\\")[(filterstring (ogOutput) "\\").count]
versionUp =  (filterstring (rendFileOuputSplit) ".")
versionPt2 = versionUp[2]
versionPt2Solo = versionPt2[1] as integer
versionUpSolo = (versionPt2Solo + 1) as string
UppedVerFilename = versionUp[1] + "." + versionUpSolo + "_" + "." + versionUp[3]
--outputPath = verShotFolder + "\\" + UppedVerFilename

ogFileName = (filterstring (ogOutput) "\\")[(filterstring (ogOutput) "\\").count]
ogFileVerMain =  (filterstring (ogFileName) ".")[1]
mainVer = ogFileVerMain[ogFileVerMain.count]
targetVersion =  "v" + mainVer + "." + versionUpSolo
shotFolder = pathConfig.removePathLeaf verFolder
if (verFolderTest == "Intro") then
(
verShotFolder = (verFolder + "\\" + targetVersion)
)
else if (verFolderTest == "Outro") then
(
verShotFolder = (verFolder + "\\" + targetVersion)
)
else
(
verShotFolder = (shotFolder + "\\" + targetVersion)
)
if doesfileexist(verShotFolder) != true do
(
makeDir verShotFolder
)

---------- Set Vray render output to new version

outputPath = verShotFolder + "\\" + UppedVerFilename
rc.output_rawFileName = outputPath

---------- Save new max file version
maxFilePathSplit = (filterstring (maxfilepath) "\\")
parentMaxFolder = pathConfig.removePathLeaf maxfilepath
newMaxFileSave = parentMaxFolder
maxFileNameSplit =  (filterstring (maxfilename) ".")
maxFileVersion = maxFileNameSplit[2] as integer
maxFileVersioningUp = (maxFileVersion + 1) as string
newMaxFileName = maxFileNameSplit[1] + "." + maxFileVersioningUp + "." + maxFileNameSplit[3]
newMaxFileNameFullPath = maxfilepath + newMaxFileName
if (doesfileexist newMaxFileNameFullPath) != true then
(
saveMaxFile newMaxFileNameFullPath
)
else
(
messagebox "!!!Warning!!!\nA more recent max file already exists\nJob has been submitted anyway"
)

----------Send to deadline

_DlJobName = maxfilename
_Priority = 30
_Comment = "-- Submitted Via DLSubmitJob"
_UserName = "Eoin"
_Group = "singles"
DLRenSubmit _DlJobName _Priority _Comment _UserName _Group 
)



No comments:

Post a Comment