0
[CS3 JS] Correcting a Character Style Anomaly
New Here
,
/t5/indesign-discussions/cs3-js-correcting-a-character-style-anomaly/td-p/1149421
Apr 11, 2008
Apr 11, 2008
Copy link to clipboard
Copied
It used to be that you could define a character style to merely colour the text and give it an underline (e.g. for Hyperlinks) or just superscript the text (for Reference citations). When such styles, which do not call for a particular font or font size, are placed into InDesign CS, the styled text would take on the font and font size of the underlying paragraph style. However, after placing a Word .doc with these styles into a CS2 template, the font and font size becomes Times New Roman and 10 pt. The solution was to save an .rtf file and re-import the text. Now, in CS3 this work-around doesnt quite work: the font is okay, but the font size reverts to that default size of 10 pt.
So, I would like a script that finds all occurrences of two specific character styles (Hyperlink and bibref) and then corrects the font size of the found text to that of the underlying paragraph style. These styles can appear anywhere within a document, including in tables. I have trawled through this forum and found enough to be able to search for the character styles, but I cannot fathom how to apply the font size of the underlying paragraph style. Any help will be greatly appreciated.
By the way, re-applying the character styles doesnt work because the character styles dont define the font size; also clearing the overrides on the paragraph style while the text is selected isnt a viable solution, because other local formatting (i.e. italic) would be lost.
So, I would like a script that finds all occurrences of two specific character styles (Hyperlink and bibref) and then corrects the font size of the found text to that of the underlying paragraph style. These styles can appear anywhere within a document, including in tables. I have trawled through this forum and found enough to be able to search for the character styles, but I cannot fathom how to apply the font size of the underlying paragraph style. Any help will be greatly appreciated.
By the way, re-applying the character styles doesnt work because the character styles dont define the font size; also clearing the overrides on the paragraph style while the text is selected isnt a viable solution, because other local formatting (i.e. italic) would be lost.
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/cs3-js-correcting-a-character-style-anomaly/m-p/1149422#M338996
Apr 11, 2008
Apr 11, 2008
Copy link to clipboard
Copied
What you need to do is to blank the fields for point size etc.:
with (app.activeDocument.characterStyles.item ('bibref'))
{
appliedFont = NothingEnum.nothing;
fontStyle = NothingEnum.nothing;
pointSize = NothingEnum.nothing;
}
Peter
with (app.activeDocument.characterStyles.item ('bibref'))
{
appliedFont = NothingEnum.nothing;
fontStyle = NothingEnum.nothing;
pointSize = NothingEnum.nothing;
}
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Simon_Fenwick_
AUTHOR
New Here
,
/t5/indesign-discussions/cs3-js-correcting-a-character-style-anomaly/m-p/1149423#M338997
Apr 16, 2008
Apr 16, 2008
Copy link to clipboard
Copied
Hi Peter
Thank you very much for your quick response. I tried your script and it did as you intended by clearing the Font, Font Style and Point Size in the character style, but unfortunately it did not correct the problem of the style becoming some default style and size (Times New Roman 10 pt) when placed into ID.
In fact, I had already set up the 'bibref' and 'Hyperlink' character styles with these fields blanked out. Also, I made Adobe aware of this bug when CS2 came out and they warned me that CS3 wouldn't fix the problem; but I didn't realize that CS3 would be worse than CS2 so that using an rtf file wouldn't fix things.
So, I am left with my initial query: is it possible to write a script to search for the character styles in question and apply the font size of the underlying paragraph style?
Thanks a lot for any help you can give.
Thank you very much for your quick response. I tried your script and it did as you intended by clearing the Font, Font Style and Point Size in the character style, but unfortunately it did not correct the problem of the style becoming some default style and size (Times New Roman 10 pt) when placed into ID.
In fact, I had already set up the 'bibref' and 'Hyperlink' character styles with these fields blanked out. Also, I made Adobe aware of this bug when CS2 came out and they warned me that CS3 wouldn't fix the problem; but I didn't realize that CS3 would be worse than CS2 so that using an rtf file wouldn't fix things.
So, I am left with my initial query: is it possible to write a script to search for the character styles in question and apply the font size of the underlying paragraph style?
Thanks a lot for any help you can give.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/cs3-js-correcting-a-character-style-anomaly/m-p/1149424#M338998
Apr 16, 2008
Apr 16, 2008
Copy link to clipboard
Copied
It could be the case that there is some local formatting. After you use the script, try removing local formatting (Alt/Opt+click on the stylename in the UI). If that works, and if it's possible to remove local formatting, you can script that as well. First let's see if removing local formatting makes a difference.
Peter
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Simon_Fenwick_
AUTHOR
New Here
,
/t5/indesign-discussions/cs3-js-correcting-a-character-style-anomaly/m-p/1149425#M338999
Apr 16, 2008
Apr 16, 2008
Copy link to clipboard
Copied
Hi Peter
No that doesn't work. Because there is no font or font size described in the character style. What does work is to clear the overrides in the underlying paragraph style, but that is not a good solution for me because in some Hyperlinks we might have italic text, which would also be overridden.
Thanks so much for your quick replies by the way. I wasn't expecting that.
SImon
No that doesn't work. Because there is no font or font size described in the character style. What does work is to clear the overrides in the underlying paragraph style, but that is not a good solution for me because in some Hyperlinks we might have italic text, which would also be overridden.
Thanks so much for your quick replies by the way. I wasn't expecting that.
SImon
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/cs3-js-correcting-a-character-style-anomaly/m-p/1149426#M339000
Apr 16, 2008
Apr 16, 2008
Copy link to clipboard
Copied
Simon,
I can't reproduce this. If you send me one of your troublesome files I'll take a look (click my name in this message to see my email address).
Peter
I can't reproduce this. If you send me one of your troublesome files I'll take a look (click my name in this message to see my email address).
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
LATEST
/t5/indesign-discussions/cs3-js-correcting-a-character-style-anomaly/m-p/1149427#M339001
Apr 18, 2008
Apr 18, 2008
Copy link to clipboard
Copied
This in the end fixed Simon's problem:
#target indesign;
charstyles = ['bibref', 'Hyperlink'];
app.findGrepPreferences = null;
for (i = 0; i < charstyles.length; i++)
reset_charstyle (charstyles);
function reset_charstyle (cs)
{
app.findGrepPreferences.appliedCharacterStyle = cs;
var f = app.activeDocument.findGrep();
for (var j = 0; j < f.length; j++)
f.pointSize = f.appliedParagraphStyle.pointSize
}
Simon thinks that this problem occurs on PCs but not on Macs.
Peter
#target indesign;
charstyles = ['bibref', 'Hyperlink'];
app.findGrepPreferences = null;
for (i = 0; i < charstyles.length; i++)
reset_charstyle (charstyles);
function reset_charstyle (cs)
{
app.findGrepPreferences.appliedCharacterStyle = cs;
var f = app.activeDocument.findGrep();
for (var j = 0; j < f.length; j++)
f
}
Simon thinks that this problem occurs on PCs but not on Macs.
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

