Skip to main content
dublove
Legend
July 13, 2025
Answered

How to create new object styles based on really  "NONE" Object using scripts?

  • July 13, 2025
  • 2 replies
  • 905 views

I realized that the  "NONE" object in the object style is not really none, it still has a lot of settings.

I would like to create a real none object style (e.g. named "trueNone ").
Then create a new AA object style based on "trueNone".

How to write it?
Thank you very much!

 

Correct answer m1b

Hi @dublove, this will do it.

- Mark

 

/**
 * @file Make Object Style.js
 *
 * Note: the `makeObjectStyle` function can create
 * an *empty* object style, with no settings enabled.
 * 
 * In this example, we make "EMPTY" object style and then
 * make "NewStyle" which is based on "EMPTY". We make both
 * styles in the "My Group" ObjectStyleGroup.
 *
 * @author m1b
 * @version 2025-10-01
 * @discussion https://community.adobe.com/t5/indesign-discussions/how-to-create-new-object-styles-based-on-really-quot-none-quot-object-using-scripts/m-p/15412503
 */
function main() {

    var doc = app.activeDocument;
    var styleGroup = makeObjectStyleGroup(doc, 'My Group');
    var emptyStyle = makeObjectStyle(styleGroup, 'EMPTY');
    var newStyle = makeObjectStyle(styleGroup, 'NewStyle', emptyStyle);

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Do Script');

/**
 * Returns an object style named `name`, or if it
 * doesn't exist, returns an empty style.
 * @author m1b
 * @version 2025-10-01
 * @param {Document|ObjectStyleGroup} container - the container for the new style.
 * @param {String} name - the style's name.
 * @param {ObjectStyle} [parentObjectStyle] - the style to base the new style on (default: nothing).
 * @returns {ObjectStyle}
 */
function makeObjectStyle(container, name, parentObjectStyle) {

    if (
        !container
        || !container.hasOwnProperty('allObjectStyles')
    )
        throw new Error('makeObjectStyle: bad `container` supplied.');

    var style = getThing(container.allObjectStyles, 'name', name);

    if (style)
        return style;

    style = container.objectStyles.add({
        name: name,
        enableAnchoredObjectOptions: false,
        enableExportTagging: false,
        enableFill: false,
        enableFrameFittingOptions: false,
        enableObjectExportAltTextOptions: false,
        enableObjectExportEpubOptions: false,
        enableObjectExportTaggedPdfOptions: false,
        enableParagraphStyle: false,
        enableStoryOptions: false,
        enableStroke: false,
        enableStrokeAndCornerOptions: false,
        enableTextFrameAutoSizingOptions: false,
        enableTextFrameBaselineOptions: false,
        enableTextFrameColumnRuleOptions: false,
        enableTextFrameFootnoteOptions: false,
        enableTextFrameGeneralOptions: false,
        enableTextWrapAndOthers: false,
        enableTransformAttributes: false,
    });

    style.contentEffectsEnablingSettings.properties = {
        enableBevelEmboss: false,
        enableDirectionalFeather: false,
        enableDropShadow: false,
        enableFeather: false,
        enableGradientFeather: false,
        enableInnerGlow: false,
        enableInnerShadow: false,
        enableOuterGlow: false,
        enableSatin: false,
        enableTransparency: false,
    };

    style.objectEffectsEnablingSettings.properties = {
        enableBevelEmboss: false,
        enableDirectionalFeather: false,
        enableDropShadow: false,
        enableFeather: false,
        enableGradientFeather: false,
        enableInnerGlow: false,
        enableInnerShadow: false,
        enableOuterGlow: false,
        enableSatin: false,
        enableTransparency: false,
    };

    if (parentObjectStyle && parentObjectStyle.isValid)
        style.basedOn = parentObjectStyle;

    return style;

};

/**
 * Returns an ObjectStyleGroup named `name`,
 * creating it if necessary in `container`.
 * @author m1b
 * @version 2025-10-01
 * @param {Document|ObjectStyleGroup} container - the container for the new style.
 * @param {String} name - the style's name.
 */
function makeObjectStyleGroup(container, name) {

    if (
        !container
        || !container.hasOwnProperty('objectStyleGroups')
    )
        throw new Error('makeObjectStyleGroup: bad `container` supplied.');

    var styleGroup = getThing(container.objectStyleGroups, 'name', name);

    if (!styleGroup)
        styleGroup = container.objectStyleGroups.add({ name: name });

    return styleGroup;

};

/**
 * Returns a thing with matching property.
 * If `key` is undefined, evaluate the object itself.
 * @author m1b
 * @version 2024-04-21
 * @param {Array|Collection} things - the things to look through.
 * @param {String} [key] - the property name (default: undefined).
 * @param {*} value - the value to match.
 * @returns {*?} - the thing, if found.
 */
function getThing(things, key, value) {

    for (var i = 0; i < things.length; i++)
        if ((undefined == key ? things[i] : things[i][key]) == value)
            return things[i];

};

Edit 2025-07-18: added "basedOn" support.

Edit 2025-10-01: changed parameter `doc` to `container` and modify code to handle either Document or ObjectStyleGroup, so we can create the style inside a group. (Note: this script does not create the object style group if it is missing.)

Edit 2025-10-01: added "makeObjectStyleGroup" function to create the group if missing.

2 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
July 18, 2025

Hi @dublove, this will do it.

- Mark

 

/**
 * @file Make Object Style.js
 *
 * Note: the `makeObjectStyle` function can create
 * an *empty* object style, with no settings enabled.
 * 
 * In this example, we make "EMPTY" object style and then
 * make "NewStyle" which is based on "EMPTY". We make both
 * styles in the "My Group" ObjectStyleGroup.
 *
 * @author m1b
 * @version 2025-10-01
 * @discussion https://community.adobe.com/t5/indesign-discussions/how-to-create-new-object-styles-based-on-really-quot-none-quot-object-using-scripts/m-p/15412503
 */
function main() {

    var doc = app.activeDocument;
    var styleGroup = makeObjectStyleGroup(doc, 'My Group');
    var emptyStyle = makeObjectStyle(styleGroup, 'EMPTY');
    var newStyle = makeObjectStyle(styleGroup, 'NewStyle', emptyStyle);

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Do Script');

/**
 * Returns an object style named `name`, or if it
 * doesn't exist, returns an empty style.
 * @author m1b
 * @version 2025-10-01
 * @param {Document|ObjectStyleGroup} container - the container for the new style.
 * @param {String} name - the style's name.
 * @param {ObjectStyle} [parentObjectStyle] - the style to base the new style on (default: nothing).
 * @returns {ObjectStyle}
 */
function makeObjectStyle(container, name, parentObjectStyle) {

    if (
        !container
        || !container.hasOwnProperty('allObjectStyles')
    )
        throw new Error('makeObjectStyle: bad `container` supplied.');

    var style = getThing(container.allObjectStyles, 'name', name);

    if (style)
        return style;

    style = container.objectStyles.add({
        name: name,
        enableAnchoredObjectOptions: false,
        enableExportTagging: false,
        enableFill: false,
        enableFrameFittingOptions: false,
        enableObjectExportAltTextOptions: false,
        enableObjectExportEpubOptions: false,
        enableObjectExportTaggedPdfOptions: false,
        enableParagraphStyle: false,
        enableStoryOptions: false,
        enableStroke: false,
        enableStrokeAndCornerOptions: false,
        enableTextFrameAutoSizingOptions: false,
        enableTextFrameBaselineOptions: false,
        enableTextFrameColumnRuleOptions: false,
        enableTextFrameFootnoteOptions: false,
        enableTextFrameGeneralOptions: false,
        enableTextWrapAndOthers: false,
        enableTransformAttributes: false,
    });

    style.contentEffectsEnablingSettings.properties = {
        enableBevelEmboss: false,
        enableDirectionalFeather: false,
        enableDropShadow: false,
        enableFeather: false,
        enableGradientFeather: false,
        enableInnerGlow: false,
        enableInnerShadow: false,
        enableOuterGlow: false,
        enableSatin: false,
        enableTransparency: false,
    };

    style.objectEffectsEnablingSettings.properties = {
        enableBevelEmboss: false,
        enableDirectionalFeather: false,
        enableDropShadow: false,
        enableFeather: false,
        enableGradientFeather: false,
        enableInnerGlow: false,
        enableInnerShadow: false,
        enableOuterGlow: false,
        enableSatin: false,
        enableTransparency: false,
    };

    if (parentObjectStyle && parentObjectStyle.isValid)
        style.basedOn = parentObjectStyle;

    return style;

};

/**
 * Returns an ObjectStyleGroup named `name`,
 * creating it if necessary in `container`.
 * @author m1b
 * @version 2025-10-01
 * @param {Document|ObjectStyleGroup} container - the container for the new style.
 * @param {String} name - the style's name.
 */
function makeObjectStyleGroup(container, name) {

    if (
        !container
        || !container.hasOwnProperty('objectStyleGroups')
    )
        throw new Error('makeObjectStyleGroup: bad `container` supplied.');

    var styleGroup = getThing(container.objectStyleGroups, 'name', name);

    if (!styleGroup)
        styleGroup = container.objectStyleGroups.add({ name: name });

    return styleGroup;

};

/**
 * Returns a thing with matching property.
 * If `key` is undefined, evaluate the object itself.
 * @author m1b
 * @version 2024-04-21
 * @param {Array|Collection} things - the things to look through.
 * @param {String} [key] - the property name (default: undefined).
 * @param {*} value - the value to match.
 * @returns {*?} - the thing, if found.
 */
function getThing(things, key, value) {

    for (var i = 0; i < things.length; i++)
        if ((undefined == key ? things[i] : things[i][key]) == value)
            return things[i];

};

Edit 2025-07-18: added "basedOn" support.

Edit 2025-10-01: changed parameter `doc` to `container` and modify code to handle either Document or ObjectStyleGroup, so we can create the style inside a group. (Note: this script does not create the object style group if it is missing.)

Edit 2025-10-01: added "makeObjectStyleGroup" function to create the group if missing.

dublove
dubloveAuthor
Legend
July 18, 2025

Hi  m1b.

Thank you very much.

 

There's one missing.
Creates an new objectstyle based on "empty" objectstyle.

m1b
Community Expert
Community Expert
July 18, 2025

I have updated. 🙂

leo.r
Community Expert
Community Expert
July 13, 2025

If I understand your question correctly, you'll need to set these properties to false:

 

The screenshot is from AppleScript dictionary, but you can easily transform the properties to their JS equivalents.

leo.r
Community Expert
Community Expert
July 13, 2025
dublove
dubloveAuthor
Legend
July 14, 2025

Thank you,
How to create a new style based on an existing style, e.g. existing "none" objectStyle, creat AA object style.