0
votes

I have defined the google slides presentation and the specific slide therein.

var MainSlideSheet = SlidesApp.openByUrl('xxxxxxx');
var Slide1 = MainSlideSheet.getSlides()[0];

Now for every shape/ element within that slide, I want to know its index number. How could this be done in Apps Script?

1

1 Answers

0
votes
  • You can get all the page elements with the getPageElements() function:

    var elements = Slide1.getPageElements();
    
  • To get the object ID of every element in your slide you can use the getObjectId() method inside a forEach loop. Using the latter, you can define an index which will provide the position of the element in the array.

The following code will log the object ID of every element and its index of the first slide:

function myFunction() {
  var MainSlideSheet = SlidesApp.openByUrl('xxxxxxx');
  var Slide1 = MainSlideSheet.getSlides()[0];
  
  var elements = Slide1.getPageElements();
  elements.forEach(
    (el,index)=>
    Logger.log(el.getObjectId(),index)
    // here goes the code that uses el.getObjectId() and/or index
  )
}