如何以编程方式控制指南(第三规则)?

Puz*_*Boy 3 google-apps-script google-slides google-slides-api

有什么方法可以控制 Google 幻灯片演示中的指南(第三条规则)。就我阅读的 Google Apps Script 文档而言,没有控制指南的方法。

我已经尝试过表现得像指南(第三规则)的线条,但这些不是“真正的”指南。用户可以删除这些行,这些行仅限于幻灯片页面区域。

看图了解线条和参考线的区别(三分法则):

线路和指南的区别

要启用指南(第三规则),请转到此处:

导游

Ole*_*ter 5

允许通过SlidesApp或 Slides API控制指南的功能请求提交给问题跟踪器。如果您发现该功能有用,请给它加星号。

简答

如前所述,不幸的是,目前无法通过SlidesApp服务或Slides API 实现这一点

解决方法

实际上可以通过传递一个负整数作为 的参数来使线条延伸到幻灯片边界之外insertLine。至于能够删除线条,如果用户将指南拖出幻灯片边界,也可以“删除”指南。

我无法模仿的指南的唯一属性是在呈现时隐藏它们(因为隐藏了真正的指南)。

以下是类似于您的方法(创建Lines网格)的解决方法:

指南

/**
 * @summary emulates adding guides to the Slide
 * 
 * @param {{
 *  rows : (number|1),
 *  deleteOld : (boolean|true),
 *  cols : (number|1),
 *  color : string
 * }} 
 */
const showGuides = ({ deleteOld = true, rows = 1, cols = 1, color = "#d3d3d3" } = {}) => {

    const presentation = SlidesApp.getActivePresentation();
    const currPage = presentation.getSelection().getCurrentPage();

    const prop = "guides";

    const store = PropertiesService.getUserProperties();

    /** @type {string[]} */
    let guideRefs = JSON.parse(store.getProperty(prop) || "[]");

    const lines = currPage.getLines();

    const oldLines = lines.filter((line) => guideRefs.includes(line.getObjectId()));

    if (deleteOld) {
        oldLines.forEach(line => line.remove());

        guideRefs = removeElements(guideRefs, oldLines.map(l => l.getObjectId()));
    }

    const currWidth = presentation.getPageWidth();
    const currHeight = presentation.getPageHeight();

    const xStep = Math.floor(currWidth / cols);
    const yStep = Math.floor(currHeight / rows);

    const newGuides = [];

    const maxScreen = 4096;

    for (let x = 0; x <= cols; x++) {
        const line = currPage.insertLine(
            SlidesApp.LineCategory.STRAIGHT,
            xStep * x, -maxScreen, xStep * x, currHeight + maxScreen
        );

        const fill = line.getLineFill();
        fill.setSolidFill(color);

        const oid = line.getObjectId();
        guideRefs.push(oid);
        newGuides.push(line);
    }

    for (let y = 0; y <= rows; y++) {
        const line = currPage.insertLine(
            SlidesApp.LineCategory.STRAIGHT,
            -maxScreen, yStep * y, currWidth + maxScreen, yStep * y
        );

        const fill = line.getLineFill();
        fill.setSolidFill(color);

        const oid = line.getObjectId();
        guideRefs.push(oid);
        newGuides.push(line);
    }

    store.setProperty(prop, JSON.stringify(guideRefs));
};
Run Code Online (Sandbox Code Playgroud)

公用事业

/**
 * @summary removes elements from an array
 * @param {any[]} arr 
 * @param {...any} elems
 * @returns {any[]}
 */
const removeElements = (arr, ...elems) => arr.filter((elem) => !elems.includes(elem));
Run Code Online (Sandbox Code Playgroud)

演示

变通方法测试