3 Replies Latest reply on Jan 4, 2013 6:57 PM by SLTyPete

    REVISED Puzzle: how to script adding XML parent?

    SLTyPete

      I've made progress, and hit a wall. Turns out:

      • In both the UI and script, if you add an XML element anywhere in the structure, it is added inside a current paragraph... and all elements moved inside the new element get their paragraph style changed to the style of the enclosing paragraph. Not fun, and not documented anywhere that I can see.
      • In the UI, there are two options: New Element, and New Parent Element.
      • The difference: if you add New Parent Element to one or more elements, the new parent encloses the other elements, and does NOT "color" the styling of the enclosed elements in any way.
      • The problem: I can't see a way to replicate this function in a script! I have searched the documents, the guides, the object model, the demos, etc.

       

      SO... my questions:

       

      1. Does anyone have an idea how to accomplish "New Parent Element" (in the Structure side menu) in a script?
      2. For things like this, with little if any known documentation, are there any analytical tools that help in deciphering how InDesign does it?
      3. If we are ultimately unsuccessful, how do I make this painful gap known to Adobe?

       

      Thanks much,

      Pete

        • 1. Re: REVISED Puzzle: how to script adding XML parent?
          SLTyPete Level 1

          I'd love any hints, and/or confirmation that others can replicate this issue.

          • 2. Re: REVISED Puzzle: how to script adding XML parent?
            Loic.Aigon Adobe Community Professional

            Hi,

             

            Don't know if it helps but you can generate a parent XMLElement on the fly and move the xmlElement inside.

             

            app.selection[0] is some tagged text.

            "parentXE" is the markupTag you want to use for the parent


            var refXE = app.selection[0].associatedXMLElements[0];
            var  parentXE = refXE.parent.xmlElements.add ( "parentXE" );
            refXE.move ( LocationOptions.UNKNOWN , parentXE )
            

             

             

            For the doc, consider Jongware html files.

             

            And for any request regarding Adobe Products : https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

             

            It sems that CS7 is going to review the XML engine. It may be time to supply

             

            Loic

            • 3. Re: REVISED Puzzle: how to script adding XML parent?
              SLTyPete Level 1

              Sorry Loic, that does NOT work.

               

              Yes, you can generate an XML element on the fly and move things inside. But that's not the same as directly generating a PARENT element. There is a difference.

               

              Here's a very very basic example that demonstrates the issue.

               

              Grab this two-line InDD file.

              • Open the Structure view (ctrl-alt-1) and Paragraph Styles window.
              • You'll see the two paragraphs each have their own XML tag and paragraph style; both are in a Story, which is in Root (as it should be).
              • Double click in the Structure pane on either paragraph; you will see the Para Style for each is properly set.
              • Open the Story editor (ctrl-Y). Everything will look "normal"
              • Now select the first paragraph
              • Step through the following minimal script (F10), while watching the structure pane

               

               

              #target indesign
              var refXE = app. selection[0].associatedXMLElements[0];
              var  parentXE = refXE.parent.xmlElements.add ( "parentXE" );
              refXE.move ( LocationOptions.UNKNOWN , parentXE );
              

               

              The "parentXE" tag will first show up at the end of the Story. Then it will become the parent of Para1. (And will be at the end of the story).

               

              If you now double click on the paragraphs and on parentXE, you will see some changes:

              • parentXE has a paragraph style: PStyle2. That's because it was first placed at the end of the story, and absorbed the style of the neighboring PStyle2 paragraph.
              • Para1 has now been given PStyle2 instead of PStyle1. That's because it is inside parentXE.
              • ANYthing you move under parentXE will take on PStyle2 from now on!

               

              You can replicate this in the UI:

              • Close (without saving) and reopen the file.
              • Select the Para1 (PStyle1) tag in the structure pane
              • In the side menu, choose New Element and make a parentXE element
              • The new element will be at the end, and (if you double click it) will have style PStyle2
              • Drag the PStyle1 element underneath so parentXE is its parent. Now the PStyle1 element (double click to select) also has PStyle2

               

              BUT if you slightly modify:

              • Close (without saving) and reopen the file.
              • Select the Para1 (PStyle1) tag in the structure pane
              • In the side menu, choose New Parent Element and make a parentXE element
              • The new element will already be the parent, and (if you double click it) will have NO paragraph style
              • Drag any/all tags within... they all properly retain their formatting.

               

              That's the issue in a nutshell.

               

              Using "New Element" and making it parent (either in UI or in script) causes formatting to be broken/lost

              But using "New Parent Element" in the UI works perfectly. I just don't know how to accomplish this in a script

               

              Blessings,

              Pete