Getting all the styles in a document?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
mkelley
Posts: 1647
Joined: Fri Nov 02, 2007 5:29 pm
Location: Sunny Florida
Contact:

Getting all the styles in a document?

Post by mkelley »

Perhaps it's a change in 10/11 or maybe it never worked this way, but I can't get a style to get called.

I see by the docs it *ought* to be:

moho.document:Style(id) or moho.document:Style(name) but trying to cycle through the styles I am getting nowhere with:

for i = 0, moho.document:CountStyles() - 1 do -- this returns count ok
local thisstyle = moho.document:Style(i) -- this returns nil

If I DO call it with a name it works (so moho.document:Style("Skin") returns a style if there is one named Skin). Doesn't help me much if I don't know the names in advance, though.

Anyone have a clue?
GaryC
Posts: 53
Joined: Tue Feb 03, 2015 1:02 pm

Re: Getting all the styles in a document?

Post by GaryC »

I was looking into this and unfortunately didn't get anywhere, but to shed some light on some confusing behaviour I did figure one thing out.

Styles are now using UUIDs instead of just integers. So instead of styles being 1, 2, 3, 4, 5 etc., they're 32 character hexadecimal strings. So you'd need to be doing something like

Code: Select all

moho.document:Style("68267908-f00f-45f9-a943-d703f299fe71")
The reason for changing this was to prevent id's clashing when you import between scenes I believe.

There is a theoretical version that could work for smaller files to do this occasionally. You could loop through shapes and get the names of all their styles. In our case it was going to be impractical because of the size of scenes but you might manage it for a tool script on smaller scenes. Alternatively if your needs could allow you to just edit the file outside Anime Studio, I'd run a Python script that opens the file's data to look at the style info there.
Post Reply