How are individual layers from a .PSD defined in ASP11?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
Lukas
Posts: 1295
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

How are individual layers from a .PSD defined in ASP11?

Post by Lukas »

How are individual layers from a photoshop file defined in ASP11?

In ASP10 It used to be something like this:

Example.psd *5

(Layer 5 from Example.psd)

How is it done since v11? What has changed exactly? We used to have use a script to exchange layer sources but it is broken now and we're on a quite tight deadline.
User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Re: How are individual layers from a .PSD defined in ASP11?

Post by Víctor Paredes »

Hi Lukas,
I have a question: Is this a script to modify the text of an AS file, or a Lua script to run in the application to set a new image layer source?
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
Breinmeester
Posts: 303
Joined: Thu May 13, 2010 2:01 pm

Re: How are individual layers from a .PSD defined in ASP11?

Post by Breinmeester »

Hi Victor. It's the latter: a lua menu script to switch sourceimages. We have a PSD in which we have the character cut up. When we design a new character to that template, we run the script to replace all the images. It used to work in ASP10 where all the PSD layers were replaced with the corresponding layers of the new design. But since APS11 it doesn't work anymore and every layer is replaced with a full composite of the PSD, so all the layers merged together. I think the problem is with how ASP marks a PSD layer.

Can you help?
User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Re: How are individual layers from a .PSD defined in ASP11?

Post by Víctor Paredes »

Hi Lukas and Breinmeester, here's an answer from Mike Clifton:
"OK, so here’s what I can tell you:

In a PSD file, each layer has a unique ID. That ID will never get used twice in the same PSD file. In the past, AS referenced PSD layers from bottom to top: 0, 1, 2, 3, etc. But starting in AS 11, we reference PSD layers by this unique ID instead. Then benefit of this is that if you add new layers or re-arrange layers in the PSD file, we can still find the same layer by its unique ID, so changing layer arrangements in Photoshop doesn’t mess up Anime Studio. With the old method, changing layers in the PSD file would just mess things up in AS.

So that’s the background, now on to the issue. In AS 11, you can still use the same notation for assigning a layer. For example, this Lua code is still valid - it will assign layer 3 of a PSD file to the given image layer. I’m seeing just this PSD particular layer appear in the AS image layer as expected:

imageLayer:SetSourceImage(“/Document/Path/MyImage.psd*3*”)

But here’s the difference: You can assign a layer that way, but then internally, AS gets the unique ID that is inside the PSD file, and it remembers that. It forgets about the *3* notation because that’s not necessarily permanently valid, but the unique ID is. So later, if you call this Lua function:

print(imageLayer:SourceImage())

The result will be: /Document/Path/MyImage.psd without the *3* notation.

AS11 can still use the *3* notation for loading a file, but it no longer stores this internally.

I hope that helps."
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
Breinmeester
Posts: 303
Joined: Thu May 13, 2010 2:01 pm

Re: How are individual layers from a .PSD defined in ASP11?

Post by Breinmeester »

Ok, so there's the problem, because my script calls the sourceimage path using: imageLayer:SourceImage()
Then it looks for the '*' and parces out the LayerID to append it to the new path to call for the right layer in the new PSD file.
How can i call for the PSD layer ID of the sourceimage used in a layer in APS11?
User avatar
synthsin75
Posts: 9935
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: How are individual layers from a .PSD defined in ASP11?

Post by synthsin75 »

The only way I can think of, offhand, is to parse the PSD for layer IDs, but maybe AS stores the layer IDs as metadata. You'd need to look at the unzipped anime file to see.
Stan
Posts: 199
Joined: Sun Apr 19, 2009 3:22 pm

Re: How are individual layers from a .PSD defined in ASP11?

Post by Stan »

The best solution would be to ask the developers to add PSD layer numbering control to the Lua API. It shouldn't be too hard for them.
________________________________________________________________________
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: 9935
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: How are individual layers from a .PSD defined in ASP11?

Post by synthsin75 »

Just checked, and metadata does give you the psd IDs in AS layer ordering notation under the metadata key "psd_layers". It would be fairly simple to parse that metadata key's value for psd layer IDs and matching AS layer order, but I'm not sure about how to you'd get the matching psd layer order. The info is in the anime file, but you have to unzip it first and it's not easy to parse in its no-whitespace form.
User avatar
Lukas
Posts: 1295
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: How are individual layers from a .PSD defined in ASP11?

Post by Lukas »

Thanks for the info synthsin75.
I have unzipped the anime file, and browsed the json content of the .animeproj fileand there I found the info array/dictionairy containing the psd info (like the "psd_layer" and "psd_layerid")
But is this information available using LUA scripts?
I am trying to read the attributes available in the imagelayer, using pairs(), but I cannot print the key/value combination because it is an userdata object.

And is there somewhere I can find some information about PSD_LayerInfotable?
User avatar
Lost Marble
Site Admin
Posts: 2347
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Re: How are individual layers from a .PSD defined in ASP11?

Post by Lost Marble »

Lua doesn't have access to these unique PSD ID numbers. I'll add access to the next version of Anime Studio, but to be honest I'm not sure how useful it will be. These layer IDs are unique identifiers, and have no relation to the ordering of layers. For example, the bottom layer might have an ID of 27, and the next layer up might have an ID of 136.

Knowing the layer IDs allows Anime Studio to find the same layer again even if you add, remove, or rearrange layers in Photoshop. But it doesn't tell you anything about a layer in relation to its neighbors.

I think I'll also add some functions to let you ask what position a PSD layer is in the PSD layer stack (this is the old *5* notation), and the ability to change that. It sounds like that's what you're after here.

The tricky thing to keep in mind is this:

Anime Studio only loads images on demand. So when you open a document, if a particular image layer is not visible (visibility turned off, not an active switch layers, etc.), the image won't be loaded yet. And if that image is a layer in a PSD file, and Anime doesn't load it yet, it can't know if other layers have been added or removed from the PSD file since the last time it was loaded. The unique layer IDs don't ever change, that's why we switched to them. But if you rely on layer-by-order-IDs, and you add or remove layers in the PSD file, you might get surprises.

So, something to keep in mind. Layer-by-order is kind of fragile if you modify the PSD file's layers. That's why we switched to unique IDs.
User avatar
Lost Marble
Site Admin
Posts: 2347
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Re: How are individual layers from a .PSD defined in ASP11?

Post by Lost Marble »

I've added the following functions to the ImageLayer class that Lua scripts can use:

void SetSourceImage(const char *path); // set the path of an image - you can use filename.psd*5* notation if you want to
const char *SourceImage(); // return the path of the image being used - *5* notation will have been stripped off
bool IsPSDImage(); // true if the image layer is using a PSD file
void SetUniquePSDLayerID(int32 layerPSDID); // set the unique layer ID that you want to use
int32 UniquePSDLayerID(); // returns the unique ID
void SetPSDLayerOrderID(int32 layerOrderID); // set the layer to use based on its order in the PSD file (0 is the bottom layer, then 1, 2, 3, etc.)
int32 PSDLayerOrderID(); // returns the layer ID by order that is being used
void UnloadImage(); // unloads the image from memory - AS will load it back in if and when it needs to use it

SetSourceImage() and SourceImage() already existed. The others are new.

I think you guys are in the beta - these functions will be available in the next beta release.
Breinmeester
Posts: 303
Joined: Thu May 13, 2010 2:01 pm

Re: How are individual layers from a .PSD defined in ASP11?

Post by Breinmeester »

Thanks Mike! That helps a lot!
User avatar
Lukas
Posts: 1295
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: How are individual layers from a .PSD defined in ASP11?

Post by Lukas »

Thanks! We'll be testing it asap.

By the way, the release on november 9th is 17881, but the release on november 3rd was also 17881. Maybe something went wrong?
User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Re: How are individual layers from a .PSD defined in ASP11?

Post by Víctor Paredes »

Thank you very much, Mike
Lukas wrote:By the way, the release on november 9th is 17881, but the release on november 3rd was also 17881. Maybe something went wrong?
I just checked, November 3rd was 17811, this one is 17881 :)
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
User avatar
Lukas
Posts: 1295
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: How are individual layers from a .PSD defined in ASP11?

Post by Lukas »

Víctor Paredes wrote:Thank you very much, Mike
Lukas wrote:By the way, the release on november 9th is 17881, but the release on november 3rd was also 17881. Maybe something went wrong?
I just checked, November 3rd was 17811, this one is 17881 :)
Ahhhhh, so confusing! I actually double checked it... I guess I have numberdyslexia :shock:
Post Reply