Notifications
Clear all

[Closed] openFile filename_string – creating a list of missing frames

in the snippet below,
missingFramesFile = <File:\pdx-3dmanager\shortstore\jross\WilsonVilleBridge\20090428\WV_Render\MissingFrames.txt>

How do I convert the filestream to a filename string?

(
 	 missingFramesFile = createFile (getSaveFileName filename:(rawOutputPath + "MissingFrames.txt") types:"Text(*.txt)")
 	  openFile missingFramesFile mode:"w"
 	  for i = 1 to missingFrames.count do
 	  (
 		   format "%
" (missingFrames[i] as string) to:missingFramesFile
 	  )
 	  flush missingFramesFile
 	  close missingFramesFile
 )

Here is the whole mess. Using the VRay Frame Buffer for output, there is no Skip Existing images functionality. So I wrote this to try and create a list of missing frames. It creates an array of the files in a folder and compares that to an array created using the render file name and sequential numbering. Then it prints the missing files and changes the Pickup Frames. Thirdly, I want to save the frames to a file. It works if I don’t use openFile but I thought that would be an easy way to clean the file out if it already exists.

macroScript FindMissingFrames
 category: "MyTools"
 
 
 (	
 	-- SetUp Variables
 	global ro_FindMissingFrames
 	local re = renderers.current
 	local rawOutputFullPath = re.output_rawFileName
 	local rawOutputPath = getFilenamePath rawOutputFullPath
 	local rawOutputFile = tolower (getFilenameFile rawOutputFullPath)
 	local rawFileList = getFiles (rawOutputPath + "*.*")
 	local animEnd = animationrange.end as integer/160
 	local filelist = #()
 	local missingFrames = #()
 	local thePickUpFrames = "0"
 	
 	--build an array of existing files
 	for i in rawfilelist do
 	(
 		append filelist (tolower (getFilenameFile i))
 	)
 	
 -------------------------------Close the old dialog if open --------------------------------------
 	
 	try (destroyDialog ro_FindMissingFrames) catch()
 
 ---------------------------------- Start UI --------------------------------------------------------	
 		rollout ro_FindMissingFrames "Find Missing Frames" width:700
 		(
 			group "Source Folder and Frame Range"
 			(
 				button btn_folder "Browse..." pos:[10,20]
 				label lab_rawPath "No Folder" pos:[80,22] align:#left
 				
 				spinner spn_FrameStart "Start: " range:[-99999, 99999, 0] align:#left type:#integer fieldWidth:50 pos:[10,45]
 				spinner spn_FrameEnd "End: " range:[-99999, 99999, animEnd] align:#left type:#integer fieldWidth:50 pos:[100,45]
 				
 				label lab_PickupFrames "Set Pickup Frames" pos:[33,70]
 				checkbox chk_Frames checked:true pos:[10,70]
 				label lab_SaveFile "Save List to File" pos:[33,95]
 				checkbox chk_Save checked:false pos:[10,95]
 				
 				button btn_ListMissingFrames "Find missing files!" align:#right
 				
 			)
 			
 --------------------------------- End UI -----------------------------------------------------------------
 			
 			on ro_FindMissingFrames open do 
 			(
 				lab_rawPath.text = rawOutputPath
 			)
 --------------------------------- Browse Button ---------------------------------------------------------
 			on btn_folder pressed do
 			(
 				newPath = getOpenFileName caption:"Choose Folder to find missing frames:" initialDir:rawOutputPath
 				lab_rawPath.text = newPath
 				rawOutputFullPath = newPath
 				rawOutputPath = getFilenamePath rawOutputFullPath
 				rawOutputFile = tolower (trimright  (getFilenameFile rawOutputFullPath) "1234567890")
 				rawFileList = getFiles (rawOutputPath + "*.*")
 					
 				filelist = #()
 				
 				for i in rawfilelist do
 				(
 					append filelist (tolower(trimright (getFilenameFile i) ".exr"))
 				)
 				
 			)
 			
 ----------------------------------Find Missing Files Button -----------------------------------------------
 			
 			on btn_ListMissingFrames pressed do
 				
 			(
 				theFrameRange = (spn_FrameEnd.value - spn_FrameStart.value )
 				
 				for f = 0 to theFrameRange-1 do
 				(   
 					if
 					(
 						(finditem filelist (rawOutputFile + (formattedPrint f format:"04u"))) == 0
 					)
 					then 
 					(
 						print (rawOutputFile + (formattedPrint f format:"04u"))
 						append missingFrames (rawOutputFile + (formattedPrint f format:"04u"))
 						--print missingFrames
 						thePickupFrames = (thePickupFrames + ", " + f as string)
 						
 					)
 					else ()
 				) 
 				
 				--Set Pickup Frames
 				thePickupFrames = (substring thePickupFrames 3 99999)
 				if chk_Frames.checked == true
 				then
 				(
 					rendTimeType = 4
 					rendPickupFrames = thePickupFrames
 					renderSceneDialog.update()
 					--print thePickupFrames
 				)
 				else()
 				
 				--Save list to file
 				if chk_Save.checked == true
 				then
 				(
 					missingFramesFile = createFile (getSaveFileName filename:(rawOutputPath + "MissingFrames.txt") types:"Text(*.txt)")
 					openFile missingFramesFile mode:"w"
 					for i = 1 to missingFrames.count do
 					(
 						format "%
" (missingFrames[i] as string) to:missingFramesFile
 					)
 					flush missingFramesFile
 					close missingFramesFile
 				)
 				else()
 			)
 			
 		)
 		
 --------------------------------------Save File Button--------------------------------------------------
 
 
 ---------------------------------------Create Dialog ----------------------------------------------------
 
 	createDialog ro_FindMissingFrames pos:[500,200]
 
 
 )
1 Reply

Your code should already have the answer. getSaveFilenName() (highlighted in green) returns the filename string. createFile() (in blue) then takes that string and (tries to) creates a file handle (which you store in missingFramesFile) for it.

So all you’d have to do is something like:


missingFramesFileName = getSaveFileName filename:(rawOutputPath + "MissingFrames.txt") types:"Text(*.txt)"
missingFramesFile = createFile missingFramesFileName

Note that you may wish to check if missingFramesFileName is valid (e.g. not ‘undefined’ – the user having cancelled the file browse operation).

After that, you can just use deleteFile() to delete the file. Alternatively, see the openFile() documentation as there is a file opening mode that will wipe the file if it already exists, or see createFile() – which will open a file handle as well but will overwrite any existing files.