Highlighted

How do I select the graph of my GREP search?

Explorer ,
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
Adobe Community Professional
Correct answer by Peter Kahrel | Adobe Community Professional

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.

 

TOPICS
Feature request, How to, Scripting, Type

Views

522

Likes

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

How do I select the graph of my GREP search?

Explorer ,
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
Adobe Community Professional
Correct answer by Peter Kahrel | Adobe Community Professional

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.

 

TOPICS
Feature request, How to, Scripting, Type

Views

523

Likes

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

}

Likes

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
Reply
Loading...
Apr 06, 2020 1
Explorer ,
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

Likes

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
Reply
Loading...
Apr 06, 2020 0
Adobe Community Professional ,
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.

 

Likes

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
Reply
Loading...
Apr 07, 2020 1
Explorer ,
Apr 07, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Apr 07, 2020 0