8 Replies Latest reply on Jan 11, 2012 5:33 PM by romanobstuder

    ID Style Editor outside of ID

    romanobstuder

      Hi all

      I have files that contain lots of styles. > 100.

      (Styles are matched up to XML tags and content is layed out via script).

      I am looking for a tool to de-bug the styles in a DB or Spread Sheet Fashion.

      Something where I could spot the one Style that is set to the wrong type size in a nice scroll list. -)

       

      Is there such an editor?

       

      Any hints appreciated

      Romano

        • 1. Re: ID Style Editor outside of ID
          [Jongware] Most Valuable Participant

          Annoyingly I can't get this to work but it might trigger a few neurons for someone else:

           

          1. Create an empty text frame

          2. Put your cursor in it

          3. Run the script from Creating a Style List to fill it with all of your styles

          4. Export as snippet.

          5. Edit this snippet with any plain text or XML editor you like

          6. Re-load the styles

           

          It's only point #6 that I can't get to work! If you load the snippet into a new document, you'll get to see all of your changes; but if you load it into your current document, your adjusted styles don't overwrite the current ones.

          • 2. Re: ID Style Editor outside of ID
            Pickory Level 3

            How about deleting all styles before re-loading them.

            • 3. Re: ID Style Editor outside of ID
              romanobstuder Level 1

              If you delet a style, ID needs to know what style it needs to assigne to the part of the text that used this very style.

              You would loose your formating.

              So I don't belive you can fix it that way.

              I will look at Jongware's code and see what it does for me.

               

              BTW: I am sure a direct XML export of all things Style would be a great tool.

              One could then create a more or less fancy editor for this and back import it into the ID file.

               

              One more idea for a rainy weekend. -)

               

              Thank you all

              Romano

              • 4. Re: ID Style Editor outside of ID
                [Jongware] Most Valuable Participant

                That would lose the link to where they are used, and the OP ends up with correct styles but with totally unstyled text.

                • 5. Re: ID Style Editor outside of ID
                  [Jongware] Most Valuable Participant

                  romanobstuder wrote:

                   

                  BTW: I am sure a direct XML export of all things Style would be a great tool.

                  One could then create a more or less fancy editor for this and back import it into the ID file.

                  One more idea for a rainy weekend. -)

                   

                  Ah now that would work! If you are comfortable with plain XML files, I can see what I can do.

                   

                  For: it's raining right now. Against: not weekend yet.

                  • 6. Re: ID Style Editor outside of ID
                    Peter Spier Most Valuable Participant (Moderator)

                    [Jongware] wrote:

                     

                    It's only point #6 that I can't get to work! If you load the snippet into a new document, you'll get to see all of your changes; but if you load it into your current document, your adjusted styles don't overwrite the current ones.

                    Right, same named style definitons are controlled by the receiving file. To get the styles to remap you'd need to load the snippet into a new file, then choose Load Styles from one of the flyout menus and tell ID to use the incoming styles in case of conflict.

                    • 7. Re: ID Style Editor outside of ID
                      [Jongware] Most Valuable Participant

                      Hah -- this is one of those things that turn out to be ... interesting.

                       

                      Problem #1: Properties, properties, more properties!

                      First of all, paragraph styles have a lot of properties. A lot -- this seemingly innocent one-line alert shows them all:

                       

                      app.activeDocument.paragraphStyles[0].reflect.properties;
                      

                       

                      and I bet you don't want to review all 180 of them (for CS4), if only because some of them are read-only and for internal use (id, index, _proto_ ) and others are just obscure (miterLimit, gradientFillAngle, strikeThroughGapTint). However, you might want to check the entire list as I only hand-picked a couple I thought were generally useful. The entire list can be viewed on-line on http://jongware.mit.edu/idcs4js/pc_ParagraphStyle.html (CS4), http://jongware.mit.edu/idcs5js/pc_ParagraphStyle.html (CS5) or http://jongware.mit.edu/idcsjs5.5/pc_ParagraphStyle.html (CS5.5).

                       

                      Problem #2: Style Groups! (shudder)

                      The way I wrote the code it will output either a simple style name, or a nested series of <group> for each level of style grouping. That results in XML like this:

                       

                      <group>Style group/2<group>Style Group:1<name>Header</name></group></group>
                      

                       

                      which is a style named "Header" inside a group "Style Group:1" inside a group "Style group/2". It might be easier if the entire group+name is a single string, but then you'd have to think about proper separators (the forward slash and the colon were my attempts to make InDesign complain, but it seems everything is allowed).

                      This also depends on the software you are using to edit the XML -- can it handle such groupings?

                       

                      Problem #3: Composite Objects!

                      The "appliedFont" in a paragraph style is not just a simple name, but a first-class Object instead, and naively asking for 'the value' will return "[Object Font]". So you have to make an exception for this, digging into the Font object to retrieve its name. Same goes for "fillColor" (and everything else with color), and probably a couple of other properties as well. I, uh, handle these as they come

                      "Font" has another potential problem, as simply retrieving its name "Times New Roman Italic" works but you cannot write it back that way! The write-back script -- which I still have to think about -- cannot safely write back the entire font name at once, and also not by first writing its family name and then its style (in the fontStyle property). That's because some fonts use complicated style names -- "46 Italic", for Univers, or "Semibold Condensed" for Myriad Pro -- and if you don't match font name plus style, InDesign rejects it in its entirety. The trick is to write "appliedFont" with the font family name plus a tab plus the style name at once; but for that you need to have it separated into its components, with a tab, in the first place. So I handle that in code too.

                      ... And you have to remember to insert a [Tab] character in your editor between font name and style.

                       

                      Problem #4: Enumerations!

                      A lot of the properties are not simple values or names, but come from a specific set of enumerations. "leading" is a nice one: it's either a numerical value, or the special value 1635019116, which is the enumeration value for "Leading.AUTO". "justification" is another -- it can only be one of the predefined values 1633772147, 1667591796, 1667920756, 1718971500, 1818584692, 1818915700, 1919379572, 1919578996, or 1630691955. That won't help you a lot, I'm afraid.

                      Now I know that all of these values are (a) simple integers, and (b) use all 4 bytes -- so I test if it contains something in the highest bytes, and if so, I convert the property name to Initial Case (gasp!) and test if there is an enumeration with that name (shudder!). Sure to fail somewhere, but so far it seems to be working.

                       

                      Problem #5: Write back!

                      I hope you can give some input on this because this also is ... interesting. Should the code create a new style if it doesn't exist under that name? What about style groups?

                       

                      Oh well, here is ID Style Editor Part 1 -- Exporting. Part 2 I have to think about for a while.

                       

                      var interestingProperties = [
                          "alignToBaseline", "appliedFont", "autoLeading",
                          "baselineShift", "capitalization", "fillColor", "fillTint", "firstLineIndent",
                          "hyphenation", "justification", "keepAllLinesTogether",
                          "keepFirstLines", "keepLastLines", "keepLinesTogether", "keepWithNext",
                          "lastLineIndent", "leading", "leftIndent", "pointSize", "rightIndent",
                          "spaceAfter", "spaceBefore"
                      ];
                      
                      /* Very handy helper  by Marc Autret (http://forums.adobe.com/thread/466357)
                      /*str*/Object.prototype.enumName = function(/*int*/enumId)
                      {
                         for ( var p in this )
                            if ( this[p] == enumId ) return(p);
                               return null;
                      }
                      
                      errorlist = [];
                      
                      styles = app.activeDocument.allParagraphStyles;
                      string = [ '<?xml version ="1.0" encoding ="utf-8"?>', '<styles>'];
                      
                      // string.push ('<!-- '+app.activeDocument.paragraphStyles[0].reflect.properties+' -->');
                      
                      for (i=2; i<styles.length; i++)
                      {
                          string.push('\t<style id="id_'+String(styles[i].id)+'">');
                          if (styles[i].parent instanceof ParagraphStyleGroup)
                          {
                                    p = styles[i];
                                    value = '<name>'+styles[i].name+'</name>';
                                    while (p.parent instanceof ParagraphStyleGroup)
                                    {
                                              value = "<group>"+p.parent.name+value+"</group>";
                                              p = p.parent;
                                    }
                                    string.push ("\t\t"+value);
                          } else
                          {
                                    string.push('\t\t<name>'+styles[i].name+'</name>');
                          }
                          for (j=0; j<interestingProperties.length; j++)
                          {
                                    if (interestingProperties[j] == '')
                                              continue;
                                    value = styles[i][interestingProperties[j]];
                                    if (value instanceof Font)
                                              value = value.fontFamily+"\t"+value.fontStyleName;
                                    if (value instanceof Swatch)
                                              value = value.name;
                                    if (value instanceof Color)
                                              value = value.name;
                                    // All enumerations have a value in the highest byte (...)
                                    if (value.constructor.name == "Number" && value > 0 && (value & 0xff000000) )
                                    {
                                              // Dirty hack to get possible enum name!
                                              tmp = interestingProperties[j].substring(0,1).toUpperCase()+interestingProperties[j].substring(1);
                                              try {
                                                              tmp = eval (tmp+".enumName("+styles[i][interestingProperties[j]]+")");
                                                              if (tmp)
                                                                        value = tmp;
                                                    } catch (e) { }
                                    }
                                    if (value.constructor.name == "Boolean" ||
                                              value.constructor.name == "Number" ||
                                              value.constructor.name == "String")
                                    {
                                              string.push ("\t\t<"+interestingProperties[j]+">"+
                                                        value+
                                                        "</"+interestingProperties[j]+">");
                                    } else
                                    {
                                              errorlist.push ("Property "+interestingProperties[j]+" is of type '"+value.constructor.name+"'");
                                              interestingProperties[j] = '';
                                    }
                          }
                          string.push('\t</style>');
                      }
                      string.push('</styles>');
                      
                      
                      if (errorlist.length)
                                alert (errorlist.join("\r"));
                      
                      
                      defaultFile = new File (Folder.myDocuments+"/styles.xml");
                      if (File.fs == "Windows")
                                writeFile = defaultFile.saveDlg( 'Save Style XML as:', "XML files:*.xml;All files:*.*" );
                      else
                                writeFile = defaultFile.saveDlg( 'Save Style XML as:');
                      if (writeFile != null)
                      {
                                if (writeFile.open("w"))
                                {
                                          writeFile.encoding = "utf8";
                                          for (i=0; i<string.length; i++)
                                                    writeFile.writeln (string[i]);
                                          writeFile.close();
                                } else
                                          alert ("unable to create file "+writeFile.fsName);
                      }
                      
                      • 8. Re: ID Style Editor outside of ID
                        romanobstuder Level 1

                        WOW!

                         

                        I will need a bit more then 5 min to look at all this.

                        You do know your stuff!

                         

                        In the specific project we eliminated all style groups. To make live easy we named the XML tags in the data input exactly the same as the styles.

                        ID actually matches the names automatically. As soon as you hide the styles inside groups, that does not play. (Bit of lazy programing Monsieur Adobe...)

                         

                        For a more generic aproach (We could make this into a product!) I think one would need a way of supporting the groups.

                         

                        Now we also had a big headake with the Cell Styles. Again we had stacks of them and we had a parent Style from which child Styles were to inherit the bottom line style and strength. The financial data needed underlines in a fine and a thick style for the totals.

                        Now if the designers would change the line strength we hoped to do this in the parent style and this would inherit through. Not so.

                        We ended up with explicit styles.

                         

                        And this is one of the main reasons I am looking for an editor where I can see all of my styles in a table.

                         

                        I am looking after the kids for a few days and will not be in my office till Monday. Then I will run your code and see what happens.

                        Thanks heaps for your contribution!

                         

                        And yes I think this is a very interesting avenue that I never looked at so far. Let's see how far down the rabbit hole we need to go...-)

                        Romano