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

How do I select the graph of my GREP search?

Explorer ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

How do I select the graph of my GREP search?

GREP only selects the text space of the image, but I need to select the graphic that is within that space (.eps).

 

app.findGrepPreferences = null;app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat="~a";///FIND image .eps
var myFinds = app.findGrep();
app.findGrepPreferences = null;app.changeGrepPreferences = null;
var img = app.activeDocument.allGraphics;
var myDocument=app.activeDocument;
for (var i = 0i < myFinds.lengthi++) {
        myFinds[i].select();// SELECT THE TEXT SPACE
        ///??????here?????? //SELECT THE GRAPH .eps 
        //THEN TO THE GRAPHIC I APPLY
        var fp = app.selection[0].graphics[0].itemLink.filePath;
        var f = File(fp);f.open('r');var fs = f.read();f.close();
        alert("the file path is : " + "\n" + fp);
}
duda.JPG
Carpe diem
TOPICS
Feature request , How to , Scripting , Type

Views

754

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

Community Expert , Apr 07, 2020 Apr 07, 2020

Moises -- You rarely need to select anything in scripting, and you should avoid it as much as possible because selections aren't stable and often behave in unexpected ways.

~a finds characters, which you can check in the ESTK's debugger (or whatever you use). Characters can have rectangles, and rectangles can contain images. So this:

myFinds[i].rectangles[0].images[0]

gets you the image. But you want to get the image's file path, which you can get only through its link:

myFinds[i].rectangles[0].
...

Votes

Translate

Translate
Explorer ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

I think you are trying to select it with the wrong tool.

 

Try:

var links = app.activeDocument.links;

 

Then you can loop through each link and do anything you need with it.

 

for (var i = 0; i < links.length; i++) {

        alert("The file path is " + links[i].filePath);

}

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
Explorer ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

Hello Friend, but I want to select the graph as if it were the selection tool.

Carpe diem

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 07, 2020 Apr 07, 2020

Copy link to clipboard

Copied

Moises -- You rarely need to select anything in scripting, and you should avoid it as much as possible because selections aren't stable and often behave in unexpected ways.

~a finds characters, which you can check in the ESTK's debugger (or whatever you use). Characters can have rectangles, and rectangles can contain images. So this:

myFinds[i].rectangles[0].images[0]

gets you the image. But you want to get the image's file path, which you can get only through its link:

myFinds[i].rectangles[0].images[0].itemLink.filePath

and now you can open and read the contents of the EPS image.

This is a very roundabout and time-consuming way of doing things. Yalda is right: it's much simpler to go through the links collection.

P.

 

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
Explorer ,
Apr 07, 2020 Apr 07, 2020

Copy link to clipboard

Copied

LATEST
app.findGrepPreferences = null;app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat="~a";       ///FIND image
var myFinds = app.findGrep();
app.findGrepPreferences = null;app.changeGrepPreferences = null;
 for (var i = 0; i < myFinds.length; i++) {
        var rectan=myFinds[i].rectangles[0].allGraphics[0];
        var path_file =rectan.itemLink.filePath;
        alert(path_file);
} 

Thank you Mr. Peter, with your explanation I found another way without using ".select ()".

Carpe diem

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