- Posts: 765
- Joined: Tue Jul 09, 2013 6:58 pm
I'm playing around with Generation for workflow enhancements, and unfortunately am not a programmer by any means. The current script create's a saver in the location of the saved .comp and names it "out_.tif"
I want to create a static location for the saver on a drive letter and also have the output name be the loaders name with a prefix and suffix.
As far as I can tell I need to modify these lines.....
firstFile = string.gsub(firstFile, path, "Comp:\\", 1)
and
Filename = \"".. path .."saver\\\\out_.".. saverExt .."\",\n" ..
Also, since the script is working, I'd like to make a copy of it for testing, but not sure where to do that and load it back in generation.
Any thoughts?
Here's the original script in Generation:
I want to create a static location for the saver on a drive letter and also have the output name be the loaders name with a prefix and suffix.
As far as I can tell I need to modify these lines.....
firstFile = string.gsub(firstFile, path, "Comp:\\", 1)
and
Filename = \"".. path .."saver\\\\out_.".. saverExt .."\",\n" ..
Also, since the script is working, I'd like to make a copy of it for testing, but not sure where to do that and load it back in generation.
Any thoughts?
Here's the original script in Generation:
- Code: Select all
if not gen.ActiveProject:AllowChanges(true) then
return
end
-- Saver output file format/extension
saverExt = "tif"
-- Global Start, Render Start, and clip start in the Loader
startFrame = 0
-- Saver Sequence Offset
saverOffset = 0
------------------------------------------------------------------------------
-- parseFilename()
--
-- this is a great function for ripping a filepath into little bits
-- returns a table with the following
--
-- FullPath : The raw, original path sent to the function
-- Path : The path, without filename
-- FullName : The name of the clip w\ extension
-- Name : The name without extension
-- CleanName: The name of the clip, without extension or sequence
-- SNum : The original sequence string, or "" if no sequence
-- Number : The sequence as a numeric value, or nil if no sequence
-- Extension: The raw extension of the clip
-- Padding : Amount of padding in the sequence, or nil if no sequence
-- UNC : A true or false value indicating whether the path is a UNC path or not
------------------------------------------------------------------------------
function parseFilename(filename)
local seq = {}
seq.FullPath = filename
string.gsub(seq.FullPath, "^(.+[/\\])(.+)", function(path, name) seq.Path = path seq.FullName = name end)
string.gsub(seq.FullName, "^(.+)(%..+)$", function(name, ext) seq.Name = name seq.Extension = ext end)
if not seq.Name then -- no extension?
seq.Name = seq.FullName
end
string.gsub(seq.Name, "^(.-)(%d+)$", function(name, SNum) seq.CleanName = name seq.SNum = SNum end)
if seq.SNum then
seq.Number = tonumber( seq.SNum )
seq.Padding = string.len( seq.SNum )
else
seq.SNum = ""
seq.CleanName = seq.Name
end
if seq.Extension == nil then seq.Extension = "" end
seq.UNC = ( string.sub(seq.Path, 1, 2) == [[\\]] )
return seq
end
function browseForSaveFile(dlg_title, initial_dir, initial_file, file_filter, file_filtername)
local file = nil
filterstr = file_filtername .."(".. file_filter ..")|".. file_filter .."|All Files (*.*)|*.*|"
filedlg = iup.filedlg
{
dialogtype = "SAVE", title = dlg_title,
extfilter = filterstr,
directory = initial_dir, file = initial_file
}
filedlg:popup(iup.ANYWHERE, iup.ANYWHERE)
if filedlg.status == "0" or filedlg.status == "1" then
file = filedlg.value
end
return file
end
function saveComp(cliplen, mediain, project, filename, path, loaders, outwidth, outheight)
local loader = loaders[1]
local first = 0
local frames = loader.Length -- not sure if this is exactly the same as the built-in code
local firstFile = loader.Filename
if cliplen == 0 then
cliplen = frames
end
firstFile = project:MapPath(firstFile)
path = project:MapPath(path)
firstFile = string.gsub(firstFile, path, "Comp:\\", 1)
firstFile = string.gsub(firstFile, "\\", "\\\\")
eyeon.createdir(string.format("%ssaver", path))
path = "Comp:\\\\"
d = "Composition {\n" ..
" CurrentTime = 0,\n" ..
" RenderRange = { ".. startFrame ..", ".. startFrame+cliplen ..", },\n" ..
" GlobalRange = { ".. startFrame ..", ".. startFrame+cliplen*2 ..", },\n" ..
" Version = \"Fusion 5.2 build 54\",\n" ..
" Tools = {\n" ..
" Loader1 = Loader {\n" ..
" Clips = {\n" ..
" Clip {\n" ..
" ID = \"Clip1\",\n" ..
" Filename = \"".. firstFile .."\",\n" ..
" StartFrame = ".. first ..",\n" ..
" Length = ".. first+frames ..",\n" ..
" TrimIn = ".. mediain ..",\n" ..
" TrimOut = ".. mediain+cliplen ..",\n" ..
" ExtendFirst = 0,\n" ..
" ExtendLast = 0,\n" ..
" Loop = 1,\n" ..
" GlobalStart = ".. startFrame ..",\n" ..
" GlobalEnd = ".. cliplen ..",\n" ..
" },\n" ..
" },\n" ..
" Inputs = {\n" ..
" EnableClipList = Input { Value = 0, },\n" ..
" },\n" ..
" ViewInfo = OperatorInfo {\n" ..
" Pos = { 394, 185, },\n" ..
" },\n" ..
" },\n" ..
" Saver1 = Saver {\n" ..
" Inputs = {\n" ..
" Clip = Input {\n" ..
" Value = Clip {\n" ..
" Filename = \"".. path .."saver\\\\out_.".. saverExt .."\",\n" ..
" },\n" ..
" },\n" ..
" Input = Input {\n" ..
" SourceOp = \"Loader1\",\n" ..
" Source = \"Output\",\n" ..
" },\n"
if saverOffset ~= 0 then
d = d ..
" SequenceStartFrame = Input { Value = ".. saverOffset ..", },\n"
end
d = d ..
" },\n" ..
" ViewInfo = OperatorInfo {\n" ..
" Pos = { 510, 186, },\n" ..
" },\n" ..
" },\n" ..
" },\n" ..
" Prefs = {\n" ..
" Comp = {\n" ..
" Interactive = {\n" ..
" Proxy = {\n" ..
" Scale = 2,\n" ..
" Auto = false,\n" ..
" AutoScale = 2,\n" ..
" },\n" ..
" },\n" ..
" FrameFormat = {\n" ..
" GuideRatio = 1,\n" ..
" Width = ".. outwidth ..",\n" ..
" Height = ".. outheight ..",\n" ..
" },\n" ..
" },\n" ..
" },\n"
local dpath = project.PathData
if dpath ~= nil then
local cpath = project.PathData.."chat\\" -- chat path
local apath = project.PathData.."annotation\\" -- annotation path
d = d ..
" CustomData = {\n" ..
" Generation = {\n" ..
" Project = \"".. project.Name .."\",\n" ..
" Location = \"".. string.gsub(project.Filename, "\\", "\\\\").. "\",\n" ..
" ChatPath = \"".. string.gsub(cpath, "\\", "\\\\").. "\",\n" ..
" AnnotationPath = \"".. string.gsub(apath, "\\", "\\\\").. "\",\n" ..
" ReferenceName = \"" .. loader.Name .."\",\n" ..
" },\n" ..
" },\n"
else
App():Log("WARNING: Project not saved yet, no chat or annotation path found")
d = d ..
" CustomData = {\n" ..
" Generation = {\n" ..
" Project = \"\",\n" ..
" Location = \"\",\n" ..
" ChatPath = \"\",\n" ..
" AnnotationPath = \"\",\n" ..
" ReferenceName = \"noreference\",\n" ..
" },\n" ..
" },\n"
end
d = d ..
"}\n"
local outfile = io.open(filename, "w")
if outfile then
outfile:write(d)
outfile:close()
end
end
local project = gen.ActiveProject
if project ~= nil then
local versions = project:SelectedVersions()
local vclip = versions[1]
if vclip ~= nil then
local ld = vclip:GetLoader()
local outwidth = project.Width
local outheight = project.Height
local filename = ld.Filename
if filename ~= nil then
local title = parseFilename(filename).Name
local temp = project.Path
if temp == nil then
temp = "PROJECTS:"
end
local name = temp .. title .. ".comp"
temp = project:MapPath(temp);
name = project:MapPath(name);
local reqstr = browseForSaveFile("Save comp", temp, name, "*.comp", "Fusion Composition")
if reqstr ~= nil then
local path = parseFilename(reqstr).Path
local items = { }
items[1] = ld
local len = 0
local mediain = 0
local mclip = vclip:GetSlotClip()
if mclip ~= nil then
len = mclip.OutPoint - mclip.InPoint
mediain = vclip.InPoint
end
saveComp(len, mediain, project, reqstr, path, items, outwidth, outheight)
reqstr = string.gsub(reqstr, "\\", "\\\\")
local newitems = project:DropFiles(reqstr)
mclip:VersionInsert(newitems[1], 0)
end
end
end
end