I believe your goal as follows.
- You want to convert your script using Google Slides API to the script using Slides Service without using Slides API.
- From
How do I get the same result using google Script, not with the Google Script API., I understood that Google Script API you are thinking might be meaning Google Slides API. By this, I thought your goal like above.
In this case, I thought that the method of replaceWithImage can be used. When this method is used, the script becomes as follows.
Sample script:
Please copy and paste the following script to the script editor of the Google Slides. And, please run the function of myFunction.
function myFunction() {
var searchText = "{{CENTERED_SHAPE}}";
var imageUrl = "https://docs.google.com/drawings/d/e/2PACX-1vR5mi6ujksb_2WtTFmk39IPYBIBlJ6WkzM1nsys9cT4Wquik627DDIRXzoYTgHPKX3fcvJzG9inDmJt/pub?w=960&h=720";
// 1. Retrieve 1st slide.
var presentation = SlidesApp.getActivePresentation();
var slide = presentation.getSlides()[0];
// 2. Replace the shape which has the text of "searchText" with the image of "imageUrl".
slide.getShapes().forEach(s => {
if (s.getText().asString().toLocaleUpperCase().includes(searchText.toLocaleUpperCase())) {
s.replaceWithImage(imageUrl);
}
});
}
- In your script,
"matchCase": false is used. At above script, I used if (s.getText().asString().toLocaleUpperCase().includes(searchText.toLocaleUpperCase())) { for this. When you want to use "matchCase": true, please modify it to if (s.getText().asString().includes(searchText)) {.
- And, if you want to replace the shape which has only the text of
{{CENTERED_SHAPE}} with the image, please modify it to if (s.getText().asString().trim() == searchText) {.
Reference: