2 Replies Latest reply on Jun 5, 2013 3:36 AM by Laubender

    How to put a frame into a table cell?

    michaelfielitz

      Hello,

       

      I just want to paste a simple text frame (which is actually a button) into a specific column/row.

      Here is my code so far:

       

           var myTextFrame = doc.textFrames.add();

           app.cut();

           var myCell = myTable.columns.item(0).cells.item(0);

           app.pasteInto(myCell);

       

      I guess it is not the cell itself, but the insertionPoint that needs to be set as target, but I have no idea how to do this right.

        • 1. Re: How to put a frame into a table cell?
          michaelfielitz Level 1

          Hello again!

           

          I found out the answer myself ten minutes after my last post.

          Here is the solution:

           

               var myCell = table.columns.item(2).cells.item(index + 1);

               myCell.contents = "axaio software";

               templateDoc.selection = myCell.characters.itemByRange(0,-1).getElements()[0];

               app.paste();

           

          The supplied dummy text will be deleted.

          • 2. Re: How to put a frame into a table cell?
            Laubender Adobe Community Professional & MVP

            @Michael – your approach does not work, because app.cut() ( or app.pasteInto() )can only act on selected page items.
            If you just add a new text frame to page 1 of your document, the text frame will not be selected. Furthermore you cannot paste into something into a cell. Instead we paste an object to a selected insertion point.

             

            So let's expand your code a bit:

             

            //There are better ways for doing this, but for "educational" purposes, let's do it:
            
            var myTextFrame = doc.textFrames.add();
            app.select(myTextFrame);
            app.cut();
            var myCell = myTable.columns.item(0).cells.item(0);
            app.select(myCell.insertionPoints.item(0));
            app.paste(); //Pastes whatever is cut before
            //app.pasteInto() is for addressing geometric objects like rectangles, NOT text objects like insertion points!
            

             

            Here is a one liner to show you another way for the same task:

             

            //Easier: just add the text frame directly to the cell
            
            //columns[0] is the same as: columns.item(0), just different notation
            //but item(0) could be used to indicate that the object is a member of a collection opposed to an array
            
            //And when we are at it, we could give the new text frame
            //immediately a value for its fillColor property (amongst others):
            var myTextFrame = myTable.columns[0].cells[0].insertionPoints[0].textFrames.add({fillColor:"Yellow"});
            

             

            Ok. Then let's go on to your existing button, that you wish to move to the cell.

            Usually the move() method will move objects around, but unfortunately when it comes to Button objects (same goes for others) move() is restricted. Buttons cannot be moved to  Text objects (an insertion point is such a thing).

             

            So we have to go the select() [Button] => cut() => select() [InsertionPoint] => pasteInto() route… //EDIT !!

             

            Uwe

             

            Message was edited by: Laubender Seeing now answer #1, why did I post all this? ;-) Have fun!!

             

            Message was edited by: Laubender