Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[CS3 JS] Exchange Character Style Problem!

New Here ,
Jul 12, 2008 Jul 12, 2008
Hello experienced JS people,
The situation is as follows -
I have a document that MAY have the Character Style 'A'.
If this were to be true - then I'd like to exchange it for Character Style 'B'.
Sounds simple doesn't it.... It's KILLING ME!

This must be possible? The problem is - I don't know how!

My scripting lookes like this so far:
> app.findTextPreferences.appliedCharacterStyle = "File name";
app.changeTextPreferences.appliedCharacterStyle = "Document No";
oneDoc.changeText();

Help would be greatly welcomed....
Thanks in advance,
Lee
TOPICS
Scripting
345
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jul 12, 2008 Jul 12, 2008
Have a try with :
var styletofind = app.activeDocument.characterStyles.item("File name");
var styletochange = app.activeDocument.characterStyles.item("Document No");
app.findTextPreferences.appliedCharacterStyle = styletofind; app.changeTextPreferences.appliedCharacterStyle = styletochange;
oneDoc.changeText();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 12, 2008 Jul 12, 2008
I think the problem is in the word "MAY".

You need to have a test for existence:
var styletofind = app.activeDocument.characterStyles.item("File name");

if (styletofind != null) {
var styletochange = app.activeDocument.characterStyles.item("Document No");
app.findTextPreferences.appliedCharacterStyle = styletofind;
app.changeTextPreferences.appliedCharacterStyle = styletochange;
oneDoc.changeText();
}
But even this might not be enough if the character styles in question are in groups.

Dave
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 14, 2008 Jul 14, 2008
Thank you both for your inputs.

I have tried them both, and the results are:
- Text with '[None]' character style are changed to 'Document No' character style.
and
- Text with 'File Name' character style are not changed!

What can it be?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 14, 2008 Jul 14, 2008
LATEST
Forget what I just wrote...

You can obviously see that I am a newbee at all this coding!
The problem was 'File name' is not in the document.
Where as 'File Name' is.
Case sensertive!

This is what happens when you have looked at the script for many days....!

So it's working now - Thank you both, very much!
Regards,
Lee
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines