Hello ,
i want to check wheather particular style is present in the document.if present then i want to apply another style.
is any method in the indesign script which will find and replce particular style in the document?
Here's a simple example:
var doc = app.activeDocument;
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedParagraphStyle = doc.paragraphStyles.item("Header");
app.changeTextPreferences.appliedParagraphStyle = doc.paragraphStyles.item("Subheader");
doc.changeText();
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
It changes paragraph style Header with Subheader
If you want to reference a paragraph style in a group, you can do this like so:
app.findTextPreferences.appliedParagraphStyle = doc.paragraphStyleGroups.item("Headers").paragraphStyles.item("Header");
And if you're operating in an environment where you know that you don't have any paragraph styles with the same names stored in different groups, and you want to reference a paragraph style that is somewhere in the document, without knowing what group it's in, you can use this recursive function to find it:
var findParagraphStyle = function( obj, name ) {
var style = obj.paragraphStyles.itemByName( name );
if (!style.isValid) {
for (var i = 0; i < paragraphStyleGroups.length; i += 1) {
style = findParagraphStyle( obj.paragraphStyleGroups[i], name );
}
}
return style; // If we haven't found a style with name "name",
// findParagraphStyle will return an invalid object.
};
app.findTextPreferences.appliedParagraphStyle = findParagraphStyle( doc, "Header" );
North America
Europe, Middle East and Africa
Asia Pacific