Copy link to clipboard
Copied
Hi All,
In the below coding is to find Italic and apply char style, if there is no char style then add new char style, But in my code doing if there is no Italic created new char style, but I need if there is no italic font nothing to do. Please advice.
app.findTextPreferences = app.changeTextPreferences =null;
app.findChangeTextOptions.includeMasterPages = false;
app.findTextPreferences.fontStyle ="Italic";
app.findTextPreferences.position = Position.NORMAL;
app.findTextPreferences.capitalization = Capitalization.NORMAL;
try{
app.changeTextPreferences.appliedCharacterStyle ="15 Italic";
app.documents.item(0).changeText();
}
catch(e){
app.documents.item(0).characterStyles.add({name:"15 Italic", fontStyle:"Italic"});
app.changeTextPreferences.appliedCharacterStyle ="15 Italic";
app.documents.item(0).changeText();
}
Regards,
Vetha
Copy link to clipboard
Copied
Moved to the scripting forum....
Copy link to clipboard
Copied
Hi Vetha,
Try this,
var doc = app.activeDocument;
var italic = doc.characterStyles.item("15 Italic");
if(!italic.isValid)
{
italic = doc.characterStyles.add({name:"15 Italic", fontStyle:"Italic"})
}
app.findTextPreferences = app.changeTextPreferences =null;
app.findChangeTextOptions.includeMasterPages = false;
app.findTextPreferences.fontStyle ="Italic";
app.findTextPreferences.position = Position.NORMAL;
app.findTextPreferences.capitalization = Capitalization.NORMAL;
app.changeTextPreferences.appliedCharacterStyle =italic;
app.documents.item(0).changeText();
Regards,
Chinna
Copy link to clipboard
Copied
hope the below code suits your requirement,
app.findGrepPreferences = app.changeGrepPreferences =null;
app.findChangeTextOptions.includeMasterPages = false;
app.findGrepPreferences.findWhat = ".+";
app.findGrepPreferences.fontStyle ="Italic";
app.findGrepPreferences.position = Position.NORMAL;
app.findGrepPreferences.capitalization = Capitalization.NORMAL;
var found = app.activeDocument.findGrep();
try{
app.changeGrepPreferences.appliedCharacterStyle ="15 Italic";
app.documents.item(0).changeGrep();
}
catch(e){
if(found.length>0){
app.documents.item(0).characterStyles.add({name:"15 Italic", fontStyle:"Italic"});
app.changeGrepPreferences.appliedCharacterStyle ="15 Italic";
app.documents.item(0).changeGrep();
}
}
Vandy
Copy link to clipboard
Copied
or this one:
var curDoc = app.activeDocument;
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = false;
app.findTextPreferences.fontStyle = "Italic";
app.findTextPreferences.position = Position.NORMAL;
app.findTextPreferences.capitalization = Capitalization.NORMAL;
var findResult = curDoc.findText();
if ( findResult.length > 0 ) {
var italic = curDoc.characterStyles.item( "15 Italic" );
if ( !italic.isValid ) {
italic = curDoc.characterStyles.add({ name: "15 Italic", fontStyle: "Italic" });
}
app.changeTextPreferences.appliedCharacterStyle = italic;
curDoc.changeText();
}
app.findTextPreferences = app.changeTextPreferences =null;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now