Skip to main content
Inspiring
March 23, 2017
Answered

Find text then add a character style script

  • March 23, 2017
  • 1 reply
  • 9775 views

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 " ﴾ "  

This topic has been closed for replies.
Correct answer tpk1982

SELECT TEXT WITH IN BRACKET.. YOU CAN SEE THE STYLES APPLIED..


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;        

app.findGrepPreferences.findWhat = cstyle.toString();         

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

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

{        

    myfound.select();        

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

    var myname=new_Style.name;

    new_Style.appliedFont = myfound.appliedFont;

  new_Style.fontStyle = myfound.fontStyle;

  new_Style.pointSize = myfound.pointSize;

  new_Style.leading = myfound.leading;

  new_Style.appliedLanguage = myfound.appliedLanguage;

  new_Style.kerningMethod = myfound.kerningMethod;

  new_Style.tracking = myfound.tracking;

  new_Style.capitalization = myfound.capitalization;

  new_Style.position = myfound.position;

  new_Style.ligatures = myfound.ligatures;

  new_Style.noBreak = myfound.noBreak;

  new_Style.horizontalScale = myfound.horizontalScale;

  new_Style.verticalScale = myfound.verticalScale;

  new_Style.baselineShift = myfound.baselineShift;

  new_Style.skew = myfound.skew;

  new_Style.fillColor = myfound.fillColor;

  new_Style.fillTint = myfound.fillTint;

  new_Style.strokeTint = myfound.strokeTint;

  new_Style.strokeWeight = myfound.strokeWeight;

  new_Style.overprintStroke = myfound.overprintStroke;

  new_Style.overprintFill = myfound.overprintFill;

  new_Style.otfFigureStyle = myfound.otfFigureStyle;

  new_Style.otfOrdinal = myfound.otfOrdinal;

  new_Style.otfFraction = myfound.otfFraction;

  new_Style.otfDiscretionaryLigature = myfound.otfDiscretionaryLigature;

  new_Style.otfTitling = myfound.otfTitling;

  new_Style.otfContextualAlternate = myfound.otfContextualAlternate;

  new_Style.otfSwash = myfound.otfSwash;

  new_Style.otfSlashedZero = myfound.otfSlashedZero;

  new_Style.otfHistorical = myfound.otfHistorical;

  new_Style.otfStylisticSets = myfound.otfStylisticSets;

  new_Style.strikeThru = myfound.strikeThru;

   

   

    app.changeGrepPreferences.appliedCharacterStyle = myname;       

    app.changeGrep();

}        

}

1 reply

Anantha Prabu G
Brainiac
March 23, 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,PrabuDesign smarter, faster, and bolder with InDesign scripting.
Inspiring
March 23, 2017

Hi

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

Inspiring
March 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; 

    }    

}  


Hi

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

" Execution finished . Result : [ object Color ] "

and it's  not work what i need