I am attempting to replace shapes color in a Google Slide presentation, using Google Apps Script.
function changeColors() {
const objectId = "#an-id#"; // Please set the object ID.
const slides = SlidesApp.openById(objectId).getSlides();
slides.forEach(loopSlides);
}
function loopSlides(slide){
var shapes = slide.getShapes();
if (shapes.length > 0) {
shapes.forEach(myFunction);
}
}
function myFunction(shape) {
try{
var st = shape.getShapeType();
if (st != SlidesApp.ShapeType["RECTANGLE"] &&
st != SlidesApp.ShapeType["ROUND_RECTANGLE"] &&
st != SlidesApp.ShapeType["UNSUPPORTED"]){
Logger.log("Not a box!!");
Logger.log(st);
Logger.log(shape.getText());
return;
}
}
catch(err) {
Logger.log("Not a Shape!!");
return; // not a shape!
}
var hexColor = shape.getFill().getSolidFill();
Logger.log(hexColor);
switch (hexColor){
case "#f16727ff": // Computer Science
shape.getFill().setSolidFill("#413c73ff");
case "#0b9faeff": // Information technology
shape.getFill().setSolidFill("#d90368ff");
case "#d71b55ff": // Digital Literacy
shape.getFill().setSolidFill("#aa968aff");
}
}
The above code will never run the replacement code (Basically it will never reach the Logger.log(hexColor); instruction
