Skip to main content
Inspiring
October 21, 2022
Answered

Unification of textFrame style

  • October 21, 2022
  • 2 replies
  • 1115 views

Hi,
I have multiple linked frames, these are the last ones - textFrame82, textFrame92.
I can't find how to set a uniform font with script, the style is carried over from previous frames.
The upper frames are already disconnected, so these lower ones don't affect it anymore.
So this doesn't work, clear style ap, i can't find.

 

textFrame82.texts[0].properties =
{
appliedFont : fonts ,
justification : Justification.FULLY_JUSTIFIED ,
pointSize : 18 ,
fillColor : doc.colors.itemByName("black") ,
lending : 20
};

 

Directions?

Thank you

Jirka

 

This topic has been closed for replies.
Correct answer m1b

Hi @jirik79416729, in addition to what @Robert at ID-Tasker has suggested, please have a look at this script. It will give you some ideas. The key is the clearOverrides method of many text objects. You can clear paragraph style overrides or character style overrides or both.

- Mark

 

function main() {

    var doc = app.activeDocument;

    /* Example 1:
         clear overrides in selection
         (first select one or more text frames or some text)
    */
    clearTextOverridesInItems(doc.selection);

    /* Example 2:
       clear overrides in whole story
       (first select a text frame)
    */
    // clearTextOverridesInItems(doc.selection[0].parentStory);


    /**
     * Clears style overrides from text
     * or textFrame(s) or story.
     * @author m1b
     * @version 2022-10-22
     * @param {PageItems} items - any indesign objects with 'texts' property.
     */
    function clearTextOverridesInItems(items) {

        if (!items.hasOwnProperty('0'))
            items = [items];

        var texts = [];

        for (var i = 0; i < items.length; i++)
            if (
                items[i].hasOwnProperty('texts')
                && items[i].texts[0].isValid
            )
                // note we want hard references here, because
                // the text may reflow after clearing overrides
                texts.push(resolve(items[i].texts[0].toSpecifier()));

        for (var i = 0; i < texts.length; i++)
            texts[i].clearOverrides(OverrideType.ALL);

    };

} // end main

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Clear text overrides');

 

 

2 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
October 21, 2022

Hi @jirik79416729, in addition to what @Robert at ID-Tasker has suggested, please have a look at this script. It will give you some ideas. The key is the clearOverrides method of many text objects. You can clear paragraph style overrides or character style overrides or both.

- Mark

 

function main() {

    var doc = app.activeDocument;

    /* Example 1:
         clear overrides in selection
         (first select one or more text frames or some text)
    */
    clearTextOverridesInItems(doc.selection);

    /* Example 2:
       clear overrides in whole story
       (first select a text frame)
    */
    // clearTextOverridesInItems(doc.selection[0].parentStory);


    /**
     * Clears style overrides from text
     * or textFrame(s) or story.
     * @author m1b
     * @version 2022-10-22
     * @param {PageItems} items - any indesign objects with 'texts' property.
     */
    function clearTextOverridesInItems(items) {

        if (!items.hasOwnProperty('0'))
            items = [items];

        var texts = [];

        for (var i = 0; i < items.length; i++)
            if (
                items[i].hasOwnProperty('texts')
                && items[i].texts[0].isValid
            )
                // note we want hard references here, because
                // the text may reflow after clearing overrides
                texts.push(resolve(items[i].texts[0].toSpecifier()));

        for (var i = 0; i < texts.length; i++)
            texts[i].clearOverrides(OverrideType.ALL);

    };

} // end main

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Clear text overrides');

 

 

Robert at ID-Tasker
Legend
October 21, 2022

I think it should be leading ... not sure if that will fix your problem.

 

And how about using ObjectStyle with ParaStyle ??? then you won't need to set-up so many params 😉 just one command 😉

 

Inspiring
October 22, 2022

Hi
If you know how to do it and how to work with it, it's easy.
I want to take the output "fonts" and make them a little bit neater after all these years.
I originally wanted to program this in Delphi, to load the font from folders. Maybe even inactive/uninstalled ones, to make it clearer where which ones are.
But I found I don't know how to start 😉 and I wonder even with things I've programmed before how I did it.
Well, the years go by and the head can't wonder anymore, what was common is no longer.
So I looked at InDesign, which I used to work in, and tried a script, unfortunately only with fonts installed, but that can be solved retrospectively, though more laboriously. (Do you have a tip for loading from a folder with uninstalled fonts?)
First, I made a page with text frames as I wanted it to look. That is, each frame has a set style, and then I had the idea of linking the frames so that the text follows. Just kind of a neat little thing, but I'm interested in the technical side of it.
Unfortunately, I don't know the details of Indesign scripting, so sometimes I ask a primitive question after a long search.
Now it was probably better to start over rather than "drive a wedge". But I found it easiest to make the last text "active" and overwrite with style.
You can't do that via textbox, parts of the text remain with the original styles.
I didn't learn Indesign scripting and couldn't find simple examples anywhere.
Thanks for the tip, but it doesn't solve anything with converting the last frames/texts to another style.

m1b
Community Expert
Community Expert
October 23, 2022

Yes, a sample of the fonts. So I can customize it as needed.
It would be nice if it could from folders with fonts that are not active/installed.

I was already happy with it, except for the last two boxes.
The procedure was, I filled the linked textFrames (from the first one on top), copied/divided and re-linked the last three textFrames, set the new style and copied/divided again. The split is so that when the style changes, the text doesn't get affected and bleed over into the previous textFrame. At first it worked, but the bottom two did not. I set the font there to 10b and 18b

I'm now looking at the scripting manual for InDesign ExtendScript to understand the definition of objects. But English is not my first language and it's slow going. I'm bad at it, so I prefer to translate it, writing it down for "future reference".

 

 

 


I suspect that your problem may be the fact that when you increase the size of the text in a text frame, some of it will overflow into the next text frame, or if you decrease the size then some text from next text frame in the wrong size will come into this text frame. Therefore your code will have to consider this and handle it. You must imagine what each change will do to the text and the flow-on or flow-back effects.

 

In my script I had to be careful with my DOM specifiers that they referenced characters in a story (as opposed to texts in a text frame) and that the text frames were processed in correct order. I'm sorry this topic is complicated.

- Mark