0

So I was able to grab the width, hight, X, and y value of a frame in Figma. However, Google App Script is asking for start and the end of the the index of the shape in Google App script. how do I manipulate the values of X and Y to get the start and end of the the index I'm not even sure what the start and the end of the box is and how to find it.

How do I work with these the width and the height variables to find the start and end value of a shape in Google App Script

I am using Figma API and Google App Script My end goal is to make Ann exporter from Figma to Google Slides

JSON File

absoluteBoundingBox: {
                  x: -460,
                  y: -333,
                  width: 586,
                  height: 586
                },

Google App Script

   var frameJSON.x = {};
   var frameJSON.y = {};
   var frameJSON.width = {};
   var frameJSON.height = {};



var subRange = textRange.getRange();
    Logger.log(
      "Sub-range Start: " +
        subRange.getStartIndex() +
        "; Sub-range End: " +
        subRange.getEndIndex() +
        "; Sub-range Content: " +
        subRange.asString()
    );
  • What do you want o achieve? Why are you using [textRange.getRange](https://developers.google.com/apps-script/reference/slides/text-range#getrangestartoffset,-endoffset) to deal with shapes? This is meant for text. – ZektorH Nov 18 '19 at 09:10
  • @ZektorH I need to create a shape and then put the text in the shape. – Zachary Blumstein Nov 18 '19 at 16:19

1 Answers1

1

When you insert a shape with SlidesApp you can getText to retrieve the TextRange object in it.

You can then manipulate this object to insert the text you want into your shape.

Here is some sample code:

function insertShapeWithText() {
  //sample shape data  
  var x = 300;
  var y = 250;
  var width = 100;
  var height = 3000;
  var text = "Bla bla bla";

  var pre = SlidesApp.getActivePresentation();
  var slide = pre.getSlides()[0];
  var shape = slide.insertShape(SlidesApp.ShapeType.DIAMOND, x, y, width, height);
  shape.getText().setText(text);
}
ZektorH
  • 2,680
  • 1
  • 7
  • 20