12 Replies Latest reply on Jan 3, 2011 10:29 AM by Kasyan Servetsky

    Is this a bug?

    thomas rollins

      OK, so I'm trying to add a textframe to a rectangle which was created after placing an image, so then I can create a hyperlinkTextDestination inside the textframe for crossreferences to the image, however, it's just taken me the best part of 4 hours to figure out why lefthand pages were not being linked up. It seems that the boundaries for left pages inside a rectangle are wrong. 0,0 is not the top left of the rectangle, but the top left of the next page. surely this can't be correct?

       

      here's some test code that i've chucked together. after running it, you'll see a small filled textframe in the rectangle on the right, but seemingly no filled textframe on the left. extend the left rectangle to the right, et voila, the textframe appears... on the next page!

       

      cs5

       

      #target indesign
      var doc = app.documents.add();
      var page = doc.pages.add();

       

      doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;
      doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;
      doc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;   // resets 0 to the top left of each page, not each spread
      color = doc.colors.add({name:"Title Colour", model:ColorModel.process, colorValue:[0, 0, 0, 85]});

       

      // place graphic
      var imageGraphic = page.place(File("/c/graphic.jpg"));
      var imageFrame = imageGraphic[0].parent;

       

      var tf = imageFrame.textFrames.add();
      tf.contents = " ";
      tf.geometricBounds = [ 0,0,1,1 ];     // top left 1" square...
      tf.fillColor = doc.colors.item("Title Colour");

       

      imageGraphic[0].remove();

       

      // place graphic
      var page = doc.pages.add();
      var imageGraphic = page.place(File("/c/graphic.jpg"));
      var imageFrame = imageGraphic[0].parent;

       

      var tf = imageFrame.textFrames.add();
      tf.contents = " ";
      tf.geometricBounds = [ 0,0,1,1 ];     // top left 1" square...
      tf.fillColor = doc.colors.item("Title Colour");  

       

      imageGraphic[0].remove();

       

      what's going wrong? is it a bug?         

        • 1. Re: Is this a bug?
          thomas rollins Level 1

          may as well add, for now, a solution if you're using doc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;  would be something like:

           

          // use negative values on left page

          if (page.side == PageSideOptions.leftHand){
              tf.geometricBounds = [ 0, -doc.documentPreferences.pageWidth, 1, -doc.documentPreferences.pageWidth + 1 ];
          }
          else{
            tf.geometricBounds = [ 0, 0, 1, 1 ] 
          }

           

          i think you can simply swap "leftHand" to rightHand if you're not using rulerOrigin

          • 2. Re: Is this a bug?
            thomas rollins Level 1

            opps, double post


            • 3. Re: Is this a bug?
              Kasyan Servetsky Level 5

              Hi Thomas,

               

              I see you misunderstood my idea about creating x-ref destination "inside" graphic frame. Here's a very simple example illustrating it. I'm on CS3 at the moment so can't create x-refs.

               

              Kasyan

               

              var doc = app.activeDocument;
              var imageGraphic = doc.pages[0].place(File("/c/graphic.jpg"));
              var imageFrame = imageGraphic[0].parent;
              var tf = imageFrame.textFrames.add({geometricBounds:imageFrame.geometricBounds, fillColor:doc.swatches[0], strokeColor:doc.swatches[0]});
              tf.contents = "Hyperlink Text Destination goes here";
              
              • 4. Re: Is this a bug?
                Harbs. Level 6

                I wrote this script about a year ago in response to a request on the forum...

                 

                var name  = prompt("Pick a name","","Create anchor in graphic frame");
                if(name){
                    makeObjectAnchor(app.selection[0],name);
                }
                function makeObjectAnchor(object,destinationName){
                    var tf = object.textFrames.add();
                    app.documents[0].hyperlinkTextDestinations.add(tf.parentStory.insertionPoints[0],{name:destinationName});
                }

                 

                Harbs

                • 5. Re: Is this a bug?
                  thomas rollins Level 1

                  i understand about setting the geometric bounds to that of the  containing rectangle, however, when i run that, the text appears not  behind the graphic (as it's on a left page), but outside the rectangle  on the right, and i have to extend the rectangle to the right to see the  text.

                   

                  is it just me?

                  Kasyan Servetsky wrote:

                   

                  Hi Thomas,

                   

                  I see you misunderstood my idea about creating x-ref destination "inside" graphic frame. Here's a very simple example illustrating it. I'm on CS3 at the moment so can't create x-refs.

                   

                  Kasyan

                   

                  var doc = app.activeDocument;
                  var imageGraphic = doc.pages[0].place(File("/c/graphic.jpg"));
                  var imageFrame = imageGraphic[0].parent;
                  var tf = imageFrame.textFrames.add({geometricBounds:imageFrame.geometricBounds, fillColor:doc.swatches[0], strokeColor:doc.swatches[0]});
                  tf.contents = "Hyperlink Text Destination goes here";
                  
                  • 6. Re: Is this a bug?
                    Harbs. Level 6

                    Any bounds property is relative to the zeroPoint which is usually the top left of the page.

                     

                    Harbs

                    • 7. Re: Is this a bug?
                      thomas rollins Level 1

                      Harbs. wrote:

                       

                      Any bounds property is relative to the zeroPoint which is usually the top left of the page.

                       

                      Harbs

                       

                      exactly, but for me it seems that it's relative to the righthand page, not the page it's on when inside a rectangle

                      • 8. Re: Is this a bug?
                        Harbs. Level 6

                        Right hand? Is this a right-to-left document? You probably have rulers per spread.

                         

                        Or, the frame might cross the spine...

                         

                        Harbs

                        • 9. Re: Is this a bug?
                          thomas rollins Level 1

                          I have the rulers set to my example code and nope, no crossing of the spine, only to see the new textframe that's been added.

                          • 10. Re: Is this a bug?
                            Harbs. Level 6

                            Try using speadOrigin, and use the bounds of the graphic parent as the starting point...

                             

                            Harbs

                            • 11. Re: Is this a bug?
                              thomas rollins Level 1

                              can someone confirm that the example in my first post doesn't put a filled textframe in the rectangle on the left page?


                              • 12. Re: Is this a bug?
                                Kasyan Servetsky Level 5

                                i understand about setting the geometric bounds to that of the  containing rectangle, however, when i run that, the text appears not  behind the graphic (as it's on a left page), but outside the rectangle  on the right, and i have to extend the rectangle to the right to see the  text.

                                 

                                is it just me?

                                It works for me with Ruler Units > Origin set to Spread.

                                Suggestion: let's remember the original setting at the start of the script

                                var doc = app.activeDocument;
                                var rulerOrigin = doc.viewPreferences.rulerOrigin;

                                set it to Spread

                                doc.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;

                                and restore the remembered setting at the end.

                                doc.viewPreferences.rulerOrigin = rulerOrigin;
                                

                                 

                                Kasyan