3 Replies Latest reply on Sep 25, 2008 2:38 AM by Loic.Aigon

    How to set the size of rectangle in a table cell?

      Hi:
      I want to place an image in the table cell, so I add a rectangle in the table cell, but I don't know how to set the size of the rectangle, any help?
      var oInsertionPoints = oCell.insertionPoints
      var oRect = oInsertionPoints.item(-1).rectangles.add()
      oRect.place(File(myGraphic))
      oRect.fit(FitOptions.contentToFrame)

      Thanks
        • 1. Re: How to set the size of rectangle in a table cell?
          Loic.Aigon Adobe Community Professional
          //Assuming oCell is the parent cell of your insertion point.
          var w = oCell.width;
          var wli = oCell.leftInset;
          var wri = oCell.rightInset;
          var ti = oCell.topInset;
          var bi = oCell.bottomInset;
          var h = oCell.height;
          var rectheight = h-(bi+ti);
          var rectwidth = w - (wli+wri);
          var oInsertionPoints = oCell.insertionPoints
          var oRect = oInsertionPoints.item(-1).rectangles.add({geometricBounds:[0, 0,rectheight,rectwidth]});
          Loic
          • 2. Re: How to set the size of rectangle in a table cell?
            Level 1
            Thanks Loic, it works fine
            but I want to add the rectangle to the table's cell in a table cell, when I set the geometricBounds, it said Invalid object for this request, any help?

            var oSubTable = oCell.insertionPoints.item(-1).tables.add()
            oSubTable.bodyRowCount = 5
            oSubTable.columnCount = 3
            var oSubCell = oSubTable.cells.item("2:1")
            var w = oSubCell.width;
            var wli = oSubCell.leftInset;
            var wri = oSubCell.rightInset;
            var ti = oSubCell.topInset;
            var bi = oSubCell.bottomInset;
            var h = oSubCell.height;
            var rectheight = h-(bi+ti);
            var rectwidth = w - (wli+wri);
            var oInsertionPoints = oSubCell.insertionPoints
            var oRect = oInsertionPoints.item(-1).rectangles.add({geometricBounds:[0, 0,rectheight,rectwidth]});

            Thanks
            • 3. Re: How to set the size of rectangle in a table cell?
              Loic.Aigon Adobe Community Professional
              Hi,
              I had a look and don't ask me why but it seems that you can't add extra rectangles in a sub table. But weirdly, it seems possible to add tables.
              I mean you can't add a rectangle using
              app.activeDocument.textframes.tables.tables.cell.insertionpoint.rectangles.add
              //remove any reference, that's conceptual at this time.

              The idea I had at the first place but put aside cause to its heaviness is to cheat.
              Instead of adding the rectangle, we are going to copy & paste it.
              So let's keep all the things you need (rectheight & rectwidth).
              But this time, let's use
              var oRect = app.activeDocument.rectangles.add({geometricBounds:[0,0,rectheight,rectwidth]});
              //You may need to use app.activeDocument.pages[x]... if you have a multi pages doc.
              app.select(oRect);
              app.cut()
              app.select(oInsertionPoints.item(-1));
              app.paste();
              heavy but it works.
              Loic