8 Replies Latest reply on Aug 6, 2018 3:13 PM by lf.corullon

    Styles in target doc but not in source doc

    lf.corullon Level 3

      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!

        • 1. Re: Styles in target doc but not in source doc
          payalm68947498 Level 2

          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.

          • 2. Re: Styles in target doc but not in source doc
            Laubender Adobe Community Professional & MVP

            Hi,

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

            Adobe InDesign CS6 (8.0) Object Model JS: Document

             

            Regards,
            Uwe

            • 3. Re: Styles in target doc but not in source doc
              payalm68947498 Level 2

              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);
              
              • 4. Re: Styles in target doc but not in source doc
                lf.corullon Level 3

                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.

                • 5. Re: Styles in target doc but not in source doc
                  yadavs92328 Level 2

                  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++;
                          }
                      }
                  
                  2 people found this helpful
                  • 6. Re: Styles in target doc but not in source doc
                    lf.corullon Level 3

                    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[x].properties = sourceStyle[z].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[j].name.toString() == targetStyles[i].name.toString()) {
                                    match = true;
                                    }
                                }
                            if (match == false) {
                                sourceStyles[j].remove();
                                }
                            }
                    //~     myTargetFile.close(SaveOptions.YES);
                        }
                    
                    • 7. Re: Styles in target doc but not in source doc
                      Laubender Adobe Community Professional & MVP

                      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

                      • 8. Re: Styles in target doc but not in source doc
                        lf.corullon Level 3

                        Uwe,

                         

                        One more time, thanks for your attention!

                        Example files (in idml): http://lf.corullon.com.br/aarquivoslfc/syncstyles.rar