5

I am trying to append a new slide to my presentation with a created layout via Google Apps Scripts.

I started a new presentation, created two new layouts, named them as 'BulletDescription' and 'TextDescription'. I can get all the layouts available in the presentation. However, I can't find the layouts which I manually created by their names.

function AddNewSlideToPresentation(LayoutType) //LayoutType = 'BulletDescription'
{ 
  var presentation = SlidesApp.openById('PresentationID');
  var layouts = presentation.getLayouts();
  var selectedLayout;
  for(var item in layouts)
  {
    Logger.log(layouts[item].getLayoutName());
    if(layouts[item].getLayoutName() == LayoutType)
    {
      selectedLayout = layouts[item];
    }
  }

  var newSlide = presentation.appendSlide(selectedLayout); // this returns an error
}

It seems that .getLayoutName() function gives us different name as I found on my log;

TITLE
SECTION_HEADER
TITLE_AND_BODY
MAIN_POINT
.
.
CUSTOM_1
CUSTOM_2

I believe CUSTOM_1 and CUSTOM_2 are the ones I created. Is there a way to get display name of the layout via Google Apps Script?

iJay
  • 4,205
  • 5
  • 35
  • 63
  • 1
    Did you ever find a solution to this? Bumping my head against the same issue (nearly 2 years later!). – zimady Oct 03 '19 at 12:40
  • https://stackoverflow.com/questions/47386726/how-to-add-a-new-slide-with-new-layout-on-google-slides has good discussion of layout names – aNewb Apr 06 '21 at 01:02

1 Answers1

0

Try this to get layout name from LayoutProperties:

if (layouts[item].layoutProperties.displayName == LayoutType)
{
    // found needed layout..
}
Kos
  • 4,890
  • 9
  • 38
  • 42