1

I am trying to freeze the shape color in google slide. So, if the user changes the theme, the shape color should not change. I understand google sheet support Theme and RGB type. I am using below snippet to fix the RGB color.

if (pageElements[j].getPageElementType() == "SHAPE") {
        var fill = pageElements[j].asShape().getFill().getSolidFill().getColor();
        var colorType = fill.getColorType();

        Logger.log(colorType)
        if (colorType == "RGB") {
          shapeColor = fill.asRgbColor().asHexString();
          Logger.log(shapeColor)
          pageElements[j].asShape().getFill().setSolidFill(shapeColor)
        }
        else if (colorType == "THEME") {
          shapeColor = fill.asThemeColor().getThemeColorType();
          Logger.log(shapeColor)

pageElements[j].asShape().getFill().setSolidFill(shapeColor)
        }
      }

Is there a way we can set/fix the theme color of the shape Google Slide Documentation

1 Answers1

0

You can use getConcreteColor() to get the RGB color based on the theme that is currently selected.

Try this:

else if (colorType == "THEME") {
  shapeColor = fill.asThemeColor().getThemeColorType();
  // Using the theme in the slide that contains the shape:
  shapeColor = pageElements[j].getParentPage().getColorScheme().getConcreteColor(shapeColor).asRgbColor().asHexString();

  // Using the theme of a specific slide previously stored in a ${slide} variable
  // shapeColor = slide.getColorScheme().getConcreteColor(shapeColor).asRgbColor().asHexString();

  Logger.log(shapeColor);
  pageElements[j].asShape().getFill().setSolidFill(shapeColor)
}

Reference:

Bryan Monterrosa
  • 1,385
  • 1
  • 3
  • 13