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: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

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

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

Post by Lukas » Tue Nov 03, 2015 1:12 pm

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
Posts: 4952
Joined: Wed Jan 26, 2005 12:18 am
Location: Ireland/Chile
Contact:

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

Post by Víctor Paredes » Thu Nov 05, 2015 6:46 pm

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?
Víctor Paredes
Former Moho Product Manager
Rigger and animator in Cartoon Saloon
My Youtube Channel - My webinars
Breinmeester
Posts: 294
Joined: Thu May 13, 2010 2:01 pm

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

Post by Breinmeester » Fri Nov 06, 2015 4:48 pm

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
Posts: 4952
Joined: Wed Jan 26, 2005 12:18 am
Location: Ireland/Chile
Contact:

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

Post by Víctor Paredes » Fri Nov 06, 2015 8:35 pm

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."
Víctor Paredes
Former Moho Product Manager
Rigger and animator in Cartoon Saloon
My Youtube Channel - My webinars
Breinmeester
Posts: 294
Joined: Thu May 13, 2010 2:01 pm

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

Post by Breinmeester » Sat Nov 07, 2015 5:52 pm

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: 7241
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 » Sat Nov 07, 2015 10:22 pm

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: 132
Joined: Sun Apr 19, 2009 3:22 pm
Contact:

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

Post by Stan » Sat Nov 07, 2015 11:35 pm

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.
________________________________________________________________________
http://mohoscripting.com/ - Unofficial Moho (Anime Studio) Lua Scripting Documentation
http://2danimator.ru/ - Russian Anime Studio Forum
User avatar
synthsin75
Posts: 7241
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 » Sun Nov 08, 2015 1:35 am

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: 811
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 » Mon Nov 09, 2015 4:20 pm

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: 2193
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 » Mon Nov 09, 2015 7:14 pm

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: 2193
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 » Tue Nov 10, 2015 12:17 am

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: 294
Joined: Thu May 13, 2010 2:01 pm

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

Post by Breinmeester » Tue Nov 10, 2015 9:01 am

Thanks Mike! That helps a lot!
User avatar
Lukas
Posts: 811
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 » Tue Nov 10, 2015 9:14 am

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
Posts: 4952
Joined: Wed Jan 26, 2005 12:18 am
Location: Ireland/Chile
Contact:

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

Post by Víctor Paredes » Tue Nov 10, 2015 2:07 pm

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 :)
Víctor Paredes
Former Moho Product Manager
Rigger and animator in Cartoon Saloon
My Youtube Channel - My webinars
User avatar
Lukas
Posts: 811
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 » Tue Nov 10, 2015 3:15 pm

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