Copy link to clipboard
Copied
var spDoc =app.documents[0];
var allPstyles = spDoc.allParagraphStyles;
var allCstyles = spDoc.allCharacterStyles;
spDoc.close();
var newDoc = app.documents[1];
for(var a=0; a<allPstyles.length;a++){
newDoc.paragraphStyles.add(allPstyles[0]);
}
I tried like this I am getting the styles as object but I don't know how to add it in new document!
Maybe this?:
//the frontmost doc
var spDoc =app.documents[0];
//its file path
var fp = spDoc.fullName
spDoc.close();
//the doc behind spDoc is now the front doc
var newDoc = app.documents[0];
newDoc.importStyles(ImportFormat.PARAGRAPH_STYLES_FORMAT, File(fp));
Copy link to clipboard
Copied
What happens if you don't close spDoc until the very end? I can't test right now so I'm just thinking about it. If spDoc is closed, the paragraphStyles references might be invalid. Also, if you can't find a better way, perhaps you could try applying each style to some temporary text in the new document. That is likely to add them to the document.
- Mark
Copy link to clipboard
Copied
Now its working fine
var spDoc =app.documents[0];
var allPstyles = spDoc.allParagraphStyles;
var allCstyles = spDoc.allCharacterStyles;
//spDoc.close();
var newDoc = app.documents[1];
for(var a=0; a<allPstyles.length;a++){
newDoc.paragraphStyles.add(allPstyles[0]);
}
As you said I tired without closing the current document and now it is working fine!
Thanks a lot Mark @m1b
Copy link to clipboard
Copied
Maybe this?:
//the frontmost doc
var spDoc =app.documents[0];
//its file path
var fp = spDoc.fullName
spDoc.close();
//the doc behind spDoc is now the front doc
var newDoc = app.documents[0];
newDoc.importStyles(ImportFormat.PARAGRAPH_STYLES_FORMAT, File(fp));
Copy link to clipboard
Copied
Hi @Karthik SG ,
look into DOM documentation!
Method add() for paragraph styles does NOT take a paragraph style object as argument.
It's taking an object of properties and values:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#ParagraphStyles.html#d1e545903__d1e545952
Look for a different method like document.importStyles() .
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html#d1e49521__d1e54566
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Paragraph style has a move method that takes document object as an argument as well. This method can be investigated. So do this
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#ParagraphStyle.html#d1e539931__d1e545655
-Manan
Copy link to clipboard
Copied
Hi @Karthik SG , Keeping the docs open doesn’t throw an error, but I don’t think you are actually moving the front document styles to the document behind. When I test your script the loop creates new styles but they all have the same properties and are named Paragraph Style 1, Paragraph Style 2...etc.
You could use the document’s importStyles() method:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html#d1e49521__d1e54566