8 Replies Latest reply on Sep 17, 2010 2:33 AM by RF2009

    Access image placed by xml-rules

    Level 1
      Hi, I have to modify an image (width/height) which is placed by xml-rules.

      XML:
      ...
      >
      >  
      >

      ...

      JavaScript:
      ...
      > function SymbolRule() {
      >   this.name = "Symbol";
      >   this.xpath = "//sometag/Symbol[@typ='new']";
      >   this.apply = function (element, ruleProcessor) {
      >   with (element) {
      >     applyObjectStyle("somestyle");
      >  }
      }
      ...

      How can I now access this image to modify its properties?
      I've read http://www.adobeforums.com/webx/.59b7295a/2 but I don't understand *where* to place the code to access the image. Is it possible to do it in my XML-Rule SymbolRule()? Or is it "to early" because the image is no yet placed in the document?
        • 1. Re: Access image placed by xml-rules
          Level 1
          Siegfried,

          I'm not certain that I fully understand your question. But here's an answer to what I think you're asking.

          Once you create a rule (or a bunch of rules), you invoke them using the rule processor's glue code.

          (InDesign CS4/Scripts/XML Rules/glue code.jsx)

          In that script you'll see:

          function __processRuleSet (root, ruleSet, prefixMappingTable)

          In your code, AFTER you have imported your xml, you'll need to call this function with the appropriate XML element and an array or rules to process.

          var root = app.activeDocument.xmlElements[ 0 ];
          var ruleSet = [ new SymbolRule() ];

          __processRuleSet( root, ruleSet );

          Does that answer the question?

          Bob
          • 2. Re: Access image placed by xml-rules
            Level 1
            Bob, thank you for your answer. I already use the glue code, and processing the rules is working correctly. I see a populated document after running my script (also the image of the Symbol-Tag). My problem is that I have to modify this image (get smaller). And I like to do that as early/easily as possible. And I ask myself (and this group ;-) if it is already possible in the rule-function of this xml-element (how?) or if I have to process the rule, place the xml in document and after that navigate through the placed images to my desired one (is it possible by using the xml-id)?

            Siegfried
            • 3. Re: Access image placed by xml-rules
              srakete Level 1
              Hi Siegfried,

              in your Xml-Rule above add the line

              var myRectangle = myElement.xmlContent.parent;

              with (element) {
              applyObjectStyle("somestyle");
              var myRectangle = myElement.xmlContent.parent;
              ... do something with your rectangle here, e,g. scale it
              }

              Hope this helps.

              Stefan
              • 4. Re: Access image placed by xml-rules
                Level 1
                Hi Stefan,

                thank you for your answer. I've read your former posts to similar problems and always wondered about the data types of element and co.:

                $.writeln(element) -> [object XMLElement]
                $.writeln(element.parent) -> [object XMLElement]
                $.writeln(element.xmlContent) -> [object Text]
                $.writeln(element.xmlContent.parent) -> [object XmlStory]

                Are that the expected data types?

                I think XmlStory is not the expected type to look for my rectangle. And why is element.xmlContent a text object? Even Indesign shows this node with the icon for "graphic node" - an I see the image in the document after processing the rule-script.
                What else than the href-attribute makes an xml-node a "graphic" one?
                • 5. Re: Access image placed by xml-rules
                  Level 1
                  Hi Siegfried,

                  If the parent of the element is an XMLStory, that means that the Element is not placed anywhere in the layout. When a graphic is contained by an unplaced XML element, it is an inline/anchored object--i.e., it's contained by a text character. Is it possible that the element has not yet been placed in the layout at the point at which you're getting the types?

                  Whether or not that remains true depends on how you place the graphic in the layout--you can place it as either an inline graphic or an independent graphic.

                  Once you place the XML in a layout, the type of the parent element of the content will change.

                  Thanks,

                  Ole
                  • 6. Re: Access image placed by xml-rules
                    Level 1
                    Hi Ole, that's it, thank you very much!

                    The following code works fine within the apply-function if you first do the placeXML and after that call __processRuleSet:

                    xmlContent.parent.verticalScale = 50;
                    xmlContent.parent.horizontalScale = 50;

                    So I think it's a good idea to call __processRuleSet (with different rule sets) more than one time:

                    1. process the first ruleSet to handle all the steps that do not need to refer to placed frames e.g. formatting steps
                    2. place xml in the page
                    3. do all layout related steps that need to access the text/img container frames
                    • 7. Re: Access image placed by xml-rules
                      pp_paul

                      Unfortunately this approach does not work for me, and I have no clue why.

                      I have 2 anchored frames in a story, one is an image-frame and the other is a text-frame.

                      Those are automatically cloned during the xml-import using the standard "repeating elements" feature.

                      Now, in the scripting part, the task is to adjust some properties and borders of some of those frames according to the value of attributes of their respective XML-element. This works for attributes which can directly be applied using xpath, like object styles etc - but not for repositioning and resizing, which is what I need.

                       

                      But whatever I try: I get either a text object or a story or a document as the xmlContent (or its parent) - and never ever what I need: a page item or textframe (with geometricBounds that I could then adjust).

                       

                      Any idea what's wrong?

                      • 8. Re: Access image placed by xml-rules
                        RF2009

                        I have the exact same issue!

                         

                        My problem occurs after I unthread the document. After unthreading, the elements parent changes to XmlStory and I can't locate the parent page/spread.

                         

                        It's an anchored textframe within a table cell. So parent path is like so:

                         

                        obj (textframe) -> Character -> Cell -> Table -> XmlStory -> Document

                         

                        In InDesign I can see that the object is on the page and visible.

                         

                        I would like to get to the page.

                         

                        Any help would be greatly appreciated.

                         

                        Thanks

                        Ruvan