Thread View: adobe.scripting.indesign
4 messages
4 total messages
Started by thiyagus5
Tue, 03 Feb 2009 10:06
Find some characters and replace with character style...
Author: thiyagus5
Date: Tue, 03 Feb 2009 10:06
Date: Tue, 03 Feb 2009 10:06
50 lines
1970 bytes
1970 bytes
Hi everyone,
The below script is to find some space characters and replacing with character style. Its working fine with InDesignCS2 MAC.
//InDesign CS2//
var myDoc = app.activeDocument;
with(app.activeDocument){
myNewCharStyle = characterStyles.add();
with(myNewCharStyle){
name= "x"
fontStyle = "Roman"
}}
app.findPreferences = null;
app.changePreferences = null;
myDoc.search("^>", false, false, undefined, undefined, {appliedCharacterStyle:"x"});
myDoc.search("^m", false, false, undefined, undefined, {appliedCharacterStyle:"x"});
////////
Now i am currently working in InDesignCS3, and i have also changed the script somewhat but its not working with CS3 MAC...
//InDesign CS3//
var myDoc = app.activeDocument;
if (myDoc.characterStyles.item ('x') == null)
myDoc.characterStyles.add ({name: 'x'});
var myNewCharStyle = myDoc.characterStyles.item ('x');
with(myNewCharStyle){
name= "x"
fontStyle = "Roman"
}
function setupFindText(myFindTextPreferences, myChangeTextPreferences, myNewCharStyle) {
app.findTextPreferences = null;
app.changeTextPreferences = null;
app.findTextPreferences.findWhat = "^>";
app.changeTextPreferences.appliedCharacterStyle = myNewCharStyle;
app.findTextPreferences.findWhat = "^m";
app.changeTextPreferences.appliedCharacterStyle = myNewCharStyle;
//
can anyone help me for this. Thanks in advance.
Regards
Thiyagu
Re: Find some characters and replace with character style...
Author: Olav_Kvern
Date: Tue, 03 Feb 2009 18:11
Date: Tue, 03 Feb 2009 18:11
35 lines
1647 bytes
1647 bytes
Hi Thiyagu,
You're not telling InDesign CS3 to do anything here:
app.findTextPreferences.findWhat = "^>";
app.changeTextPreferences.appliedCharacterStyle = myNewCharStyle;
app.findTextPreferences.findWhat = "^m";
app.changeTextPreferences.appliedCharacterStyle = myNewCharStyle;
You've set the find and change text preferences, but you haven't issued a command to change the text. What you need looks something more like this:
app.findTextPreferences.findWhat = "^>";
app.changeTextPreferences.appliedCharacterStyle = myNewCharStyle;
//Add a line to perform the change:
app.documents.item(0).changeText();
app.findTextPreferences.findWhat = "^m";
app.changeTextPreferences.appliedCharacterStyle = myNewCharStyle;
//Add a line to perform the change:
app.documents.item(0).changeText();
It's also not clear to me that this will work:
if (myDoc.characterStyles.item ('x') == null)
I think that this will always be true, even if the style does not exist.
Thanks,
Ole
Re: Find some characters and replace with character style...
Author: thiyagus5
Date: Wed, 04 Feb 2009 06:36
Date: Wed, 04 Feb 2009 06:36
6 lines
924 bytes
924 bytes
Hi Ole, Thanks for your kind support. Actually what i need is, find en space & em space characters in the InDesign CS3 document and apply character style for those characters. I have tested your script also its running but not performing the change action. Please look into this and help for this. Regards Thiyagu
Re: Find some characters and replace with character style...
Author: Olav_Kvern
Date: Wed, 04 Feb 2009 08:08
Date: Wed, 04 Feb 2009 08:08
7 lines
822 bytes
822 bytes
Hi Thiyagu, If it's not working, it's most likely that the character style does not exist, or, if it does exist, it's inside a style group. Could that be the problem? Thanks, Ole
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads