Created
January 10, 2020 18:06
-
-
Save sathishvj/2901d707872c2e79c660d39db5b5b39b to your computer and use it in GitHub Desktop.
Google Apps Script to Center Selection Horizontally and Vertically on the Slide
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @OnlyCurrentDoc | |
*/ | |
/** | |
* Create a open translate menu item. | |
* @param {Event} event The open event. | |
*/ | |
function onOpen(event) { | |
SlidesApp.getUi().createAddonMenu() | |
.addItem('Align Selection Centrally on Slide', 'alignSelectedCentrallyOnSlide') | |
.addToUi(); | |
} | |
/** | |
* Open the Add-on upon install. | |
* @param {Event} event The install event. | |
*/ | |
function onInstall(event) { | |
onOpen(event); | |
} | |
function alignSelectedCentrallyOnSlide() { | |
var selection = SlidesApp.getActivePresentation().getSelection(); | |
if (selection == null) { | |
return; | |
} | |
per = selection.getPageElementRange(); | |
if (per == null) { | |
return; | |
} | |
pes = per.getPageElements(); | |
if (pes == null || pes.length == 0) { | |
return; | |
} | |
pes.forEach(function(f, i) { | |
pes[i].alignOnPage(SlidesApp.AlignmentPosition.HORIZONTAL_CENTER); | |
pes[i].alignOnPage(SlidesApp.AlignmentPosition.VERTICAL_CENTER); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment