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 " ﴾ "
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;
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..?
Copy link to clipboard
Copied
Hi
No , I want script create the new Character Style ... no inputs for style properties .
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;
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 ...
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
Copy link to clipboard
Copied
Not sure why the above my post being moderated?
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 "
Copy link to clipboard
Copied
Delete the my_style character style if you have already and then rerun the script..
Copy link to clipboard
Copied
I do this , but the same result
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;
Copy link to clipboard
Copied
Why the hell always keep the answers in moderated? Any one please answer?
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;
}
}
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
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
Copy link to clipboard
Copied
Yes , the GREP code is correct .
Copy link to clipboard
Copied
Are you running the script from Indesign or Extendscript editor?
Copy link to clipboard
Copied
use this as grep code..
(?<=\\)).+?(?=\\()
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 .
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;
}
}
Copy link to clipboard
Copied
any one in the forum leaders let me know why always the reply getting moderated?
Copy link to clipboard
Copied
I am sorry ... but the same result
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.
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..
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 .