Copy link to clipboard
Copied
Hi Everyone,
I have tried to set the underline options for character style like type, weight, offset, color etc... through script but i doesn't got any idea and i have refered the scripting guide still now i'm confused....
I have attached the sample code for more details......
Kindly tell me how to set this???????????
app.findGrepPreferences = app.changeGrepPreferences =null;
var searchText = "InDesign";
app.findGrepPreferences.findWhat = searchText ;
var list = app.activeDocument.findGrep ();
try
{
var new_Style = app.documents[0].characterStyles.item("underlie_Text");
new_Style.name;
}
catch (myError){
var new_Style = app.documents[0].characterStyles.add()
new_Style.name = "underlie_Text";
}
new_Style.underline= true;
list.appliedCharacterStyle="col";
Thanks,
-Jo
Hi Jo, I don't fully understand what you are doing, but this may help a little:
var doc = app.activeDocument;
// try to get reference to the character style
var styleName = 'Underlined',
myStyle = doc.characterStyles.itemByName(styleName);
// if it isn't valid (it's missing) then make it
if (!myStyle.isValid) myStyle = doc.characterStyles.add({ name: styleName });
// give the style a cyan underline
myStyle.underline = true;
myStyle.underlineColor = "C=100 M=0 Y=0 K=0";
// apply the style
...
for(var i = 0; i < list.length; i++)
list[i].appliedCharacterStyle = "underlie_Text"
-Manan
Copy link to clipboard
Copied
Hi Jo, I don't fully understand what you are doing, but this may help a little:
var doc = app.activeDocument;
// try to get reference to the character style
var styleName = 'Underlined',
myStyle = doc.characterStyles.itemByName(styleName);
// if it isn't valid (it's missing) then make it
if (!myStyle.isValid) myStyle = doc.characterStyles.add({ name: styleName });
// give the style a cyan underline
myStyle.underline = true;
myStyle.underlineColor = "C=100 M=0 Y=0 K=0";
// apply the style to a selected text frame's story
doc.selection[0].parentStory.paragraphs.everyItem().applyCharacterStyle(myStyle);
Copy link to clipboard
Copied
What I'm trying to do is to set a character style for the serched text....
While creating the character style
1. the underline options are not set
2. the created character style was not applied to the search text
this was my problem and I have tried
myStyle.underlineColor = "C=100 M=0 Y=0 K=0";
it's not applying and i have added the comments in my code to understand better
app.findGrepPreferences = app.changeGrepPreferences =null;
var searchText = "hi"; //search text
app.findGrepPreferences.findWhat = searchText ;
var list = app.activeDocument.findGrep ();
try
{
var new_Style = app.documents[0].characterStyles.item("underlie_Text");//character style
new_Style.name;
}
catch (myError){
var new_Style = app.documents[0].characterStyles.add()
new_Style.name = "underlie_Text";
}
new_Style.underline= true;//It's Working
myStyle.underlineColor = "C=100 M=0 Y=0 K=0";//It's not working
list.appliedCharacterStyle="underlie_Text";//Style was not applied to the search text
what was the problem in my code???????????
-jo
Copy link to clipboard
Copied
for(var i = 0; i < list.length; i++)
list[i].appliedCharacterStyle = "underlie_Text"
-Manan
Copy link to clipboard
Copied
Hi mlb and manan,
Thankyou so much!
Now only i noticed that now it's working perfect.
Thanks,
-Jo