• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to get layers refs from inactive document (AAM)?

Guide ,
Oct 06, 2019 Oct 06, 2019

Copy link to clipboard

Copied

Good afternoon! I am writing a script that looks for layers with certain characteristics among open documents.

Is there a way to get references to layers of an inactive document through AAM (now my script switches to the next document in advance, but for the user this mode of operation is not very comfortable).

There are a lot of documents (usually more than 20, in each ~ 50 layers) - the DOM makes it possible to access layers of inactive documents, but it works very slowly when you need to iterate over all layers.

TOPICS
Actions and scripting

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
LEGEND ,
Oct 06, 2019 Oct 06, 2019

Copy link to clipboard

Copied

If I'm right you can't access layers from the document that is not active at the time. BTW what stands for 1st or 2nd 'A' in AAM?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 06, 2019 Oct 06, 2019

Copy link to clipboard

Copied

Adobe Action Manager. I'm used to calling through double A 🙂

In fact, if layers in another document were previously selected, then their referecnes can be obtained through targetLayers of the desired document. However, it’s still not nice to select all layers without switching to the document 😞

I’m trying to understand how xbytor receives layer descriptions from other documents in GetterDemo.lsx (it seems that it is implemented exactly as I need it).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2019 Oct 06, 2019

Copy link to clipboard

Copied

Adobe Action Manager. I'm used to calling through double A In fact, if layers in another document were previously selected, then their referecnes can be obtained through targetLayers of the desired document. However, it’s still not nice to select all layers without switching to the document The second day I’m trying to understand how xbytor receives layer descriptions from other documents in GetterDemo (it seems that it is implemented exactly as I need it), however, although I am a technical specialist, but not a developer and it’s hard for me to understand such a lot of code. Hoping there was a working solution

 

It's what I thought, but wanter to be sure. First A for Adobe, but normally everyone use AM only.

Hmm, you may be right, by DOM the document must be active, but maybe by ActionManager not...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 06, 2019 Oct 06, 2019

Copy link to clipboard

Copied

Found that in getterDemo.jsx also also made each document active before receiving the references of  its layers ðŸ˜ž 

 

I decided to do an exhaustive search of documents as follows:

 

 

function loopDocsByAM ()
{
     var ref = new ActionReference()
     ref.putProperty(s2t("property"), s2t("numberOfDocuments"))
     ref.putEnumerated(s2t("application"), s2t("ordinal"), s2t("targetEnum"))
     var len = executeActionGet(ref).getInteger(s2t("numberOfDocuments"))
    
    for (var i =0; i < len; i++)
    {
     /* doing something useful */
     selectPreviousDocument()
    } 
    
    function selectPreviousDocument() 
{
	var desc = new ActionDescriptor();
	var ref = new ActionReference();
	ref.putOffset( s2t( "document" ), -1);
	desc.putReference( s2t( "null" ), ref );
	executeAction( s2t( "select" ), desc, DialogModes.NO );
}  
    
function s2t(s) {return stringIDToTypeID(s)}
function t2s(t) {return typeIDToStringID(t)}
}

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 07, 2019 Oct 07, 2019

Copy link to clipboard

Copied

All the same, it is possible 🙂 I tried to access layer references through .putIndex (i.e., first specify the index of the document, and then the index of the layer in this document) - everything works. This code demonstrates how to get into the console all layer names (for example) of all open documents, without making these documents active.

 

 

// const of AM types
gApp = s2t("application")
gDoc = s2t("document")
gHasBackgroundLayer = s2t("hasBackgroundLayer")
gLayer =  s2t("layer")
gLayerSection = s2t("layerSection")
gName = s2t("name")
gNumberOfDocuments = s2t("numberOfDocuments")
gNumberOfLayers = s2t("numberOfLayers")
gOrdinal = s2t("ordinal")
gProp =  s2t("property")
gProp = s2t("property")
gTargetEnum = s2t("targetEnum")

// get number of docs
var ref = new ActionReference()
ref.putProperty(gProp, gNumberOfDocuments)
ref.putEnumerated(gApp, gOrdinal, gTargetEnum)
var docCounter = executeActionGet(ref).getInteger(gNumberOfDocuments)

// for each doc
for (var n = 1; n <=docCounter; n++)
{
    // get number of layers in n-doc
    var ref = new ActionReference()
    ref.putProperty(gProp, gNumberOfLayers)
    ref.putIndex (gDoc , n )
    var lrCounter = executeActionGet(ref).getInteger(gNumberOfLayers)
    
    // check and update counter if doc has 0-indexed background
    var ref = new ActionReference()
    ref.putProperty(gProp, gHasBackgroundLayer)
    ref.putIndex (gDoc , n )
    var shift = executeActionGet(ref).getBoolean(gHasBackgroundLayer) ? 0 : 1
    lrCounter += shift == 0 ? 1 : 0
    
    // for each layer in n-doc
    for (var i = shift; i<lrCounter; i++)
    {
            // skip layers closing groups 
            var ref = new ActionReference()
            ref.putProperty( gProp, gLayerSection) 
            ref.putIndex (gLayer, i )
            ref.putIndex (gDoc , n )
            if (t2s(executeActionGet(ref).getEnumerationValue(gLayerSection)) == 'layerSectionEnd') continue
            
            var ref = new ActionReference()
            ref.putProperty( gProp, gName) 
            ref.putIndex (gLayer, i )
            ref.putIndex (gDoc , n )

            $.writeln (executeActionGet(ref).getString(gName))
    }
}

function s2t(s) {return stringIDToTypeID(s)}
function t2s(t) {return typeIDToStringID(t)}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 07, 2019 Oct 07, 2019

Copy link to clipboard

Copied

LATEST

it is possible 🙂 I tried to access layer references through .putIndex (i.e., first specify the index of the document, and then the index of the layer in this document) - everything works. This code demonstrates how to log into the console all layer names (for example) of all open documents, without making these documents active.

 

 

// const of AM types
gApp = s2t("application")
gDoc = s2t("document")
gHasBackgroundLayer = s2t("hasBackgroundLayer")
gLayer =  s2t("layer")
gLayerSection = s2t("layerSection")
gName = s2t("name")
gNumberOfDocuments = s2t("numberOfDocuments")
gNumberOfLayers = s2t("numberOfLayers")
gOrdinal = s2t("ordinal")
gProp =  s2t("property")
gProp = s2t("property")
gTargetEnum = s2t("targetEnum")

// get number of docs
var ref = new ActionReference()
ref.putProperty(gProp, gNumberOfDocuments)
ref.putEnumerated(gApp, gOrdinal, gTargetEnum)
var docCounter = executeActionGet(ref).getInteger(gNumberOfDocuments)

// for each doc
for (var n = 1; n <=docCounter; n++)
{
    // get number of layers in n-doc
    var ref = new ActionReference()
    ref.putProperty(gProp, gNumberOfLayers)
    ref.putIndex (gDoc , n );
    var lrCounter = executeActionGet(ref).getInteger(gNumberOfLayers)
    
    // check and update counter if doc has 0-indexed background
    var ref = new ActionReference()
    ref.putProperty(gProp, gHasBackgroundLayer)
    ref.putIndex (gDoc , n );
    var shift = executeActionGet(ref).getBoolean(gHasBackgroundLayer) ? 0 : 1
    lrCounter += shift == 0 ? 1 : 0
    
    // for each layer in n-doc
    for (var i = shift; i<lrCounter; i++)
    {
            // skip closing groups layers
            var ref = new ActionReference()
            ref.putProperty( gProp, gLayerSection) 
            ref.putIndex (gLayer, i )
            ref.putIndex (gDoc , n )
            if (t2s(executeActionGet(ref).getEnumerationValue(gLayerSection)) == 'layerSectionEnd') continue;
            
            var ref = new ActionReference()
            ref.putProperty( gProp, gName) 
            ref.putIndex (gLayer, i )
            ref.putIndex (gDoc , n )

            $.writeln (executeActionGet(ref).getString(gName))
    }
}


function s2t(s) {return stringIDToTypeID(s)}
function t2s(t) {return typeIDToStringID(t)}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines