Skip to content

Instantly share code, notes, and snippets.

@tar-bin
Last active April 30, 2019 00:34
Show Gist options
  • Save tar-bin/b27ad5337fd730867bd533766d93241a to your computer and use it in GitHub Desktop.
Save tar-bin/b27ad5337fd730867bd533766d93241a to your computer and use it in GitHub Desktop.
Google SlidesをGoogle Driveの指定フォルダに出力(VRC_Panorama向け)
function removeFileIfExists(folder, filename) {
var children = folder.getFilesByName(filename);
if (children.hasNext()) {
var childFile = children.next();
folder.removeFile(childFile);
}
}
function exportSlideImages(presentationId) {
var myFolder = DriveApp.getFolderById('<Google Drive の Folder ID>');
var linkfilename = 'link.txt'
var linktext = '';
var presentation = SlidesApp.openById(presentationId);
presentation.getSlides().forEach(function(slide, i) {
var filename = 'slide' + (i + 1) + '.png';
var thumbnail = Slides.Presentations.Pages.getThumbnail(presentationId, slide.getObjectId(), {
'thumbnailProperties.thumbnailSize': 'LARGE'
});
var response = UrlFetchApp.fetch(thumbnail.contentUrl);
var blob = response.getBlob();
blob.setName(filename);
removeFileIfExists(myFolder, filename);
var newFile = myFolder.createFile(blob);
newFile.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
linktext += ' - url: http://drive.google.com/uc?export=view&id=' + newFile.getId() + '\n'
linktext += ' texture: {fileID: 0}' + '\n'
Logger.log('Created file "%s" for slide number %s', filename, i + 1);
});
removeFileIfExists(myFolder,linkfilename);
myFolder.createFile(linkfilename, linktext, MimeType.PLAIN_TEXT);
}
function myFunction() {
exportSlideImages("<Google Slides の ID>");
}
@tar-bin
Copy link
Author

tar-bin commented Mar 30, 2019

(1) リソース > Googleの拡張サービスで以下を許可
・Drive API v2
・Google Slides API v1
(2) Googleの拡張サービスのリンク先のGoogle Cloud Platform API ダッシュボードで以下を許可
・Google Drive API
・Google Slides API
(3) コード内の以下のIDを実際のものに更新
・Google SlidesのID
・Google Drive の 出力先 Folder ID
(4) スクリプトを実行
(5) 出力先に指定したGoogle Driveのフォルダ内にlink.txtが出力されている。.unity ファイルをテキストエディタで開いてVRC_Panoramaのpanoramasパラメータを書き換える。

@tar-bin
Copy link
Author

tar-bin commented Apr 30, 2019

要修正
・スライドの枚数が90枚あたりを超えるとエクスポート時にタイムアウトする

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment