2

I know how to add a shape to a slide, but I know in Google Slides you are able to link another slide to display once you click on that text box. Is it possible to in App Script create a shape and then attach a link to it?

I have looked at the API documentation and was confused as to if it was possible.

This is a Sheets/Slides Add-On.

What I need to do is when a button is pressed on my Add On menu that I created, is to create a Slide in Google Slides, and use the information from a Sheets. I want to create a TextBox, and have when you click it link to another slide in the Slide Show. I just want it all automated.

If it is possible, how do I apply it to a shape I created?

var elementId = 'MyTextBox_001';
  var pt350 = {
    magnitude: 350,
    unit: 'PT'
  };
  var requests = [{
    createShape: {
      objectId: elementId,
      // tried linkUrl: "link";
      shapeType: 'TEXT_BOX',
      elementProperties: {
        pageObjectId: "slide_001_001",

        size: {
          height: pt350,
          width: pt350
        },
        transform: {
          scaleX: 1,
          scaleY: 1,
          translateX: 350,
          translateY: 100,
          unit: 'PT'
        }
      }
    }
  },

// Insert text into the box, using the supplied element ID.
{
   insertText: {
     objectId: elementId,
     // tried linkUrl: "link";
     insertionIndex: 0,
     text: SpreadsheetApp.getActiveSheet().getRange(3,2).getValue()
    }
 }];

// have tried elementId.setLinkUrl(linkHere);
Rubén
  • 34,714
  • 9
  • 70
  • 166
Corie LeClair
  • 51
  • 1
  • 9
  • 1
    The code isn't complete and the question hasn't enough details. You are using a project bounded to a spreadsheet, right? Which the shape to add the link? What did you tried so far? – Rubén Oct 06 '19 at 01:57
  • ! ! ! ! ! ! ! See - Star - Comment in Issue tracker! ! ! ! ! ! ! "Page elements on Slides should be selectable to run scripts like the shapes and images in spreadsheet" https://issuetracker.google.com/issues/186214943 "Presentation mode in slides should fill window not device" https://issuetracker.google.com/issues/186204484 – aNewb Apr 24 '21 at 23:46

2 Answers2

2

You can create a slide, add a shape and add a link to it using the following code:

  var presentationId =  "<YOUR_PRESENTATION_ID>";
  var newSlideId = Utilities.getUuid();
  var newElementId = Utilities.getUuid();
  var pt350 = {
    magnitude: 350,
    unit: 'PT'
  };
  var requests = [
    {
      createSlide: {
        objectId: newSlideId
      }
    },
    {
      createShape: {
        objectId: newElementId,
        shapeType: 'TEXT_BOX',
        elementProperties: {
          pageObjectId: newSlideId,
          size: {
            height: pt350,
            width: pt350
          },
          transform: {
            scaleX: 1,
            scaleY: 1,
            translateX: 350,
            translateY: 100,
            unit: 'PT'
          }
        }
      }
    },
    {
      insertText: {
        objectId: newElementId,
        insertionIndex: 0,
        text: SpreadsheetApp.getActiveSheet().getRange(3,2).getValue()
      }
    },
    {
      updateShapeProperties: {
        objectId: newElementId,
        shapeProperties: {
          link: {
            pageObjectId: "<YOUR_PAGE_ID>"
          }
        },
        fields: "link"
      }
    }];

Note that you will need your presentation's id and the destination page's id. If you prefer, you can use a slide index as a destination (more information here).

In case you need more help creating a slides add-on, you can visit this example.

If you have any other question regarding this topic, please don't hesitate to reach back.

Regards

carlesgg97
  • 4,184
  • 1
  • 8
  • 24
1

Yes, it's possible. Checkout Extending Google Slides and shape.setLinkUrl(url)

Rubén
  • 34,714
  • 9
  • 70
  • 166