Reputation: 29
I store in a Google Sheets table some data about quotes, which I inject in a Google Slides (duplicate of a template).
My script works replacing the placeholders with the cell content and injecting the images from the URLs. However, I get an error message that breaks the rest of the script.
function createSlide_(currentAppName) {
let presentation = SlidesApp.openByUrl('https://docs.google.com/presentation/d/###/edit');
let templateSlide = presentation.getSlideById('###');
let newSlide = templateSlide.duplicate();
newSlide.setSkipped(false);
newSlide.replaceAllText('{{AppName}}',currentAppName[0]);
newSlide.replaceAllText('{{Company}}',currentAppName[1]);
newSlide.replaceAllText('{{Founder}}',currentAppName[2]);
newSlide.replaceAllText('{{Designation}}',currentAppName[3]);
newSlide.replaceAllText('{{quote}}',currentAppName[4]);
newSlide.getShapes().forEach(s => {
if (s.getText().asString().trim() == "{{AppImage}}") s.replaceWithImage(DriveApp.getFileById(currentAppName[5].match(/[-\w]{25,}/)).getBlob());
if (s.getText().asString().trim() == "{{FounderImage}}") s.replaceWithImage(DriveApp.getFileById(currentAppName[6].match(/[-\w]{25,}/)).getBlob());
});
};
Exception: Page element is not of type shape.
var shapes = newSlide.getShapes()
, check that it exists and then iterate if typeof shapes !== 'undefined'
and shapes.length > 0
.getPageElements
method - the script does not work.Any idea please?
Upvotes: 0
Views: 582
Reputation: 8596
Not know exactly what is failing in you script I created a simple example. Try this and see what you template consists of. I have a simple slide with just one text box.
function test() {
try {
let presentation = SlidesApp.getActivePresentation();
let slides = presentation.getSlides();
slides.forEach( slide => console.log(slide.getObjectId()) );
let template = presentation.getSlideById("p");
let slide = template.duplicate();
slide.replaceAllText("{{hello}}","goodbye");
let elements = slide.getPageElements();
elements.forEach( element => console.log(element.getPageElementType().toString()))
}
catch(err) {
console.log(err)
}
}
Execution log
3:52:46 PM Notice Execution started
3:52:47 PM Info p
3:52:47 PM Info SHAPE
3:52:47 PM Notice Execution completed
Upvotes: 1