Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

[Script] Cannot set an object style as a default frame style if this style is inside a folder

New Here ,
Jul 11, 2022 Jul 11, 2022

I have a simple script:

 

var doc = app.activeDocument;

var myStyle = doc.objectStyleGroups.itemByName('My Group1').objectStyles.itemByName('My Style1');

doc.pageItemDefaults.appliedTextObjectStyle = myStyle;

 

I'd like to set "My Style1" as a default text frame style. But when this style is inside a folder - I get this error:

Invalid value for set property 'appliedTextObjectStyle'. Expected ObjectStyle or String, but received ObjectStyle

 

The following piece of code - where target style is at the first level, outside folders - works fine:

var doc = app.activeDocument;
var myStyle = doc.objectStyles.itemByName('2 Columns');
doc.pageItemDefaults.appliedTextObjectStyle = myStyle;

 

Does anyone know how I can set a style from the folder as a default text/graphic frame style ?

 

Screen Shot 2022-07-11 at 22.34.12.pngexpand image

TOPICS
Bug , How to , Scripting
699
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Guru , Jul 12, 2022 Jul 12, 2022

The same here in Indy 15.0.3 and 17.2.1, Win 10.

Definitely a bug!

Translate
Community Expert , Jul 12, 2022 Jul 12, 2022

Hi together,

I can re-create the issue as well on my German InDesign 2022 on Windows 10.

Tried it with the doc.allObjectStyles array. This failed when the object style was nested in an object style group and is clearly working when the object style is in the root of the Object Styles panel.

 

The workaround would be:

[1] Move the style to the root.

[2] Apply it to the pageItemDefaults

[3] Move it back to the group

 

if( myStyle.parent.constructor.name != "Document" )
{
	var objStyleGroup = mySty
...
Translate
Community Expert ,
Jul 11, 2022 Jul 11, 2022

Hmm, seems like a bug. I was able to re-create on my Windows 11 running ID 17.3. I'll let others weigh in; I haven't worked much with doc.pageItemDefaults so maybe there's a gotcha there. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jul 12, 2022 Jul 12, 2022

The same here in Indy 15.0.3 and 17.2.1, Win 10.

Definitely a bug!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2022 Jul 12, 2022

Hi together,

I can re-create the issue as well on my German InDesign 2022 on Windows 10.

Tried it with the doc.allObjectStyles array. This failed when the object style was nested in an object style group and is clearly working when the object style is in the root of the Object Styles panel.

 

The workaround would be:

[1] Move the style to the root.

[2] Apply it to the pageItemDefaults

[3] Move it back to the group

 

if( myStyle.parent.constructor.name != "Document" )
{
	var objStyleGroup = myStyle.parent;
	myStyle.move( LocationOptions.AT_END , doc );
	doc.pageItemDefaults.appliedTextObjectStyle = myStyle;
	myStyle.move( LocationOptions.AT_END , objStyleGroup );
}
else
{
	doc.pageItemDefaults.appliedTextObjectStyle = myStyle;
};

 

Note: You need perhaps another check for the name of the object style, because there could be a style in the root with the same name.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 12, 2022 Jul 12, 2022

Hi @Laubender

Thanks a lot! It works and solves my problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2022 Jul 12, 2022

Another note:
I can see the issue already with InDesign CS6 version 8.1 on Windows 10.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2022 Jul 12, 2022

I have submitted the bug to InDesign User Voice: https://indesign.uservoice.com/forums/601180-adobe-indesign-bugs/suggestions/45417503-object-styles-...

 

Please vote to increase visibility. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2022 Jul 12, 2022
LATEST

Hi Brian,

thank you very much. I voted for fixing the bug.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines