创建幻灯片时,高级幻灯片 api 未使用预定义布局
Predefined layout not being used by advance slides api on slide create
这是我第一个几乎成功的插件。它是一个独立的脚本。我已经在其他人创建的几个幻灯片上对其进行了测试。在最新的测试中,我的代码创建的内容 Table 使用了卡片组中的 master/layout 而不是我在代码中调用的 BLANK 预定义内容?
/**
not using blank predefined blank master
MINI TEST
*/
function miniTest() {
const pres = SlidesApp.getActivePresentation();
const presId = pres.getId();
let updtReqArr = [];
// create request for a Slide to hold the table of contents
let insertIdx = 0;
pageId = miniPage(updtReqArr, insertIdx);
if (updtReqArr.length > 0) {
response = Slides.Presentations.batchUpdate({ 'requests': updtReqArr }, presId);
}
}
/**
* create request for a Slide to hold the table of contents
*/
function miniPage(updtReqArr, insertIdx) {
// console.log('Begin createTocPage - insertIdx: ', insertIdx );
pageId = Utilities.getUuid();
// console.log('pageId: ', pageId);
// base slide object request
slideObj = [{
'createSlide': {
'objectId': pageId,
'insertionIndex': insertIdx,
'slideLayoutReference': {
'predefinedLayout': 'BLANK' // name of master
}
}
}];
// console.log('slideObj: ', JSON.stringify(slideObj));
updtReqArr.push(slideObj);
// console.log('updtReqArr.length: ', updtReqArr.length);
// code that creates page elments, background, etc. removed for simplicity
return pageId;
}
我遇到此问题的演示文稿是 GEG Eduprotocols 演示文稿的副本。这是我的副本的link。
https://docs.google.com/presentation/d/1EEUDz0fBXnI4IBT8xlcKJrfPs_KMr5HIY2YfCjDLiuQ/edit?usp=sharing
这是公开的来源
https://docs.google.com/presentation/d/1i5Hhod8ERu8dfmMk5f-pcuFGHZ6bc96JAe3Pca_rbxY/edit#slide=id.p
创作者使用了 Slidesmania 母版,这些母版出现在我添加的 Table 目录中,尽管我说使用空白。我做错了什么?
-
-
-
-
-
-
-
- 正在尝试使用 2021 年 3 月 31 日的答案 - - - - - - - -
在 slidedeck 中使用现有的 BLANK 布局仍然没有运气。真的被 getMasters() 和 getLayouts() 弄糊涂了。以下两组代码找到相同的'objectId',但在批量更新中不起作用。
let layoutsArr = pres.getLayouts();
let lArrSize = layoutsArr.length;
for ( i = 0 ; i < lArrSize ; i++ ) {
console.log('layoutsArr[i].getLayoutName(): ', layoutsArr[i].getLayoutName() );
if ( layoutsArr[i].getLayoutName() === 'BLANK' ) {
blankObjId = layoutsArr[i].getObjectId();
blankIdx = i;
console.log('layoutsArr[i] blankIdx: ', blankIdx );
i = presSize + 1;
}
}
let mastersArr = pres.getMasters();
let mArrSize = mastersArr.length;
for ( i = 0 ; i < mArrSize ; i++ ) {
console.log('i: ', i );
layoutsArr = mastersArr[i].getLayouts();
let lArrSize = layoutsArr.length;
for ( j = 0 ; j < lArrSize ; j++ ) {
console.log('j: ', j, ' layoutsArr[j].getLayoutName(): ', layoutsArr[j].getLayoutName() );
if ( layoutsArr[j].getLayoutName() === 'BLANK' ) {
blankObjId = layoutsArr[j].getObjectId();
console.log(' blankObjId: ', blankObjId );
blankIdx = j;
console.log('layoutsArr[i] blankIdx: ', blankIdx );
j = lArrSize + 1;
i = mArrSize + 1;
}
}
}
pageId = Utilities.getUuid();
console.log('pageId: ', pageId);
slideObj = [{
'createSlide': {
'objectId': pageId,
'insertionIndex': insertIdx,
'slideLayoutReference': {
"layoutId": blankObjId
}
}
}];
生成的批量更新代码:
slideObj: [{"createSlide":{"objectId":"c5f67b57-3318-4e4a-9aff-7d1a09f57464","insertionIndex":0,"slideLayoutReference":{"layoutId":"p12"}}}]
error
// Invalid requests[0].createSlide: The layout (p12) is not present in the current master (gc92c1a471f_0_19804).
我不得不添加额外的行,因为代码显示为一个混在一起的段落???
解释:
由于您的幻灯片具有自定义模板,预定义的布局已被新模板覆盖。您需要从 slide-mania
master.
所需的特定布局中指定对象 ID
示例代码:
/**
not using blank predefined blank master
MINI TEST
*/
function miniTest() {
const pres = SlidesApp.getActivePresentation();
const presId = pres.getId();
const master = pres.getMasters()[1]; // slide-mania
const layout = master.getLayouts()[16].getObjectId(); // blank
let updtReqArr = [];
// create request for a Slide to hold the table of contents
let insertIdx = 0;
pageId = miniPage(updtReqArr, insertIdx, layout); // blank
if (updtReqArr.length > 0) {
response = Slides.Presentations.batchUpdate({ 'requests': updtReqArr }, presId);
}
}
/**
* create request for a Slide to hold the table of contents
*/
function miniPage(updtReqArr, insertIdx, layout) {
// console.log('Begin createTocPage - insertIdx: ', insertIdx );
pageId = Utilities.getUuid();
// console.log('pageId: ', pageId);
// base slide object request
slideObj = [{
'createSlide': {
'objectId': pageId,
'insertionIndex': insertIdx,
'slideLayoutReference': {
'layoutId': layout // object ID of layout
}
}
}];
// console.log('slideObj: ', JSON.stringify(slideObj));
updtReqArr.push(slideObj);
// console.log('updtReqArr.length: ', updtReqArr.length);
// code that creates page elments, background, etc. removed for simplicity
return pageId;
}
要更改创建的布局,请根据 Slide Mania 母版中布局的顺序更改 master.getLayouts()
的索引。您可以使用 View
菜单 -> Master
.
查看它们
参考文献:
这是我第一个几乎成功的插件。它是一个独立的脚本。我已经在其他人创建的几个幻灯片上对其进行了测试。在最新的测试中,我的代码创建的内容 Table 使用了卡片组中的 master/layout 而不是我在代码中调用的 BLANK 预定义内容?
/**
not using blank predefined blank master
MINI TEST
*/
function miniTest() {
const pres = SlidesApp.getActivePresentation();
const presId = pres.getId();
let updtReqArr = [];
// create request for a Slide to hold the table of contents
let insertIdx = 0;
pageId = miniPage(updtReqArr, insertIdx);
if (updtReqArr.length > 0) {
response = Slides.Presentations.batchUpdate({ 'requests': updtReqArr }, presId);
}
}
/**
* create request for a Slide to hold the table of contents
*/
function miniPage(updtReqArr, insertIdx) {
// console.log('Begin createTocPage - insertIdx: ', insertIdx );
pageId = Utilities.getUuid();
// console.log('pageId: ', pageId);
// base slide object request
slideObj = [{
'createSlide': {
'objectId': pageId,
'insertionIndex': insertIdx,
'slideLayoutReference': {
'predefinedLayout': 'BLANK' // name of master
}
}
}];
// console.log('slideObj: ', JSON.stringify(slideObj));
updtReqArr.push(slideObj);
// console.log('updtReqArr.length: ', updtReqArr.length);
// code that creates page elments, background, etc. removed for simplicity
return pageId;
}
我遇到此问题的演示文稿是 GEG Eduprotocols 演示文稿的副本。这是我的副本的link。 https://docs.google.com/presentation/d/1EEUDz0fBXnI4IBT8xlcKJrfPs_KMr5HIY2YfCjDLiuQ/edit?usp=sharing 这是公开的来源 https://docs.google.com/presentation/d/1i5Hhod8ERu8dfmMk5f-pcuFGHZ6bc96JAe3Pca_rbxY/edit#slide=id.p
创作者使用了 Slidesmania 母版,这些母版出现在我添加的 Table 目录中,尽管我说使用空白。我做错了什么?
-
-
-
-
-
-
-
- 正在尝试使用 2021 年 3 月 31 日的答案 - - - - - - - - 在 slidedeck 中使用现有的 BLANK 布局仍然没有运气。真的被 getMasters() 和 getLayouts() 弄糊涂了。以下两组代码找到相同的'objectId',但在批量更新中不起作用。
-
-
-
-
-
-
let layoutsArr = pres.getLayouts();
let lArrSize = layoutsArr.length;
for ( i = 0 ; i < lArrSize ; i++ ) {
console.log('layoutsArr[i].getLayoutName(): ', layoutsArr[i].getLayoutName() );
if ( layoutsArr[i].getLayoutName() === 'BLANK' ) {
blankObjId = layoutsArr[i].getObjectId();
blankIdx = i;
console.log('layoutsArr[i] blankIdx: ', blankIdx );
i = presSize + 1;
}
}
let mastersArr = pres.getMasters();
let mArrSize = mastersArr.length;
for ( i = 0 ; i < mArrSize ; i++ ) {
console.log('i: ', i );
layoutsArr = mastersArr[i].getLayouts();
let lArrSize = layoutsArr.length;
for ( j = 0 ; j < lArrSize ; j++ ) {
console.log('j: ', j, ' layoutsArr[j].getLayoutName(): ', layoutsArr[j].getLayoutName() );
if ( layoutsArr[j].getLayoutName() === 'BLANK' ) {
blankObjId = layoutsArr[j].getObjectId();
console.log(' blankObjId: ', blankObjId );
blankIdx = j;
console.log('layoutsArr[i] blankIdx: ', blankIdx );
j = lArrSize + 1;
i = mArrSize + 1;
}
}
}
pageId = Utilities.getUuid();
console.log('pageId: ', pageId);
slideObj = [{
'createSlide': {
'objectId': pageId,
'insertionIndex': insertIdx,
'slideLayoutReference': {
"layoutId": blankObjId
}
}
}];
生成的批量更新代码:
slideObj: [{"createSlide":{"objectId":"c5f67b57-3318-4e4a-9aff-7d1a09f57464","insertionIndex":0,"slideLayoutReference":{"layoutId":"p12"}}}]
error
// Invalid requests[0].createSlide: The layout (p12) is not present in the current master (gc92c1a471f_0_19804).
我不得不添加额外的行,因为代码显示为一个混在一起的段落???
解释:
由于您的幻灯片具有自定义模板,预定义的布局已被新模板覆盖。您需要从 slide-mania
master.
示例代码:
/**
not using blank predefined blank master
MINI TEST
*/
function miniTest() {
const pres = SlidesApp.getActivePresentation();
const presId = pres.getId();
const master = pres.getMasters()[1]; // slide-mania
const layout = master.getLayouts()[16].getObjectId(); // blank
let updtReqArr = [];
// create request for a Slide to hold the table of contents
let insertIdx = 0;
pageId = miniPage(updtReqArr, insertIdx, layout); // blank
if (updtReqArr.length > 0) {
response = Slides.Presentations.batchUpdate({ 'requests': updtReqArr }, presId);
}
}
/**
* create request for a Slide to hold the table of contents
*/
function miniPage(updtReqArr, insertIdx, layout) {
// console.log('Begin createTocPage - insertIdx: ', insertIdx );
pageId = Utilities.getUuid();
// console.log('pageId: ', pageId);
// base slide object request
slideObj = [{
'createSlide': {
'objectId': pageId,
'insertionIndex': insertIdx,
'slideLayoutReference': {
'layoutId': layout // object ID of layout
}
}
}];
// console.log('slideObj: ', JSON.stringify(slideObj));
updtReqArr.push(slideObj);
// console.log('updtReqArr.length: ', updtReqArr.length);
// code that creates page elments, background, etc. removed for simplicity
return pageId;
}
要更改创建的布局,请根据 Slide Mania 母版中布局的顺序更改 master.getLayouts()
的索引。您可以使用 View
菜单 -> Master
.
参考文献: