Skip to main content
KlausFriese
Inspiring
April 1, 2020
Answered

Scripting: How to copy ObjectStyle to another document?

  • April 1, 2020
  • 1 reply
  • 1166 views

Hi,

 

I try to copy an ObjectStyle from one document to another, I didn't find a "copy" method so I tried to duplicate and move the style.

This is my code:

 

var destDoc = app.open( "destination.indd" );
var sourceDoc = app.open( "source.indd" );
var ObjectStyleName = "MyStyle";
var sourceStyle = sourceDoc.objectStyles.itemByName( ObjectStyleName );
var destStyle = sourceStyle.duplicate();
destStyle.move( LocationOptions.AT_END , destDoc );

 

But the style is not moved to the destination - what's wrong here?

Thanks for any tipps

Klaus

This topic has been closed for replies.
Correct answer Peter Kahrel

Apply the object style to a text frame or rectangle, move/duplicate that frame to the target document, then delete the frame. That'll leave the object style in the target document. (This is also the quickest manual way to copy style to another document.)

 

P.

1 reply

Derek Cross
Community Expert
Community Expert
April 1, 2020

You can just use "Load Object Styles" from the flyout menu in your new document and select the document you want to transfer object styles from.

(In the resulting Load Styles dialogue box you can select the Object Styles you wish to use.)

KlausFriese
Inspiring
April 1, 2020

Hi Derek,

 

thanks - but I need a Scripting solution, I know how to do this directly from the user interface.

 

Klaus

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
April 1, 2020

Apply the object style to a text frame or rectangle, move/duplicate that frame to the target document, then delete the frame. That'll leave the object style in the target document. (This is also the quickest manual way to copy style to another document.)

 

P.