How to use the AutoText class in Google slides API?

Hi everybody,

How to use the AutoText class in Google slides API? That's the question ? I don't find any code example ? Has anyone ever used this class and how ? Thanks

I would like to add 2 autotext on each slide of a presentation
If N is the number of a slide

  • First Autotext : 2N-1
  • Second Autotext : 2N

I would like to number a presentation like a book with 2 page numbers !

Solved Solved
1 6 982
1 ACCEPTED SOLUTION

Hi Eric, 

The autoText feature is not meant for you to place value on the textbox but to read from where the autotext is coming from, as an example:

1- You start a slide and then add the slide number

2- You read the slides and then select the text box 

3- Extract the text box text and then you can read the value of where the auto text is coming from

 
function myFunction() {
 var slide = SlidesApp.getActivePresentation().getSlides()[1];
 var items = slide.getShapes();
  Logger.log(items[0].getText());
  Logger.log(items[0].getText().getAutoTextType);
  Logger.log(items[0].getText().getIndex);
  Logger.log(items[0].getText().getRange);
}
 
On the desire outcome that you have I guess that it would be better to place two separate counters and use that to increment the text and inserted into a text box. Hope that it helps 

 

View solution in original post

6 REPLIES 6

Eric, did you ever figure this out?

 

To be honest, I couldn't find any information explaining how to use the AutoText class.

I wanted to try displaying 2 page numbers on 1 slide. But I don't know how to do it

Hi Eric, 

The autoText feature is not meant for you to place value on the textbox but to read from where the autotext is coming from, as an example:

1- You start a slide and then add the slide number

2- You read the slides and then select the text box 

3- Extract the text box text and then you can read the value of where the auto text is coming from

 
function myFunction() {
 var slide = SlidesApp.getActivePresentation().getSlides()[1];
 var items = slide.getShapes();
  Logger.log(items[0].getText());
  Logger.log(items[0].getText().getAutoTextType);
  Logger.log(items[0].getText().getIndex);
  Logger.log(items[0].getText().getRange);
}
 
On the desire outcome that you have I guess that it would be better to place two separate counters and use that to increment the text and inserted into a text box. Hope that it helps 

 

Hi Sergio,

Now I understand. This is useful for reading Autotext.
It does not allow AutoText fields to be added dynamically.

Thanks

To use the AutoText class in the Google Slides API, you can follow these steps:

  1. First, authenticate and authorize your application to access the Google Slides API using OAuth 2.0.
  2. Create a new presentation or open an existing one using the Google Slides API.
  3. Retrieve the desired slide where you want to add the AutoText.
  4. Define the AutoText object by specifying the content and properties you want to include. For example, if you want to add "Watco Delivery Information" as AutoText, you would set the text property of the AutoText object to delivery.
  5. Determine the position or location on the slide where you want to insert the AutoText. This can be specified using coordinates or slide layout properties.
  6. Add the AutoText object to the desired slide using the slides().presentations().batchUpdate() method. Include the AutoText object in the createSlide() or createShape() request, depending on your preferred placement method.
  7. Execute the batch update request to apply the changes to the slide.

By following these steps and customizing the content and properties of the AutoText object, such as adding "Watco Delivery Information" as the text, you can use the AutoText class in the Google Slides API to programmatically insert and manage AutoText elements within your slides.

Hi,
I don't understand the purpose of putting "Watco Delivery Information" in AutoText. 

If I want to add text, I use a Shape object with text inside! 

Top Labels in this Space
Top Solution Authors