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.

Robert at ID-Tasker
Legend
October 22, 2022

So what EXACTLY is your goal? Samples of fonts? Or what?

 

Because you are another person asking "how can I get from point A to B" without giving more details 😞 what is the location of points A & B? Are you alone? Truckload of bananas? Etc.