5 Replies Latest reply on Jun 16, 2010 2:59 PM by sstanleyau

    scripting xml map and exporting xml (applescript)

    IowaBoy9

      I am trying to create a workflow using applescrips whereever possible. I have a large set of documents with the same paragraph and character styles. I want to create a set of tags, map styles to these tags, and export the document to xml. My trial script is below. The lines that create tags work fine. The "make xml export map" lines do not seem to be working, nor does the "export to test.xml" line.

       

      NOTE: all the active paragraph and character styles are in style groups with names like "HeadStyles" and "BodyStyles". Placing the group names before the paragraph style names ("BodyStyles:Main_SuggestedTime") does not change the outcome. When I run the script, the tags appear but the style to tag mapping does not show up in the Map Styles to Tags menu. No errors appear and the applescript result window shows that actions taking place.

       

      Any hints would be appreciated.

       

      tell application "Adobe InDesign CS3"
          set myDocument to active document
          tell myDocument
              set myRootXMLElement to XML element 1
              set chapter to make XML tag with properties {name:"chapter"}

              set chapterTime to make XML tag with properties {name:"chapterTime"}
              --more like this
              make XML export map with properties {markup tag:"chapter", mapped style:"Head_Main"}
              make XML export map with properties {markup tag:"chapterTime", mapped style:"BodyStyles:Main_SuggestedTime"}
              map styles to XML tags
              export to "test.xml" format "XML"
              --save XML tags to "xml_tags.xml"
          end tell
      end tell

        • 1. Re: scripting xml map and exporting xml (applescript)
          sstanleyau Level 4

          If your styles are in style groups, you need to use references to them rather than just style names. So roughly:

           

              tell myDocument

                  set mainHeadStyle to paragraph style "Head_Main" of paragraph style group "HeadStyles"

               [...]

                  make XML export map with properties {markup tag:"chapter", mapped style: mainHeadStyle}

          If you're not sure of the groups, you can also use something like:

                  set mainHeadStyle to item 1 of all paragraph styles whose name is "Head_Main"

           

          • 2. Re: scripting xml map and exporting xml (applescript)
            IowaBoy9 Level 1

            No love.

             

            Here is the adjusted script.

             

            tell application "Adobe InDesign CS3"
                set myDocument to active document
                tell myDocument
                    set myRootXMLElement to XML element 1
                    set chapter to make XML tag with properties {name:"chapter"}
                   --more like this.
                    set chapterStyle to paragraph style "Head_Main" of paragraph style group "HeadStyles"
                    make XML export map with properties {markup tag:"chapter", mapped style:"chapterStyle"}
                    --make XML export map with properties {markup tag:"chapterTime", mapped style:"BodyStyles:Main_SuggestedTime"}
                    map styles to XML tags
                    export to "test.xml" format "XML"
                    --save XML tags to "xml_tags.xml"
                end tell
            end tell

             

            Here is the result:

             

            tell application "Adobe InDesign CS3"
                get active document
                    --> document "77913WWPTWEG7_ILC21.indd"
                get XML element 1 of document "77913WWPTWEG7_ILC21.indd"
                    --> XML element id 2 of document "77913WWPTWEG7_ILC21.indd"
                make with properties {name:"chapter"} new XML tag
                    --> XML tag id 37887 of document "77913WWPTWEG7_ILC21.indd"
               --items cut from here.
                get paragraph style "Head_Main" of paragraph style group "HeadStyles" of document "77913WWPTWEG7_ILC21.indd"
                    --> paragraph style id 33492 of paragraph style group id 34226 of document "77913WWPTWEG7_ILC21.indd"
                make with properties {markup tag:"chapter", mapped style:"chapterStyle"} new XML export map
                map styles to XML tags document "77913WWPTWEG7_ILC21.indd"
                export document "77913WWPTWEG7_ILC21.indd" to "test.xml" format "XML"
            end tell

             

            No export document; no change to the "map Styles to Tags" menu.

             

            ??

            • 3. Re: scripting xml map and exporting xml (applescript)
              IowaBoy9 Level 1

              You are on to something, however. When I move styles out of a group to the "root" level of the style palette, the script is able to address them. So the issue is one of addressing a style inside a group. Or perhaps it an issue of moving a style outside a group.

              • 4. Re: scripting xml map and exporting xml (applescript)
                IowaBoy9 Level 1

                Workaround:

                 

                move all styles out of groups using the move command:

                 

                move all paragraph styles of paragraph style group "HeadStyles" to end

                 

                The rest of the script now works.

                • 5. Re: scripting xml map and exporting xml (applescript)
                  sstanleyau Level 4

                  It won't work wuthout making references to all the styles you use. And you then need to use the references as variables, not strings. So this:

                   

                          make XML export map with properties {markup tag:"chapter", mapped style:"chapterStyle"}

                   

                  shouldn't have quotes around chapterStyle.

                  1 person found this helpful