4 Replies Latest reply on May 5, 2014 3:27 AM by Sebbomatico

    Set a XML-attribute of a selected Object

    Sebbomatico Level 1

      Hi Everybody,

       

      I'm new here and I want to start with a question I can find no anwser to.

      I want to select an Object in my document and get the coordinates and the geometricBounds of it and the write it down as XML-Attributes so I can export them afterwards.

      Here is what I got so far:

       

      var meinObjekt    = app.selection[0];

      var ycoords = meinObjekt.geometricBounds[0];

      app.activeDocument.xmlElements.item(0).xmlAttributes.add ("Y-Koordinate", ycoords);

       

       

      The problem is, that ycoords is a variable and not a string. But he expect a string for this value.

      How can I get ycoords as a string?

       

      Maybe someone can help me with a further problem. In the next step I want to automate this process as following. The designer places every box inside InDesign. When he is finished he should just run the Script and the script should write down all attributes of all Object in the document.

      Is this possible?

       

      Thanks in advance

      Sebastian

        • 1. Re: Set a XML-attribute of a selected Object
          csm_phil Level 4

          Hi sebbomatico,

           

          I just modified your js code,  .toString()

           

          var meinObjekt= app.selection[0];

          var ycoords = (meinObjekt.geometricBounds[0]);

          app.activeDocument.xmlElements.item(0).xmlAttributes.add ("Y-Koordinate", ycoords.toString());

           

           

           

          thx,

          csm_phil

          • 2. Re: Set a XML-attribute of a selected Object
            Sebbomatico Level 1

            Hi csm_phil,

             

            thanks for your very fast reply and for your help!

            • 3. Re: Set a XML-attribute of a selected Object
              csm_phil Level 4

              Hi sebbomatico,

               

              Please always follow whenever you post any request in the forum. You have to check and click the the "correct answer"  or "helpful answer" because the thread is still opening, so most of the person and look into your post. that is waste of time you got the solution. If you select the any one options, somebody not look into your post.

               

              Please select any one of the options!

               

              thx,

              csm_phil

              • 4. Re: Set a XML-attribute of a selected Object
                Sebbomatico Level 1

                Hi people,

                 

                thanks to csm_phil I can write down the XML-Attributes of the selected Object. Now I want that the the script deselect the first object and jump to the next one and write down the XML-attributes automaticly until no further objects were found.

                 

                here is what i got so far:

                 

                var elements = i;

                var i = 1;

                 

                if (i >= 10, i++) {

                    var myObject     = app.selection[0];

                    var myXMLobject = myObject.associatedXMLElement;

                 

                    var ycoords     = myObject.geometricBounds[0];

                    var xcoords     = myObject.geometricBounds[1];

                    var width         = myObject.geometricBounds[2] - myObject.geometricBounds[0]);

                    var height         = myObject.geometricBounds[2] - myObject.geometricBounds[0]);

                 

                    myXMLobject.xmlAttributes.add ("Y-Koordinate", ycoords.toString() + " px");

                    myXMLobject.xmlAttributes.add ("X-Koordinate", xcoords.toString() + " px");

                    myXMLobject.xmlAttributes.add ("Width", width.toString() + " px");

                    myXMLobject.xmlAttributes.add ("Height", height.toString() + " px");

                } else {

                    alert("No Objekts found");

                }

                 

                But how can I deselect the first object and jump to the next one?