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

Trying to Access the Arrays of Images or Pdfs or Epss

Enthusiast ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

Hi Experts

I was playing with the arrays of Items, so i can access those types of arrays as you see i can get text frames or any items or polygons, also with the same method i can access the others like (ovals - rectangles - graphiclines) :

var allFrames = app.activeDocument.allPageItems;
var allFrames = app.documents[0].pages.everyItem().textFrames.everyItem().getElements(); 
var allFrames = app.documents[0].pages.everyItem().pageItems.everyItem().getElements(); 
var allFrames = app.activeDocument.pages.everyItem().polygons.everyItem().getElements(); 

 but i can't access the Images(content) or pdfs or epss in the containers like( rectangles - ovals - groups..etc), i tried for Images :

var allFrames = app.activeDocument.pages.everyItem().images.everyItem().getElements();

 also can't access pdf or epss :

var allFrames = app.activeDocument.pages.everyItem().epss.everyItem().getElements();

var allFrames = app.activeDocument.pages.everyItem().pdfs.everyItem().getElements();

what im trying to get is control their movements (like) :

var allFrames = app.activeDocument.pages.everyItem().groups.everyItem();
allFrames.move(undefined , [0 ,"100mm"]);

so this is working with all items except the (images - pdfs - epss) ?, maybe i miss something? or miss understand the correct way of access!, i get the error (object doesnt support the property or method (images - pdfs - epss)  message), so please help? and thanks in Advance

Best
Mohammad Hasanin
TOPICS
Scripting

Views

435

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 4 Correct answers

Community Expert , Apr 25, 2022 Apr 25, 2022

Hi @M.Hasanin,

The error you get says it all, there are no such collections in the object model for you to access. What you can do rather is iterate the links collection and check the linkType property to identify the type of placed object. Run the following code and it will alert the type of each placed content.

for(var i = 0; i < app.documents[0].links.length; i++)
	alert(app.documents[0].links[i].linkType)

-Manan

Votes

Translate

Translate
Community Expert , Apr 26, 2022 Apr 26, 2022

Hi M. Hasanain,

you could loop the allGraphics array of the document.

That will also catch graphics or images that have no link in the Links panel.

Like ones where someone pasted a selection of pixels from e.g. PhotoShop to InDesign, just to name one example.

 

With properties like parentPage or imageTypeName you could build a list of e.g. EPS graphics that are on a particular page.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate
Community Expert , Apr 26, 2022 Apr 26, 2022

Well, there are three samples of pasted in pixel graphics where imageTypeName throws this error:

ERROR: 30615, The property is not applicable in the current state.

 

So do your try catch without exit() and perhaps log the occurences.

 

That's all to it.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate
Community Expert , Apr 26, 2022 Apr 26, 2022

You could. But you only get good results with objects that are not converted from e.g. type rectangle to type oval.

At least not when you resolve the specifier of the parent of a graphic with:

 

graphics[n].parent.getElements()[0] 

 

and ask for e.g. the constructor and its name:

 

graphics[n].parent.getElements()[0].constructor.name

 

 

Example:

When the user created an oval or a rectangle with the appropriate tool, like the Oval Frame tool or the Rectangle Frame tool and did not use the method

...

Votes

Translate

Translate
Community Expert ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

Hi @M.Hasanin,

The error you get says it all, there are no such collections in the object model for you to access. What you can do rather is iterate the links collection and check the linkType property to identify the type of placed object. Run the following code and it will alert the type of each placed content.

for(var i = 0; i < app.documents[0].links.length; i++)
	alert(app.documents[0].links[i].linkType)

-Manan

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
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Hi M. Hasanain,

you could loop the allGraphics array of the document.

That will also catch graphics or images that have no link in the Links panel.

Like ones where someone pasted a selection of pixels from e.g. PhotoShop to InDesign, just to name one example.

 

With properties like parentPage or imageTypeName you could build a list of e.g. EPS graphics that are on a particular page.

 

Regards,
Uwe Laubender

( ACP )

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 ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Thanks a lot @Laubender @Manan Joshi 

now i understand what i miss

 

Best
Mohammad Hasanin

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 ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Hi @Laubender 

I tried your suggestion and  it works partiely and stopped and get strange error, can you please tell me what the wrong?

var docgrphs = app.activeDocument.allGraphics;

function MoveGraphicsJPEG(){
   try{
    for( var i=0; i<docgrphs.length; i++ ){
        if(docgrphs[i].imageTypeName == "JPEG"){
            docgrphs[i].move(undefined , [0 ,"3mm"]);
                }
            }
        }catch(myerror){ 
            alert (myerror,"Error");
            exit();
                }
            }
MoveGraphicsJPEG();

also i tried the following :

var docgrphs = app.activeDocument.allGraphics;

function ScanGraphics(){
           try{
        if (docgrphs == ""){
                alert ("No Graphics Items Found! or Something Wrong!","ERROR");
                exit(); 
        }
            MoveGraphicsJPEG();
    }catch(myerror){ 
            alert (myerror,"ERROR");
            exit(); 
    }
}
        
function MoveGraphicsJPEG(){
        while (graphicitems = docgrphs.pop()) { 
            if(graphicitems.imageTypeName == "JPEG"){
                graphicitems.move(undefined , [0 ,"3mm"]);
        }           
    }
    alert ("Done!","Finish");
}

app.doScript(ScanGraphics, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Move JPEG All Graphics");

in both examples it works partiely and stopped and i get the error catched (the same) as (The property is not applicable in the current state! :

The property is not applicable in the current state.jpg

So please what i have done wrong! and thanks in advance

Best
Mohammad Hasanin

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
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Well, could it be that you have locked items?

Or items that are anchored in overset text?

 

Write a log with the errors. Do not exit the loop. Instead continue the loop to the next graphic in the array.

Detect all the graphics where your code fails. Read out their id numbers and later, when you see the whole picture, only some fail vs all fail, try to select the failed graphics one by one with e.g.:

app.documents[0].pageItems.itemByID( ID-Number ).select();

Or add a red rectangle stacked over a failed graphic so that it is easy to identify it in your layout.

 

Regards,
Uwe Laubender

( ACP )

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 ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Hi @Laubender 

Actually nothing locked in the file, here is the link of the Pacakged project (its just test file) not real project including multiple graphics formats beside some text frames (for test), kindley please examine by yourself , download from here :

InDesign Item Tests 

i noticed if  i remove the (if condition) the error is gone! but ofcourse all kind of graphics is moved! :

 

if(graphicitems.imageTypeName == "JPEG")

 

or

 

if(docgrphs[i].imageTypeName == "JPEG")

 

anyway thanks a lot for your reply . i will try your sugessions

Best
Mohammad Hasanin

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
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Well, there are three samples of pasted in pixel graphics where imageTypeName throws this error:

ERROR: 30615, The property is not applicable in the current state.

 

So do your try catch without exit() and perhaps log the occurences.

 

That's all to it.

 

Regards,
Uwe Laubender

( ACP )

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 ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Thanks @Laubender a lot

Can i test if the Image (JPEG) is inside Oval or Rectangle frame? to add this condition? or this is not possible and thanks alot

Best
Mohammad Hasanin

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
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

You could. But you only get good results with objects that are not converted from e.g. type rectangle to type oval.

At least not when you resolve the specifier of the parent of a graphic with:

 

graphics[n].parent.getElements()[0] 

 

and ask for e.g. the constructor and its name:

 

graphics[n].parent.getElements()[0].constructor.name

 

 

Example:

When the user created an oval or a rectangle with the appropriate tool, like the Oval Frame tool or the Rectangle Frame tool and did not use the method to convert the object you can identify as Oval or Rectangle with the method above.

 

Regards,
Uwe Laubender

( ACP )

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 ,
Apr 27, 2022 Apr 27, 2022

Copy link to clipboard

Copied

LATEST

@Laubender Thanks a lot, i will give it a try, have a great day

Best
Mohammad Hasanin

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