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

Get app.documents[???] for the activeDocument

Enthusiast ,
Aug 29, 2011 Aug 29, 2011

Copy link to clipboard

Copied

An example:

I have 10 opened images in photoshop.

I start working on the last one, then the one before, and so on until the 8th image.

1, 2, 3, 4, 5, 6 are opened

7, 8, 9 are finished and must be saved.

I want an action that will save the activeDocument and all the ones after that: in the example will save the 7th 8th and 10th image.

Is this possible?

I have everything but I don't know how to get the number for the activeDocument >>> app.documents[???]

TOPICS
Actions and scripting

Views

1.1K

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

correct answers 1 Correct answer

Guru , Aug 29, 2011 Aug 29, 2011

Here is a quick way to get the index of the activeDocument.

function getActiveDocumentIndex(){
     var ref = new ActionReference();
     ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
     return desc = executeActionGet(ref).getInteger(stringIDToTypeID('itemIndex'))-1;
};
alert('The activeDocument is app.documents['+getActiveDocumentIndex()+']');

Votes

Translate

Translate
Adobe
Guru ,
Aug 29, 2011 Aug 29, 2011

Copy link to clipboard

Copied

Here is a quick way to get the index of the activeDocument.

function getActiveDocumentIndex(){
     var ref = new ActionReference();
     ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
     return desc = executeActionGet(ref).getInteger(stringIDToTypeID('itemIndex'))-1;
};
alert('The activeDocument is app.documents['+getActiveDocumentIndex()+']');

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
Advisor ,
Aug 29, 2011 Aug 29, 2011

Copy link to clipboard

Copied

The quick way doesn't always work.

For instance:

1) File > New...

2) 3D > New Shape From Layer > Cube Wrap

3) Image > Duplicate...

Then run your code (slightly modified):

function getActiveDocumentIndex(){
     var ref = new ActionReference();
     ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
     return desc = executeActionGet(ref).getInteger(stringIDToTypeID('itemIndex'))-1;
};
var index = getActiveDocumentIndex();
alert('The activeDocument is app.documents['+getActiveDocumentIndex()+']');
alert(app.documents[index].name);

It thinks the duplicated doc is [2] instead of [1] then fails when you try to get the name. This is apparently an artifact of the 3D system introducing new pseudo-documents internally when you have 3D layers.

You end up have to use something like this to get the actual DOM index:

function getDocumentIndex(doc) {
  var docs = app.documents;
  for (var i = 0; i < docs.length; i++) {
    if (docs == doc) {
      return i+1;
    }
  }

  return -1;

};

This is a CS5/Extended problem but the problem may present itself in other ways.

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
Guru ,
Aug 29, 2011 Aug 29, 2011

Copy link to clipboard

Copied

I have never run into that before. But then again I don't do much with 3D.

I still like getting the index directly instead of looping so I think I will try to come up with an Action Manger fix.

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
Advisor ,
Aug 29, 2011 Aug 29, 2011

Copy link to clipboard

Copied

But then again I don't do much with 3D.

Nor do I, but I have very thorough beta testers. There may also be other cases that cause this problem that I don't recall. I just changed my code to compensate for the problem.

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
Enthusiast ,
Aug 30, 2011 Aug 30, 2011

Copy link to clipboard

Copied

Thanks Michael

That's what I needed.

I only need to apply it to opened photos (never new documents) and I do not need 3D

Tks

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
Advisor ,
Aug 30, 2011 Aug 30, 2011

Copy link to clipboard

Copied

LATEST
I only need to apply it to opened photos (never new documents) and I do not need 3D

The problem I noted happens with new or existing documents that contain 3D shape layers. It can apparently happen with docs containing certain Smart Object or Smart Filter layers but I haven't been able to replicate those cases.

The important point here is that there are (undocumented) situations where the index in a document's descriptor may not correspond to the document's DOM index.

-X

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