Page 2 of 2
Re: How do I create a new moho file and copy a layer to it via script?
Posted: Sun Dec 03, 2023 6:41 pm
by hayasidist
Thanks Wes. I'll aim to put a bug report together on this re FileClose with an active Lua console window...
Lukas wrote: ↑Sat Dec 02, 2023 11:34 am
I do wish we could do this without Ctrl+N and running the script twice, because the purpose of this script was actually to keep the animator focussed on the shot. Just hit a button and the layer is sent away for later.
I think this might do it IF you're ok with copy paste the layer's contents rather than duplicate the layer (I have to say that I'm not 100% sure what gets "left behind" in either scenario -- at first sight it looks as though styles, animation etc all get copied over)
Re: How do I create a new moho file and copy a layer to it via script?
Posted: Sun Dec 03, 2023 7:51 pm
by synthsin75
I thought of copying the contents, but I didn't know if this could occasionally be used on group layers too.
Re: How do I create a new moho file and copy a layer to it via script?
Posted: Sun Dec 03, 2023 8:21 pm
by synthsin75
This should be a reliable way to get the last selected layer in the original, saved file:
Code: Select all
function LK_ExportLayerToTodoFolder:IsEnabled(moho)
if (moho.document:Path() ~= "") then
self.layerID = moho.document:LayerID(moho.layer)
self.docPath = moho.document:Path()
end
self.lastLayer = moho.layer
self.lastdoc = moho.document:Path()
return true
end
This only assumes that the newly opened file hasn't been saved yet. So this should work good with just Ctril+N and run the script once.
I also added a check to make sure it won't run on the saved file:
Code: Select all
function LK_ExportLayerToTodoFolder:Run(moho)
if (moho.document:Path() ~= "") then
return
end
if (self.docPath) then
local origdoc = moho:LoadDocument(self.docPath)
local name = origdoc:Layer(self.layerID):Name()
local newlayer = moho:DuplicateLayer(origdoc:Layer(self.layerID), false)
newlayer:SetName(name)
local targetPath = self.todoFolderPath..name..".moho"
moho:DestroyDocument(origdoc)
moho:FileSaveAs(targetPath)
moho:FileClose()
end
end
Re: How do I create a new moho file and copy a layer to it via script?
Posted: Mon Dec 04, 2023 3:11 pm
by hayasidist
Issue J305 raised regarding the odd behaviours of FileClose() when the Lua console window is open.