Script Recipes
Posted: Thu Feb 23, 2017 5:13 pm
I'm wondering, especially with recent changes in Moho, if others would find it valuable to have a collection of scripting recipes? I've started doing that on my own, because it helps me remember how to do common things.
As an example, I've been wanting to rename styles. The reason is that I start with a common rig for creating characters, but I'd like their styles to be unique, because even if you unlink shared styles they have the same names, so it can be hard to find which style matches which character. The problem is that I've never been able to get Moho:RenameStyle to work. So my recipe for that would be
Rename Style
Rename the first style to "lulu". Shapes using the first style will be updated so that the new name is displayed.
Another example might be
Process top level layers
CoutLayers enumerates the top level layers. This code allows you to run through the top level layers.
As an example, I've been wanting to rename styles. The reason is that I start with a common rig for creating characters, but I'd like their styles to be unique, because even if you unlink shared styles they have the same names, so it can be hard to find which style matches which character. The problem is that I've never been able to get Moho:RenameStyle to work. So my recipe for that would be
Rename Style
Rename the first style to "lulu". Shapes using the first style will be updated so that the new name is displayed.
Code: Select all
local firstStyle = self.moho.document:StyleByID(0)
if firstStyle ~= nil then
firstStyle.fName:Set("lulu")
end
Process top level layers
CoutLayers enumerates the top level layers. This code allows you to run through the top level layers.
Code: Select all
for i = 0, self.moho.document:CountLayers()-1 do
local layer = self.moho.document:LayerByAbsoluteID(i)
-- do some work here
end