The stacking order is determined by the order by which they are inserted into the slide. However, some of the page elements in slides remain hidden.
Is there a way to change the Order of objects in Google slides using apps script?
The stacking order is determined by the order by which they are inserted into the slide. However, some of the page elements in slides remain hidden.
Is there a way to change the Order of objects in Google slides using apps script?
How about this workaround? I have experienced the same situation with you. At that time, I have moved the element using this workaround. I think that there are several workarounds for this situation. So please think of this as one of them. The flow of this workaround is as follows.
In Google Slides, for example, when new shape is created to a slide, it is added to the last element to pageElements
. This means that the last element to pageElements
is the most front. This is used for the workaround.
insertPageElement()
. These are added to the page as new elements.pageElements
.By this, the selected shapes can be brought to the most front and back. When this flow is reflected to the script, it becomes as follows.
function move(page, spe) {
var pe = page.getPageElements();
spe.forEach(function(e) {
page.insertPageElement(e);
});
pe.forEach(function(f, i) {
if (spe.some(function(g) {return f.getObjectId() == g.getObjectId()})) {
pe[i].remove();
}
});
}
// Bring to back
function back() {
var slide = SlidesApp.getActivePresentation();
var selected = slide.getSelection();
var page = selected.getCurrentPage();
var pageElements = page.getPageElements();
var selectedPageElements = selected.getPageElementRange().getPageElements();
var noSelectedPageElements = pageElements.filter(function(e) {return !selectedPageElements.some(function(f) {return e.getObjectId() == f.getObjectId()})});
move(page, noSelectedPageElements);
}
// Bring to front
function front() {
var slide = SlidesApp.getActivePresentation();
var selected = slide.getSelection();
var page = selected.getCurrentPage();
var pageElements = page.getPageElements();
var selectedPageElements = selected.getPageElementRange().getPageElements();
move(page, selectedPageElements);
}
front()
or back()
. When front()
is run, the selected shape is moved to the most front. When back()
is run, it is moved to the most back.If this answer was not what you want, I'm sorry.
The Slides service was updated at Google's update at November 14, 2018, and several methods were added for achieving this issue.
The Slides service has been extended with the following new methods that let you control the Z-positioning of page elements in Slides.
- bringForward()
- bringToFront()
- sendBackward()
- sendToBack()