Discussion:
it can not search the text with Grep, what's wronge with my code?
(too old to reply)
r***@adobeforums.com
2009-02-16 04:23:40 UTC
Permalink
Hi scripter,

I got a Arabian files that include English and arabian fonts, but i need to find Arabian to change Fonts style. my grep may got some pro. please see the below:

//Clear the find/change preferences.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
//Regular expression for finding an email address.
app.findGrepPreferences.findWhat = "[^A-Za-z0-9/.-]+";
//Apply the change to 24-point text only.
app.findGrepPreferences.pointSize = 24;
app.changeGrepPreferences.underline = true;
app.documents.item(0).changeGrep();
//Clear the find/change preferences after the search.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
r***@adobeforums.com
2009-02-16 07:02:48 UTC
Permalink
Dear robin521,

I saw your code, and below I have to change the code

Your code :
//Regular expression for finding an email address.
app.findGrepPreferences.findWhat = "[^A-Za-z0-9/.-]+";

Change Code:
//Regular expression for finding an email address.
app.findGrepPreferences.findWhat = [A-Za-z0-9._%-]+@(?:[A-Za-z0-9-]+\.)+([A-Za-z]*)

Please use the above code and get correct answers, Let me know if you have any queries.

Thanks & Regards
T.R.Harihara SudhaN
Peter Kahrel
2009-02-16 09:25:48 UTC
Permalink
Do you want to find Arabic or email addresses? Whichever, in your other topic on the same subject I replied that your GREP is faulty:

app.findGrepPreferences.findWhat = "[^A-Za-z0-9/.-]+";




should be

app.findGrepPreferences.findWhat = "[^A-Za-z0-9\\.-]+";




But this isn't going to find Arabic or email addresses: it finds everything that's not an unaccented Latin letter, a digit, dot, or hyphen.

Peter
r***@adobeforums.com
2009-02-18 07:58:32 UTC
Permalink
Hi Peter,

yes, you are right! I need to find Arabic and i have been change my Grep, But there are still has no responses with my Indesign.





if(app.documents.length ==0){
alert("您没有打开任何文档!");
}

//Clear the find/change preferences.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
//找到匹配的阿拉伯文文字进行修改.
app.findGrepPreferences.findWhat = "[^A-Za-z0-9\\.-]+";
app.changeGrepPreferences.underline = true;
app.documents.item(0).changeGrep();
//Clear the find/change preferences after the search.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
j***@adobeforums.com
2009-02-18 09:58:23 UTC
Permalink
The

findWhat




specifies what is searched for. You'll have to change that.
Peter Kahrel
2009-02-18 10:02:12 UTC
Permalink
How is the Arabic coded? In your InDesign document, select a character which you expected to be found but isn't and press F8 to display the Info panel. Somewhere in the centre of the panel you see "Unicode: " followed by a unicode value. Tell us what you see there.

Peter
r***@adobeforums.com
2009-02-23 06:41:07 UTC
Permalink
Hi peter,

Sorry for late, i can not post my message.
I got it, Cause of low memory, I have already change it, but how can i change desiredWordSpacing=130 what i find? I need to change all character to desiredWordSpacing=130.




try{
if(app.documents.length ==0){
alert("您没有打开任何文档!");
}
}
catch(e){

}

//Clear the find/change preferences.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
//找到匹配的阿拉伯文文字进行修改.
app.findGrepPreferences.findWhat = "[^A-Za-z0-9\\.-]+";
app.changeGrepPreferences.appliedFont="Arial"
app.documents.item(0).changeGrep();
//Clear the find/change preferences after the search.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
Peter Kahrel
2009-02-23 06:53:55 UTC
Permalink
desiredWordSpace applies to paragraphs. What you're after is probably tracking.

Peter
r***@adobeforums.com
2009-02-23 09:35:56 UTC
Permalink
Hi Peter,

when i found the text base on GREP, Need to increase 30 percent PointSize and change font, Now, I found that needn't to change desiredWordSpacing, PointSize is ok.(pointSize*1.3)

I have two questions, how can i get the fontlist of current document and display on menu or dialogs, can i return a int in order to increase pointSize.

Thanks very much.
Regards,
Robin
Peter Kahrel
2009-02-23 19:31:22 UTC
Permalink
I have two questions, how can i get the fontlist of current document and
display on menu or dialogs




Just get an array of font names, probably something like myDoc.fonts.everyItem().name and display it in a dropdown list in a dialog.

can i return a int in order to increase pointSize.




Sure.

Peter
r***@adobeforums.com
2009-03-02 12:03:54 UTC
Permalink
Hi Peter,

how can i get current fonts style and pointsize when i search it by grep, i mean, i need to find the word by grep but when this fonts is different style i need to change it and different pointsize also.



main();
function main(){
if(app.documents.length != 0){
if(app.activeDocument.pageItems.length != 0){

}
else{
alert("Document contains no page items.");
}
}
else{
alert("Please open a document and try again.");
}
}

var MyFontList=new Array;

MyFontList=app.fonts.everyItem().name;



var MyDialog=app.dialogs.add({name:"change your heart"});
with(MyDialog){

with(dialogColumns.add()){
with(borderPanels.add()){
staticTexts.add({staticLabel:"target:"});
}
with(dialogColumns.add()){
var myMenu=dropdowns.add();
myMenu.stringList=MyFontList;
myMenu.selectedIndex=0;

}
}
var myResult=MyDialog.show();
if(myResult== true )
{
var changeWord=myMenu.selectedIndex;
var changeTo=app.fonts[changeWord].name;
alert("you cange the font to"+changeTo)
FindGrep();

}

else{
alert ("you are fault")
}
MyDialog.destroy();

}

function FindGrep(){
//Clear the find/change preferences.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
//find
app.findGrepPreferences.findWhat = "[^A-Za-z0-9/.-]+";

app.changeGrepPreferences.appliedFont=changeTo;
var myFoundItem= app.findGrep ();
if(app.changeGrepPreferences.pointSize=app.findGrepPreferences.pointSize){
var number=0;
number=app.findGrepPreferences.pointSize
number=1.3*number;
number=app.changeGrepPreferences.pointSize;
}
app.changeGrepPreferences.underline = true;
app.documents.item(0).changeGrep();
//Clear the find/change preferences after the search.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;

}
Peter Kahrel
2009-03-02 12:37:37 UTC
Permalink
you say,

if (app.changeGrepPreferences.pointSize=app.findGrepPreferences.pointSize)




but for comparison, you need ==, not =. There's also not much point comparing these two if you haven't set them first. And when you set them like that there's no need to compare them, if you follow me.

You need something like this:

var myFoundItem = app.findGrep ();
for (var i = 0; i < myFoundItem.length; i++)
if (myFoundItem[i].pointSize == 11 && myFoundItem[i].fontStyle == 'Italic')
// do something



The way you've coded the last part of the script and that you use 'myFoundItem' rather than 'myFoundItems' suggest that you don't really understand what app.findGrep () does. Before you continue to tinker with existing scripts you should take some time to learn more about JavaScript. It'll save you much time in the end.

Peter
r***@adobeforums.com
2009-03-02 13:40:42 UTC
Permalink
Hi peter,

Again, Thank you very much, I think i must learn more about JavaScript.

Robin,
Regards

Loading...