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

Find text then add a character style script

Explorer ,
Mar 22, 2017 Mar 22, 2017

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
10.1K
Translate
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; 

...
Translate
Engaged ,
Mar 22, 2017 Mar 22, 2017

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.
Translate
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

Hi

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

Translate
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

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.
Translate
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

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 ...

Translate
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

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

Translate
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

Not sure why the above my post being moderated?

Translate
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

Hi

thank you for try . but :

when i run your script tell me :

"A style with this name already exist "

Translate
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

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

Translate
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

I do this , but the same result

Translate
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

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;

Translate
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

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

Translate
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

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; 

    }    

}  

Translate
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

Hi

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

" Execution finished . Result : [ object Color ] "

and it's  not work what i need 

Translate
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

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

Translate
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

Yes , the GREP code is correct .

ghhvub.png

Translate
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

Are you running the script from Indesign or Extendscript editor?

Translate
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

use this as grep code..

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

Translate
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

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 .

Translate
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

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;   

    }      

}    

Translate
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

Untitled.jpg

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

Translate
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

I am sorry ... but the same result

Translate
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

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.

Translate
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

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

Translate
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

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 .

Translate
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