Eyeon:Script/Reference/Libraries/eyeon/readfile

From VFXPedia

Jump to: navigation, search


Contents

Usage

eyeon.readfile(string filename)

  • filename (required, string)

A string containing the full filename of a composition


Returns

This function returns a table if it succesfully reads the composition, and nil if it fails.


Remarks

The eyeon.readfile function reads a composition from disk and formats it into a table. Fusion does not have to be running when this happens. The result can be manipulated and written back to disk using the eyeon.writefile function.


Requires

  • Fusion 5.2
  • eyeonScript 5.2


Examples

usage = [[
This script takes loadername=clipname arguments and modifies a template composition
 
script template_comp dest_comp length toolname=clip [toolname=clip ...]
 
template_comp : the template to load
dest_comp     : the filename for the result
length        : the length of the composition (optional)
toolname      : the name of the loader or saver in the composition
clip          : the name of the clip to replace the loader with
 
]]
 
if arg[1] then 
	if fileexists(arg[1]) then
		filename = arg[1]
	else
		print("Could not find the template composition - "..arg[1])
		print(usage)
		error(-2)
	end
else
	print("Please provide the path to a template composition.")
	print(usage)
	error(-1)
end
 
if arg[2] then
	f, err = io.open(arg[2], "w")
	if not f then
		print("Could not create output composition "..arg[2].." The system returned the following error : \n"..err)
		error(-4)
	end
	f:close()
	f = nil
	
	output_comp = arg[2]
else
	print("Please provide an output composition.")
	print(usage)
	error(-3)
end
 
if arg[3] then
	length = tonumber(arg[3])
	if not length then
		print("The third argument must be a numeric value which represents the length of the output.")
		print(usage)
		error(-5)
	end
end
 
-- load the composition
comp = eyeon.readfile(filename)
 
if not comp then
	print("The script could not parse "..filename)
	error(-100)
end
 
for i, v in arg do 
	if not (i == "n") then
	
		-- make sure this is one of the named arguments
		if type(i) == "string" then
		
			if comp.Tools[i] then
				-- this ignores the possibility of clip lists, assuming the template has only one clip per loader.
				
				print("\n"..i)
				if comp.Tools[i].__ctor == "Loader" then
					print("Before: "..comp.Tools[i].Clips[1].Filename.."\nAfter : "..v)
					comp.Tools[i].Clips[1].Filename = v
				elseif comp.Tools[i].__ctor == "Saver" then
					print("Before: "..comp.Tools[i].Inputs.Clip.Value.Filename.."\nAfter : "..v)
					comp.Tools[i].Inputs.Clip.Value.Filename = v
				end
				
				-- when you change a loader this way (without using the GUI Fusion) you become responsible for setting the 
				-- global start, length, aspect etc - it won't be done automatically
			else
				print("WARNING: Could not find a tool called "..i.." in the template composition.")
			end
			
		end
	end
end
 
bol = eyeon.writefile(output_comp, comp)


Tips for readfile (edit)

EyeonTips:Script/Reference/Libraries/eyeon/readfile