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)
How do I create a new moho file and copy a layer to it via script?
Moderators: Víctor Paredes, Belgarath, slowtiger
- hayasidist
- Posts: 3830
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: How do I create a new moho file and copy a layer to it via script?
Thanks Wes. I'll aim to put a bug report together on this re FileClose with an active Lua console window...
- synthsin75
- Posts: 10253
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: How do I create a new moho file and copy a layer to it via script?
I thought of copying the contents, but I didn't know if this could occasionally be used on group layers too.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
- synthsin75
- Posts: 10253
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: How do I create a new moho file and copy a layer to it via script?
This should be a reliable way to get the last selected layer in the original, saved file:
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: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
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
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
- hayasidist
- Posts: 3830
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: How do I create a new moho file and copy a layer to it via script?
Issue J305 raised regarding the odd behaviours of FileClose() when the Lua console window is open.