8

Has anyone found support for creating or changing a drawing using Google Apps Script? I've looked through the Google documentation, but I don't see any classes for drawing. I found out how to build user interface elements, but not drawings.

I'd like to have the drawing as part of a document or spreadsheet, but a stand-alone drawing would be good enough.

Don Kirkby
  • 53,582
  • 27
  • 205
  • 286

3 Answers3

6

It's not possible to do anything related to Google Drawings, embedded on files or not, up until today. The closest thing you have is ability to insert images (via urls), which you can do on spreadsheets and UIs.

You can always ask for this enhancement at the Apps Script issue tracker: http://code.google.com/p/google-apps-script-issues/issues/list

Henrique G. Abreu
  • 17,406
  • 3
  • 56
  • 65
  • OK, I created a [feature request](http://code.google.com/p/google-apps-script-issues/issues/detail?id=1054). – Don Kirkby Jan 26 '12 at 17:56
3

I got an answer on a related question that is good enough to use as a workaround for this question. You may not be able to modify a Google Drawing directly through code, but you can generate a Windows Metafile image and then upload that to a Google Drawing as described on the Google Docs blog.

Until my feature request is completed, this will have to do.

Update

You can now create drawings through the Google Slides API. If you want that in a Google Drawing, Doc, or Sheet, you can copy it there.

Don Kirkby
  • 53,582
  • 27
  • 205
  • 286
  • When you say copy it inside a Doc you mean manually os is it possible to do it with the API? I need to embed a drawing (and link it to the original slide) to a Doc and I am able to modify it with the Slides API but I don't see a way to add it to do it in a programatic way – joseprupi Oct 09 '19 at 15:18
  • I meant to copy it manually, @joseprupi. I don't know if there's any way to do it through the API. – Don Kirkby Oct 09 '19 at 17:26
  • Thanks, @Don Kirby. I posted a separate question about this, [see here](https://stackoverflow.com/questions/58312843/linking-a-google-slide-and-drawing-to-a-google-doc-using-api?noredirect=1#comment102987882_58312843), and from Tanaike's comment it seems is not possible yet. – joseprupi Oct 10 '19 at 12:42
-1

modifying seldom includes a deletion too...

var drawingRange = body.findElement(DocumentApp.ElementType.INLINE_DRAWING);
           while (drawingRange != null) {
               var element = drawingRange.getElement();
               var drawingElement = element.asInlineDrawing();
               drawingElement.removeFromParent();
               drawingRange = body.findElement(DocumentApp.ElementType.INLINE_DRAWING);
           }
user3436029
  • 75
  • 1
  • 2
  • 13