如何将元素转换为与第一个选定元素相同的大小? [英] How to convert elements to the same size as the first selected element?

查看:59
本文介绍了如何将元素转换为与第一个选定元素相同的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有元素的大小设置为第一个选定元素的大小.但是我的代码似乎有问题,以某种方式第一个元素的大小不适用于其他人.

请参阅附件脚本

 /**使所有元素大小相同*/函数sameSizeElements(){var selection = SlidesApp.getActivePresentation().getSelection();var selectionType = selection.getSelectionType();var pageElements = selection.getPageElementRange().getPageElements();//迭代选定的页面元素以获取每个位置的值for(var i = 0; i< pageElements.length; i ++){if(i!= 0){pageElements [i] .setWidth(pageElements [0] .getWidth());pageElements [i] .setHeight(pageElements [0] .getHeight());}}} 

这是方法)按选择顺序.

至少这确认了可以遵循选择的顺序,但是管理服务器端上述列表的方式改变了该顺序.不幸的是,我无法确定 .getSelection().getPageElementRange().getPageElements()返回元素的任何特定顺序(除了形式为 g8edc625556_0_0 的ID分组)代码>方法链:

I want to set the size of all elements as the size of the first selected element. but seems something wrong with my code , somehow first element size not working for others.

Please see attached script

/*
 * Make all elements same size
 */
function sameSizeElements() {
  var selection = SlidesApp.getActivePresentation().getSelection();
  var selectionType = selection.getSelectionType();
  var pageElements = selection.getPageElementRange().getPageElements();
  
  //iterate the selected page elements to grab the values of each positiion
  for (var i = 0; i < pageElements.length; i++) {
  
    if(i != 0){
      pageElements[i].setWidth(pageElements[0].getWidth());
      pageElements[i].setHeight(pageElements[0].getHeight());
    }
  }   
}

Here is the full code you can put in ScriptEditor > code.js default file and refresh slide. it will work as you want to debug.

Updated

We are in the discussion with Google App Script issue tracking team - https://issuetracker.google.com/issues/162545277

解决方案

Additional context to the issue:

when a server-side function is invoked, a ctx object is sent to the /invoke endpoint that, among other info (session id ssid, document id docId, revision number rev, and application type app), contains data about currently selected PageElements in property value with key sel.

The value is an array of arrays of strings and numbers, of which only one of the elements contains strings - if you look closely, these strings are object Ids (you can confirm with getObjectId method) in order of selection.

At least this confirms that the order of selection can be respected, but the way how the abovementioned list is managed server-side changes that order. Unfortunately, I could not confirm any particular order of how the elements (apart from grouping of Ids of form g8edc625556_0_0) are returned by .getSelection().getPageElementRange().getPageElements() chain of methods:

这篇关于如何将元素转换为与第一个选定元素相同的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆