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

Find text then add a character style script

Explorer ,
Mar 22, 2017 Mar 22, 2017

Copy link to clipboard

Copied

Hello

I am trying to make a script to find any text between two glyphes ( ﴾ ﴿ ) and create a new character style for the selected text .

note : i do not want to apply a character style on the selected text , but i want to create a new character style for the selected text .

note : i do "find what "correctly but i do not know how to complete the script .

i am start but i do not know how to complete  :

function main()      

    { 

        var myDoc = app.activeDocument, 

        FindWhat = "(?<=\﴿).+?(?=\﴾)";  // The 2 glyphes are " ﴿ " and " ﴾ "  

TOPICS
Scripting

Views

7.2K

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

Guide , Mar 25, 2017 Mar 25, 2017

Moreover the below script completes with all character style properties..

app.findGrepPreferences = app.changeGrepPreferences =null;        

app.findGrepPreferences.findWhat = "(?<=\﴿).+?(?=\﴾)"       

var found = app.documents[0].findGrep();    

if(found.length==0){alert("No bracket text found"); exit(0);}

cstyle = [];   

for(j=0; j<found.length; j++)        

{  

  cstyle.push(found.contents);

}

for(k=0; k<cstyle.length; k++)        

{  

 

app.findGrepPreferences = app.changeGrepPreferences =null; 

...

Votes

Translate

Translate
Engaged ,
Mar 22, 2017 Mar 22, 2017

Copy link to clipboard

Copied

Hi,

Just one clarification. Your requirement is create new Cstyles on selected text..

Do you give inputs of style properties? or script will create the new Cstlyes..?

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

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 ,
Mar 22, 2017 Mar 22, 2017

Copy link to clipboard

Copied

Hi

No , I want script create the new Character Style ... no inputs for style properties .

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
Engaged ,
Mar 22, 2017 Mar 22, 2017

Copy link to clipboard

Copied

Hi,

Try this code..

app.findGrepPreferences = app.changeGrepPreferences =null;

app.findGrepPreferences.findWhat = "" // apply your grep code

var found = app.documents[0].findGrep();

    var new_Style = app.documents[0].characterStyles.add()

    new_Style.name = "my_style"; // your style name

//~     new_Style.fontStyle = "Italic" // create your style properties

//~     new_Style.pointSize = 28;

//~     // give ur inputs

     for(i=0; i<found.length; i++)

{

    if(found.contents)

    {

     found.select();

     app.changeGrepPreferences.appliedCharacterStyle=""; // style name

    found.changeGrep();

    } 

}

    app.findGrepPreferences = app.changeGrepPreferences =null;

   

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

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 ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

Hi

it's not  working ... because : i do not try to apply a character style for the selected texts .

i want to create a character style for each selected text ...

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
Guide ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

I hope you meant to create style based on text selected.. i edited the script what Ananth provided

app.findGrepPreferences = app.changeGrepPreferences =null;

app.findGrepPreferences.findWhat = "(?<=\)).+?(?=\()" // apply your grep code

var found = app.documents[0].findGrep();

  for(i=0; i<found.length; i++)

{

    if(found.contents)

    {

    found.select();

        var new_Style = app.documents[0].characterStyles.add()

    new_Style.name = "my_style"; // your style name

    new_Style.fontStyle=found.fontStyle;

    new_Style.fillColor=found.fillColor;

    }  

}

    app.findGrepPreferences = app.changeGrepPreferences =null;

HTH,

K

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
Guide ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

Not sure why the above my post being moderated?

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 ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

Hi

thank you for try . but :

when i run your script tell me :

"A style with this name already exist "

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
Guide ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

Delete the my_style character style if you have already and then rerun the script..

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 ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

I do this , but the same result

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
Guide ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

try this

app.findGrepPreferences = app.changeGrepPreferences =null;  

app.findGrepPreferences.findWhat = "(?<=\)).+?(?=\()" // apply your grep code  

var found = app.documents[0].findGrep();  

try

{

var new_Style = app.documents[0].characterStyles.item("my_style");

new_Style.name;

}

catch (myError){

var new_Style = app.documents[0].characterStyles.add()  

    new_Style.name = "my_style";  }

for(i=0; i<found.length; i++)  

{  

    if(found.contents)  

    {  

    found.select();  

       

    new_Style.fontStyle=found.fontStyle; 

    new_Style.fillColor=found.fillColor; 

    }    

}  

    app.findGrepPreferences = app.changeGrepPreferences =null;

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
Guide ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

Why the hell always keep the answers in moderated? Any one please answer?

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
Guide ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

try this..

app.findGrepPreferences = app.changeGrepPreferences =null;  

app.findGrepPreferences.findWhat = "(?<=\)).+?(?=\()" // apply your grep code  

var found = app.documents[0].findGrep();  

try

{

var new_Style = app.documents[0].characterStyles.item("my_style");

}

catch (myError){

var new_Style = app.documents[0].characterStyles.add()  

    new_Style.name = "my_style";  }

for(i=0; i<found.length; i++)  

{  

    if(found.contents)  

    {  

    found.select();  

       

    new_Style.fontStyle=found.fontStyle; 

    new_Style.fillColor=found.fillColor; 

    }    

}  

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 ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

Hi

i try it ... it's tell me :

" Execution finished . Result : [ object Color ] "

and it's  not work what i need 

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
Guide ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

Is it your grep code is correct? Do you the texts within brackets like that? Also please share the screenshots. so we can know better

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 ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

Yes , the GREP code is correct .

ghhvub.png

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
Guide ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

Are you running the script from Indesign or Extendscript editor?

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
Guide ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

use this as grep code..

(?<=\\)).+?(?=\\()

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 ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

I try run the script from InDesign and from Extendscript editor .... but the same result >>> the script create just 1 character style does not based on any of the selected texts and not applied on any text .

I am using a GREP code like what you say but with different glyph :    (?<=\﴿).+?(?=\﴾)     ... and it is correct .

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
Guide ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

You done wrong with grep code.. try this.. this will work

app.findGrepPreferences = app.changeGrepPreferences =null;    

app.findGrepPreferences.findWhat = "(?<=\\().+?(?=\\))" // apply your grep code    

var found = app.documents[0].findGrep();    

try 

var new_Style = app.documents[0].characterStyles.item("my_style"); 

new_Style.name;

catch (myError){ 

var new_Style = app.documents[0].characterStyles.add()    

    new_Style.name = "my_style";  } 

 

 

for(i=0; i<found.length; i++)    

{    

    if(found.contents)    

    {    

    found.select();    

         

    new_Style.fontStyle=found.fontStyle;   

    new_Style.fillColor=found.fillColor;   

    }      

}    

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
Guide ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

Untitled.jpg

any one in the forum leaders let me know why always the reply getting moderated?

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 ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

I am sorry ... but the same result

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 ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

If you want this is a sample text ... you can try the script on it .... this is maybe help to fine the problem :

In precabo. Occaborem reptate pe plabor ﴿ ﭞﭟﭠ﴾ assitat ut eaquid magnis ea inciunt labo. Ut verciis doloriatquis restiatusa consequi desequam dolut voluptat fugia voluptatus abo. Rovid magnis dolorro excerna tecatatur, conseque ﴿ ﮦﮧﮨﮩ﴾ explignistia nem vel est, vitate di optatestium que pel eumquas volessim adicipit volorro vidictur sin num nonet eum eturehe nihillenim quiatiatium consequo blaccum nam ea vitatium ut alia nes veliquatur, sitio modisqu iatem. Et endit maio blab iur ﴿ ﭑﭒﭓ﴾ andaeri squundus que cuptas quiatqui id ea doluptius suntotatus il incia commolo eos doluptatusam venis nulparibusci omni omni dis arcipsaest atquam quisqua tiumquis enduciis nonecte porerore num dolupiciae niet alit omnisque natium qui reperciat audistis mintem aut endanis tibus.

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
Guide ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

The bracket looks weird.. and in JavaScript using a single slash will get omitted.. so we need to use double slashes..

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 ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

i try what you say ... but the same result .

I try the GREP code in find/change in InDesign and it is good and select what i need to select .

i think the problem in the script , but i do not know it .

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