8 Replies Latest reply on Feb 9, 2015 4:16 AM by Dirk Becker

    Can I export objects without border?

    Stamm Level 1

      Hey guys,

       

      I'm writing on a xml export script. I sadly can't use the "export images" function of xml, as I have two different types. For some "<graphic-area>"s I need the original images and for some I need the formatted ones. So I'm exporting object or object.graphics depending on what I need in either case. Now the question is, how can I export object without the border? So that I only have the perfect sized image.

       

      A workaround would be to duplicate the object, save the visible Bounds with the border, make the border to "0", and calculate the difference. Then I could shrink the frame to the size I need and export this object.

       

      I feel this is a little strange and think there could be a known function which makes this easier. Is there, or do I have to write my own function?

       

      Best regards

       

      Fred

        • 1. Re: Can I export objects without border?
          pixxxel schubser Level 5

          This is the difference between visibleBounds and geometricBounds.

           

          • 2. Re: Can I export objects without border?
            Stamm Level 1

            Hey, not really. geometricBounds for example is the same output as visibleBounds, when the border is inside. When it is on the middle, then geometricBounds is 1/2 border + object. When it is on the outside, your assumption is right. Then visibleBounds are = object+border and geometricBounds is only the object itself. I don't see how this could be a solution to the question, though.

            • 3. Re: Can I export objects without border?
              pixxxel schubser Level 5

               

              Perhaps I understood you totally wrong.

              Stamm schrieb:

               

              … save the visible Bounds with the border, make the border to "0", and calculate the difference …

              Fact:

              make the border to "0" ---> visibleBounds === geometricBounds

              Also

              If item.strokeWidth > 0 then you only have to calculate the visibleBounds (width & heigth) minus strokeWidth

              • 4. Re: Can I export objects without border?
                Stamm Level 1

                I will try to make my point clear using some screenshots:

                 

                Screen Shot 2015-02-05 at 12.32.45.png

                 

                Screen Shot 2015-02-05 at 12.32.52.png

                 

                As you can see, if I would export the lower picture without a border, the image would not be what you see in the first picture, as the border covered a part of the picture. This is why I need to resize the frame to the size visibleBounds-border to make it the same look as it was with the border. I hope you understand now what I mean

                • 5. Re: Can I export objects without border?
                  Stamm Level 1

                  I just wrote my own function now. Note that I need 'MM' for my stroke, this is why I calculate stroke * 0.35277... Maybe this will help somebody.

                   

                  function tagImagesV2(object) {

                          myDup = object.duplicate();

                          strokeWidth = object.strokeWeight*0.352777778;

                          alignment = object.strokeAlignment;

                          myDup.strokeWeight = 0;

                          if(alignment.toString() == 'CENTER_ALIGNMENT')

                              difference = strokeWidth/2;

                          else if(alignment.toString() == 'INSIDE_ALIGNMENT')

                              difference = strokeWidth;

                          else if(alignment.toString() == 'OUTSIDE_ALIGNMENT')

                              difference = 0;

                          myDup.geometricBounds = [myDup.geometricBounds[0] + difference, myDup.geometricBounds[1] + difference, myDup.geometricBounds[2] - difference , myDup.geometricBounds[3] - difference ];

                          //your xml stuff here

                          myDup.remove();

                  }

                  • 6. Re: Can I export objects without border?
                    Dirk Becker Level 4

                    IMO the best approach to deal with conversions is to avoid them - it helps to prevent rounding errors. InDesign uses points internally, so I prefer to keep computations in points by adjusting the measurement units at least during script execution.

                     

                    If you have a stubborn company policy that insists to use metrics all over the place for consistency sake (I once had such a client), there is also the class UnitValue.

                     

                    UnitValue(100/0.352777778,"pt").as("mm")

                    Ergebnis: 99.9999999370079

                    • 7. Re: Can I export objects without border?
                      Stamm Level 1

                      Yeah, we have to use mm for everything. Even for font size/line-height. Would you tell me where the difference between calculating "pt*0.352..." and using "UnitValue" is? Is UnitValue more accurate?

                      • 8. Re: Can I export objects without border?
                        Dirk Becker Level 4

                        I can feel your pain, that's even worse than my case. People that have no clue but all decision powers.

                         

                        UnitValue is the officially supported way to do the conversions, and it yields a slightly different value for your quoted factor. On the other hand, it is an ExtendScript artifact, not connected to InDesign's own measurement units.

                         

                        As you can see here, at InDesign's C++ receiving side for all scripting engines you can in theory pass values bound to a unit. The link is for CS1, but principles have not changed. In practice I haven't ever seen that used, ExtendScript always passes an int or real. For completeness sake I just tried in CS6 to assign a UnitValue straight to the selection's pointSize and still got an error "Expected Unit, but received nothing"; the value passed to InDesign indeed is s_empty. Probably somebody forgot the final code lines.