Copy link to clipboard
Copied
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!
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-re
...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thank you,
How to create a new style based on an existing style, e.g. existing "none" objectStyle, creat AA object style.
Copy link to clipboard
Copied
duplicate it
Copy link to clipboard
Copied
Found this one that brian_p_dts was talking about.
I'm a bit skeptical though, copying isn't based on it.
var myDocument = app.activeDocument;
myObjectStyle = myDocument.objectStyles.add({
name:"obj style 1",
enableTextFrameAutoSizingOptions: true,
textFramePreferences: {
autoSizingType: AutoSizingTypeEnum.HEIGHT_ONLY,
autoSizingReferencePoint: AutoSizingReferenceEnum.TOP_CENTER_POINT,
}
})
myNewObjectStyle = myObjectStyle.duplicate();
myNewObjectStyle.name = "obj style 2";
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Hi m1b.
Thank you very much.
There's one missing.
Creates an new objectstyle based on "empty" objectstyle.
Copy link to clipboard
Copied
I have updated. 🙂
Copy link to clipboard
Copied
Thank you very much.
Very good study material.
Help me out, originally you wrote to convert selected rows to table headers and I am trying to duplicate the table headers.
I used the previous method of duplicating rows.
I found that when there is a spanning of rows or columns, it reports an error.
I see that you wrote specifically about solving cross rows and columns, but I can't quite read it..
Thanks.
Copy link to clipboard
Copied
Is there any way to set a shortcut for NewStyle?
Copy link to clipboard
Copied
Not that I know of.
Copy link to clipboard
Copied
There really isn't any information about it yet.
Probably no way to judge the conflict
Copy link to clipboard
Copied
Copy link to clipboard
Copied
After adding a new group,
the newly created style ABC is no longer based on “trueNone”.
I've been working on this for ages and still can't figure out what's wrong.
var sL = newObjStyle(app.activeDocument, "ABC", emptyStyle, "Group");
/**
* Returns an object style named `name`, or if it
* doesn't exist, returns an empty style.
* @author m1b
* @version 2025-07-18
* @param {Document} doc - an Indesign document.
* @param {String} name - the style's name.
* @param {ObjectStyle} parentObjectStyle - the style to base the new style on.
* @returns {ObjectStyle}
*/
//CreatObj
var d = app.activeDocument;
var emptyStyle = newObjStyle(d, 'trueNone');
function newObjStyle(d, n, parentObjectStyle, g) {
if (g != null) {
var group = d.objectStyleGroups.itemByName(g);
if (!group.isValid)
group = d.objectStyleGroups.add({ name: g })
if (!group.objectStyles.itemByName(n).isValid)
group.objectStyles.add({ name: n });
}
if (d.objectStyles.itemByName(n).isValid) {
return d.objectStyles.itemByName(n);
} else {
var style = getThing(d.allObjectStyles, 'name', n);
if (style)
return style;
style = d.objectStyles.add({
name: n,
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 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];
};
Copy link to clipboard
Copied
@dublove I have updated the script above to show creating an object style inside an existing group.
- Mark
Copy link to clipboard
Copied
Also there is a mistake in your code (maybe just when pasting here on forum?) where you create `sL` before creating `emptyStyle`. That would explain why you aren't getting a proper empty style as a result.
- Mark
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@dublove I have updated the script above to create the object style group if it is missing. - Mark
Copy link to clipboard
Copied
Hi@m1b
You've just created a new style called "NewStyle".
var newStyle = makeObjectStyle(styleGroup, ‘NewStyle’, emptyStyle);
and set one or two properties for it.
Then create NewStyle2 based on NewStyle. Try it out and see if NewStyle2 inherits any settings from NewStyle.
I tried it, and it doesn't work.
You need to reset the base style, but I'm not sure how to implement that step.
Copy link to clipboard
Copied
It seems that using `basedOn` doesn't always work. I've now adopted the approach of copying to get the second style, which has resolved the issue.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now