3

I have just started playing with Google Slide API. I am able to duplicate object within a file. However, I couldn't do it when I tried copying an object from one file to another. The function will return an error that the objectId is not found. Thank you for helping!

Invalid requests[0].duplicateObject: The object (myObjectId) could not be found.

//read a file
function copyPasteObject() {
  //presentationId if the input
  var presentationId = myPresentationId;
  var presentation = Slides.Presentations.get(presentationId);
  var slides = presentation.slides;
  //getting elements objectId
  Logger.log(slides[0].pageElements[0].objectId);

  var request1 = [{
    duplicateObject: {
      objectId: slides[0].pageElements[0].objectId
    }
  }];

  // Execute the request.
  var createBullet = Slides.Presentations.batchUpdate({
    requests: request1
  }, myTargetPresentationId);
}
Kos
  • 4,890
  • 9
  • 38
  • 42
Rick Chong
  • 33
  • 4

2 Answers2

2

duplicateObject only works with objects in the same presentation. Copying objects across presentations isn't supported just yet-- the feature request to follow is here.

Maurice Codik
  • 598
  • 2
  • 6
1

At February 13, 2018, Slides service was updated. By this, copying objects on slides got to be able to be achieved by the native methods.

This sample script copies a shape object on 1st page of the source slides to the 1st page of the destination slide. When you use this, please modify for your environment.

Sample script :

function myFunction(){
  // source side
  var srcSlide = SlidesApp.getActivePresentation().getSlides()[0];
  var shape = srcSlide.getShapes()[0];

  // destination side
  var dstSlides = SlidesApp.openById("### file ID ###");
  var dstSlide = dstSlides.getSlides()[0];
  dstSlide.insertShape(shape)
}

Reference :

Tanaike
  • 181,128
  • 11
  • 97
  • 165