Create new layercomp from toolscript

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
JeroenKoffeman
Posts: 32
Joined: Tue Mar 24, 2015 3:04 pm

Create new layercomp from toolscript

Post 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
Stan
Posts: 199
Joined: Sun Apr 19, 2009 3:22 pm

Re: Create new layercomp from toolscript

Post by Stan »

I think the only way to create a layercomp is the Layers panel in Anime Studio UI... :(
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
JeroenKoffeman
Posts: 32
Joined: Tue Mar 24, 2015 3:04 pm

Re: Create new layercomp from toolscript

Post 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
User avatar
synthsin75
Posts: 9964
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Create new layercomp from toolscript

Post 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.
User avatar
hayasidist
Posts: 3500
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Create new layercomp from toolscript

Post 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!!
User avatar
synthsin75
Posts: 9964
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Create new layercomp from toolscript

Post by synthsin75 »

Yeah, that's the first thing I mentioned in the bug report, Paul.
Stan
Posts: 199
Joined: Sun Apr 19, 2009 3:22 pm

Re: Create new layercomp from toolscript

Post by Stan »

Hi Wes,
Was the bug resolved in Moho 12?
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
User avatar
synthsin75
Posts: 9964
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Create new layercomp from toolscript

Post 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()
Stan
Posts: 199
Joined: Sun Apr 19, 2009 3:22 pm

Re: Create new layercomp from toolscript

Post by Stan »

Great, thank you Wes!
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
Post Reply