Skip to main content
lfcorullon13651490
Legend
January 16, 2018
Question

Styles in target doc but not in source doc

  • January 16, 2018
  • 4 replies
  • 1390 views

Hello, there.

Any of you already need to "sync" styles between documents, removing the ones that not match?

I have two documents. My source and my target.

I can't handle with this task.

Any help will be very appreciated.

Thank you so much!

This topic has been closed for replies.

4 replies

Sunil Yadav
Legend
June 29, 2018

Hi there,

    You should try this, this might help you,

var srcDoc = app.documents[0];

var trgtDoc = app.documents[1];

var srcStyles = srcDoc.paragraphStyles;

var sc = 0;

while(sc < trgtDoc.paragraphStyles.length){

    var myStyle = trgtDoc.paragraphStyles[sc];

    var sdc = 0;

    var match = false

    while(sdc < srcStyles.length){

        if(myStyle.name.toString() == srcStyles[sdc].name.toString()){

            match = true;

            sdc = srcStyles.length;

            }

        sdc++;

        }

    if(match==false){

        trgtDoc.paragraphStyles[sc].remove();

        }

    else{

        sc++;

        }

    }

lfcorullon13651490
Legend
August 3, 2018

Thank you so much for all suggestions.

But, I can't handle with this... yet.

My goal: "sync" paragraph styles between source and target documents.

Source: 700 styles

Target: 80 styles

The best way I can think to do what I want is: duplicate the source doc, saving it as temp, and matching the styles, removing all that don't match with the target files. So, I expect to get a temp file with 80 styles. And then, import styles to the target.

I tried a Harbs.​ suggestion too: targetStyle.properties = sourceStyle.properties. But I noticed that not all properties are "synchronized" (text fill color, for example).

So, I tried this code, but, of course, it doesn't work.

What am I doing wrong?

var myFileFolder = Folder(/*HERE GOES THE DEFAULT FOLDER*/).selectDlg("Select the folder.");

var myDialog = myFileFolder;

if (myDialog != null) {

    var myTargetFiles = myFileFolder.getFiles("*.indd");

    alert (myTargetFiles.length + " files were found in the selected.","Script by LFCorullón");

    var mySourceFile = File.openDialog("Select the source file...", "InDesign files:*indd;*indt");

    }

else {

    exit();

    }

mySourceFile = app.open(mySourceFile);

var sourceStyles = [];

var targetStyles = [];

var match = false;

for (var td=0; td<myTargetFiles.length; td++) {

    var myTargetFile = app.open(myTargetFiles[td]);

    var myTempFile = mySourceFile.save(File(Folder.temp + "/" + myTargetFile.name.replace(".indd", "") + "_estilos.indd"));

   

    for (var ss=0; ss<myTempFile.allParagraphStyles.length; ss++) {

        sourceStyles.push(myTempFile.allParagraphStyles[ss]);

        }

   

    for (var ts=0; ts<myTargetFile.allParagraphStyles.length; ts++) {

        targetStyles.push(myTargetFile.allParagraphStyles[ts]);

        }

    for (var j=sourceStyles.length-1; j>=2; j--) {

        for (var i=targetStyles.length-1; i>=0; i--) {

            if (sourceStyles.name.toString() == targetStyles.name.toString()) {

                match = true;

                }

            }

        if (match == false) {

            sourceStyles.remove();

            }

        }

//~     myTargetFile.close(SaveOptions.YES);

    }

Community Expert
August 6, 2018

Hi,

it's hard to tell what's going wrong without you telling what actually went wrong.

And also without seeing the documents.

Can you share the two documents?

Regards,
Uwe

payalm68947498
Inspiring
January 17, 2018

Hiii

     try this..

var myDoc = app.documents[0];

var stlyle = myDoc.paragraphStyles;

var myDoc2 = app.documents.add();

var FileName = path + "/" + fileName + ".indd";

var StylePath = myDoc.filePath + "/" + myDoc.name;

myDoc2.save(File(FileName), true);

myDoc2.importStyles(ImportFormat.paragraphStylesFormat, File(StylePath),GlobalClashResolutionStrategy.loadAllWithOverwrite);

Community Expert
January 17, 2018

Hi,

did you see into method importStyles() of object Document:

Adobe InDesign CS6 (8.0) Object Model JS: Document

Regards,
Uwe

lfcorullon13651490
Legend
January 17, 2018

Hi, Uwe and payalm. Yes. I'm using this.

But this don't deal with the styles that doesn't match. If the style is only on the target file, it remains there. I'm looking for a way to remove them (if they're not in use). Keeping only the styles that match between both docs, and, of course, are not in use.

payalm68947498
Inspiring
January 17, 2018

Hello....

     If you want to import or load styles that doesn't match that is possible through script and If you need to remove all the styles that doesn't match that is also can be done through script.