Page 1 of 1
Create new layercomp from toolscript
Posted: Wed Feb 24, 2016 2:56 pm
by JeroenKoffeman
For our pipeline, Im writing a tool script that automatically generates layercomps.
However, I am not able to create a new layercomp through scripting.
I'm using:
moho.document:AddLayerComp()
But I need to refer to a LayerComp object. How to create a new one?
Thanks in advance!
Jeroen
Re: Create new layercomp from toolscript
Posted: Fri Feb 26, 2016 6:56 pm
by Stan
I think the only way to create a layercomp is the Layers panel in Anime Studio UI...

Re: Create new layercomp from toolscript
Posted: Tue Mar 08, 2016 1:25 pm
by JeroenKoffeman
Thanks Stan, I suppose there must be a way, as the function is there:
moho.document:AddLayerComp()
When I call this function, the lua console outputs:
argument 2 is no object: 'LayerComp expected. So my guess was:
local comp = MOHO.LayerComp:new_local()
moho.document:AddLayerComp(comp)
But the LayerComp Class has no function called 'new_local()'. I'm sure it must be possible, I just cannot find it in the reference, the only place with documentation about layercomp scripting is aslua.com
Re: Create new layercomp from toolscript
Posted: Tue Mar 08, 2016 7:31 pm
by synthsin75
Yeah, I tried that. There seems to be a bug in the layer comp script access. It does actually do something, but you can't see it until you save/reopen the file. You have to copy an existing comp, since we can't create a new one. And closing the file after running this will crash AS every time:
Code: Select all
local doc = moho.document
local name = LM.String:new_local()
name:Set('new comp')
local id = doc:CountLayerComps()-1
local comp = doc:GetLayerComp(id)
doc:AddLayerComp(comp)
doc:GetLayerComp(id+1):SetName(name)
It also renames 2 comps, so I assume the crash is related to AS somehow confusing memory spaces or something. I'll report the bug.
Re: Create new layercomp from toolscript
Posted: Tue Mar 08, 2016 8:48 pm
by hayasidist
ha! beat me to it... I'd just done the same - duplicate the last -- and *crash* with all the layer comps named the same as the one I'd just created .. I'd been looking for a bug in my code... kinda glad to see it wasn't me...
Wes, If you're logging a bug - could you ask for a :new() and :new_local() as well please!! Ta!!
Re: Create new layercomp from toolscript
Posted: Tue Mar 08, 2016 10:06 pm
by synthsin75
Yeah, that's the first thing I mentioned in the bug report, Paul.
Re: Create new layercomp from toolscript
Posted: Mon Aug 15, 2016 1:24 am
by Stan
Hi Wes,
Was the bug resolved in Moho 12?
Re: Create new layercomp from toolscript
Posted: Mon Aug 15, 2016 1:59 am
by synthsin75
Stan wrote:Hi Wes,
Was the bug resolved in Moho 12?
Yes, I tested it when it was fixed.
moho.document:AddLayerCompWithName("someName")
moho:UpdateUI()
Re: Create new layercomp from toolscript
Posted: Mon Aug 15, 2016 2:47 am
by Stan
Great, thank you Wes!