🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.scripting.indesign
8 messages
8 total messages Started by Andreas_Jansson Wed, 04 Mar 2009 15:11
[CS3 JS] Question about collecting overridden style settings
#804
Author: Andreas_Jansson
Date: Wed, 04 Mar 2009 15:11
8 lines
1143 bytes
Hi!

I can use the styleOverridden to check every item in a textStyleRange for overrides. But is there a smart way to collect the attributes actually overridden? (The attributes showing up neatly in the tooltip when you hold the mouse cursor over an overridden style name.)

My script needs to add a clean character style for every overridden style, recreating the behaviour of the add new character style dialogue, creating the new style based on the overrides.

Kind regards,
Andreas
Re: [CS3 JS] Question about collecting overridden style settings
#828
Author: Andreas_Jansson
Date: Thu, 05 Mar 2009 08:59
7 lines
1054 bytes
Or... is there a way for a script to mimic the way of the user?

When manually adding a new style in InDesign the "new style" window shows the attributes of selected text from the beginning.

Can a new style be created from the styles of a textStyleRange (including its overrides)?

I hope I've made my question clear enough. Anyone?
Re: [CS3 JS] Question about collecting overridden style settings
#830
Author: Peter Kahrel
Date: Thu, 05 Mar 2009 10:35
5 lines
825 bytes
Andreas,

Dave Saunders has a few scripts that reposrt some features of paragraph styles. I don't know if they deal with overrides, but do check his web sites(s).

Peter
Re: [CS3 JS] Question about collecting overridden style settings
#832
Author: Andreas_Jansson
Date: Thu, 05 Mar 2009 12:03
20 lines
1858 bytes
Thanks for the suggestion, Peter. I've found one example of a script dealing with "Italic", "Bold" and "Bold Italic" (which might originate from David Saunders, I'm not sure).
It's described as "Preserve Local Formatting" and looks for ranges without a character style (i.e. with "noCharStyle") but with those specific fontStyles, creating Italic etc, as character styles, and applies them on the text.

These are very specific fontStyle attributes and would not deal with the font size being changed, or the character spacing set to another number between two words etc.

I need to create a more generic code to create character styles for all overridden textstyle ranges in a text.

And now I'm also a bit confused about the nature of the textStyleRange object as well. Looking at its properties some of them have the same names as properties of a characterStyle object, but of different type:

myTextStyleRange.appliedFont.constructor.name
Result: Font

While

myNewCharacterStyle.appliedFont.constructor.name
Result: String

Meaning that I can't directly assign the attributes of the textStyleRange with the overridden styles, to a newly created character style, or is there a way?

Andreas
Re: [CS3 JS] Question about collecting overridden style settings
#836
Author: Peter Kahrel
Date: Thu, 05 Mar 2009 13:13
10 lines
1143 bytes
You needn't worry too much about the difference in constructors. In many cases you can apply a font using either a string or an object:

myNewCharacterStyle.appliedFont = "Times";
myNewCharacterStyle.appliedFont = app.fonts.item ("Times");

The second one always works, so it's good practice to assign objects rather than strings (that goes for all objects, not just strings). So you should be able to do this:

myNewCharacterStyle.appliedFont = myTextStyleRange.appliedFont

Peter
Re: [CS3 JS] Question about collecting overridden style settings
#838
Author: Andreas_Jansson
Date: Thu, 05 Mar 2009 14:07
23 lines
2209 bytes
Ah, it looks like it's beginning to work now :-)
I thought I had tried some of these things before, but obviously not. Thanks Peter, for your assistance. Now even assigning the whole properties collection of the TextStyleRange objects to the new character style object works! There's a lot of properties created, which I'd really would have preferred not to show up (in the summary of the character style dialogue box), since they are (as far as I can see) the default values, but I like the easy code this approach results in:

var selText = app.selection;
var srs = selText[0].textStyleRanges;

for (var iTSR=srs.length-1; iTSR>=0; iTSR--){ 

      	if (srs[iTSR].styleOverridden){ >		// This is an overridden style we
      need to create a style for >		var ch = srs[iTSR]; >		newStyle = app.activeDocument.characterStyles.add(ch.properties);
      >		if (app.activeDocument.characterStyles.item('newstyle'+iTSR.toString())!=null)
      app.activeDocument.characterStyles.item('newstyle'+iTSR.toString()).remove();
      >		newStyle.name = 'newstyle'+iTSR.toString(); 	} }





I'm not yet quite clear on how to treat overridden paragraph styles. Perhaps I need to check whether the properties of the new character style are already the same as the ones of an possibly applied paragraph style, and if so, not assign (or remove) that property from the new character style.

Also... possible need to name all uniquley auto-generated styles and find a way to apply the same style again (not to risk creating a large number of character styles just setting "bold").

Andreas
Re: [CS3 JS] Question about collecting overridden style settings
#840
Author: Peter Kahrel
Date: Thu, 05 Mar 2009 15:01
5 lines
1111 bytes
You could get the properties of the textStyleRange and those of the containing paragraph by using toResource(). You then have two objects that can be compared fairly easily. Collect the differences and set those to the new paragraph style.

If you store these settings (in a variable, array, object -- whatever), you can use them to check whether another textStyleRange differs and decide not to create a new char. style but use one that already exists with those same settings.

Peter
Re: [CS3 JS] Question about collecting overridden style settings
#845
Author: Andreas_Jansson
Date: Thu, 05 Mar 2009 16:14
31 lines
2109 bytes
I guess you mean the toSource() method, but I don't follow quite here, how the properties could be compared - or rather how toSource() can be helpful.

"sr" being the TextStyleRange, the following statement ... 

      sr.properties.toSource()




and the one from its paragraphstyle ...

      sr.paragraphs[0].appliedParagraphStyle.properties.toSource()




... returns partly different things,
obviously since the TextStyleRange contains properties from character styles as well as from paragraph style (and perhaps some of its own). Only the "clean" paragraph style properties would match - can toSource() be helpful making such a comparison?

I guess I could try and make use of the complete toSource() strings of the properties of the paragraph styles as keys (property names) in an associative array (if they are allowed as such - they do get very long), to be able to check for the exact same paragraph style.

But getting the differing style properties only, wouldn't that require checking each property from the text style range object against the corresponding one in the containing paragraph, individually?

(
I also noticed a bug in CS3 - when there is no paragraph style (not the Basic Paragraph but NO paragraph style at all), InD craches when you try to do something with the "properties" object of that TextStyleRange object, such as 

  var srProperties = sr.properties;

)

Andreas
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