8 Replies Latest reply on May 7, 2012 6:41 AM by Pooja_IDDev

    How can I find the left edge of a column

    TᴀW Adobe Community Professional & MVP

      Given a textColumn, how can I know what it's lefttmost edge is? That is, I would like to know the column's horizontal offset from the textFrame or the page. Is there any way of knowing this?

       

      Thanks,

      Ariel

        • 1. Re: How can I find the left edge of a column
          Peter Kahrel Adobe Community Professional & MVP

          Maybe this:

           

          leftEdge = textColumn.lines[0].insertionPoints[0].horizontalOffset;

           

          The left side of the column's text frame you get with this line:

           

          left = textColumn.parentTextFrames[0].geometricBounds[1];

           

          and then you substract one from the other (haven't tried it).

           

          Peter

          • 2. Re: How can I find the left edge of a column
            TᴀW Adobe Community Professional & MVP

            Hi Peter,

             

            It doesn't work if the first line of the column has a paragraph indent,

            is centre- or right-aligned, or has otherwise been altered.

             

            Ariel

            • 3. Re: How can I find the left edge of a column
              Olav Martin Kvern Level 3

              Hi Ariel, Peter,

               

              For an untransformed, rectangular text frame, you can try something like this:

               

              //Where textColumn is a reference to a text column...

              function findLeftEdge(textColumn){
                  var textFrame = textColumn.parentTextFrames[0];
                  var leftEdge = textFrame.geometricBounds[1];
                  var leftIndent = textFrame.textFramePreferences.insetSpacing;
                  var textColumnIndex = findTextColumnIndex(textColumn);
                  if(leftIndent.length == 1){
                      leftIndent = leftIndent[0];
                  }
                  else{
                      leftIndent = leftIndent[1];
                  }
                  var numberOfColumns = textFrame.textFramePreferences.textColumnCount;
                  var spaceBetweenColumns = textFrame.textFramePreferences.textColumnGutter;
                  var textFrameWidth = textFrame.geometricBounds[3] - textFrame.geometricBounds[1];
                  var textColumnWidth = textFrame.textFramePreferences.textColumnFixedWidth;
                  leftEdge = leftEdge + (textColumnIndex * spaceBetweenColumns) + (textColumnWidth * textColumnIndex);
                  return leftEdge;
              }
              function findTextColumnIndex(textColumn){
                  var result = 0;
                  var textFrame = textColumn.parentTextFrames[0];
                  for(var counter = 0; counter < textFrame.textColumns.length; counter++){
                      //The index of the text column is actually the
                      //index of the first character in the text column.
                      if(textFrame.textColumns.item(counter).index == textColumn.index){
                          result = counter;
                          break;
                      }
                  }
                  return result;
              }

               

              Thanks,

               

              Ole

              • 4. Re: How can I find the left edge of a column
                TᴀW Adobe Community Professional & MVP

                Hi Ole,

                 

                Thanks for this. (I would just comment for the benefit of anyone who

                hasn't looked up the insetSpacing property recently, that if the inset

                is equal on all sides, it returns a single number, but if it's

                different, it return 4 numbers; hence the need for that if statment in

                the first function.)

                 

                Does this work also with a CS5 split paragraph?

                 

                I was thinking of another way to do it, and that is to add a temporary

                anchored object to any given textColumn, with settings that are

                "relative to the column." Then take an appropriate x reading from that

                anchored object, and then remove it. Perhaps it's a more solid way,

                also, since we're relying on InDesign's built in way of getting the

                left-edge of a column. For instnace, in Ole's function, what if that

                columns are not fixed width?

                 

                Thanks,

                Ariel

                • 5. Re: How can I find the left edge of a column
                  Olav Martin Kvern Level 3

                  Hi Ariel,

                   

                  re: "Does this work also with a CS5 split paragraph?"

                   

                  I don't know?:-)

                   

                  re: "For instance, in Ole's function, what if the columns are not fixed width?"

                   

                  This will work even if textFramePreferences.useFixedColumnWidth is false--the textFramePreferences.textColumnFixedWidth property always holds the current width of the column (just as in the UI). At one point (CS3?) it didn't do that, but it does now (or seems to, anyway).

                   

                  Thanks,

                   

                  Ole

                  • 6. Re: How can I find the left edge of a column
                    TᴀW Adobe Community Professional & MVP

                    Hi Ole,

                     

                    I'm in the middle of working on something else in CS4, so I'll have to

                    wait to find out about split paragraphs (it's not a good idea to open

                    two versions of indesign at the same time, is it?).

                     

                    You know, I don't use columns much myself, so I thought that you can

                    have uneven columns widths. But I see that you can't. So in that case

                    your function should work perfectly.

                     

                    This is one of those things that you think should be terribly simple,

                    and in the end requires two functions and about 8 variables...

                     

                    Thanks,

                    Ariel

                    • 7. Re: How can I find the left edge of a column
                      TᴀW Adobe Community Professional & MVP

                      Hi Ole,

                       

                      No, it doesn't work with split paragraphs (since textColumnFixedWidth is

                      not applicable for a split paragraph). I suppose you could add a

                      condition for split paragraphs, but then you need to check if you're not

                      in CS4...

                       

                      So, my function to get the left edge of a column (given a textColumn),

                      using anchored objects, for CS4 (I hope) and CS5 (tested) is as follows:

                       

                      function getColumnLeftEdge(myColumn){

                           myChar = myColumn.lines.middleItem().characters.middleItem();

                           myAnchoredObject = myChar.rectangles.add();

                           with(myAnchoredObject.anchoredObjectSettings){

                                   anchorPoint = AnchorPoint.RIGHT_CENTER_ANCHOR;

                                   anchorSpaceAbove = 0;

                                   anchorXoffset = 0;

                                   anchorYoffset = 0;

                                   anchoredPosition = AnchorPosition.ANCHORED;

                                   horizontalAlignment = HorizontalAlignment.LEFT_ALIGN;

                                   horizontalReferencePoint = AnchoredRelativeTo.COLUMN_EDGE;

                                   verticalAlignment = VerticalAlignment.CENTER_ALIGN;

                                   verticalReferencePoint = VerticallyRelativeTo.LINE_BASELINE;

                           }

                           leftEdge = myAnchoredObject.geometricBounds[3];

                           myAnchoredObject.remove();

                           return (leftEdge);

                      }

                      • 8. Re: How can I find the left edge of a column
                        Pooja_IDDev Level 1

                        Hello eveyone

                          

                        function getColumnLeftEdge(myCell){

                          

                            var myAnchoredObject = null;

                            var insertionPt = myCell.insertionPoints[0];

                            myAnchoredObject = insertionPt.rectangles.add();

                            with(myAnchoredObject.anchoredObjectSettings){

                                anchorPoint = AnchorPoint.BOTTOM_RIGHT_ANCHOR;

                                anchorSpaceAbove = 0;

                                anchorXoffset = 0;

                                anchorYoffset = 0;

                                anchoredPosition = AnchorPosition.ANCHORED;

                                horizontalAlignment = HorizontalAlignment.LEFT_ALIGN;

                                horizontalReferencePoint = AnchoredRelativeTo.COLUMN_EDGE;

                                verticalAlignment = VerticalAlignment.TOP_ALIGN;

                                verticalReferencePoint = VerticallyRelativeTo.COLUMN_EDGE;

                            }

                            var topEdge = myAnchoredObject.geometricBounds[2];

                            var leftEdge = myAnchoredObject.geometricBounds[3];

                            myAnchoredObject.remove();

                            return [topEdge, leftEdge];

                        }

                          I tried above code with some modification to get the top and left points of a cell

                        but if there is overset in any cell then i am not able to get the geometricBounds of that myAnchoredObject.

                        please suggest any solution

                         

                        thanks in advace.