Skip to content

Commit 8b38053

Browse files
[PowerPoint] (shapes) Add 'Move group' to group-ungroup snippet (#983)
* [PowerPoint] (shapes) Add 'Move group' to group-ungroup snippet * Fix typo
1 parent ddf187a commit 8b38053

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

samples/powerpoint/shapes/group-ungroup-shapes.yaml

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ api_set:
99
script:
1010
content: |
1111
document.getElementById("group-shapes").addEventListener("click", () => tryCatch(groupShapes));
12+
document.getElementById("move-group").addEventListener("click", () => tryCatch(moveGroup));
1213
document.getElementById("ungroup-shapes").addEventListener("click", () => tryCatch(ungroupShapes));
1314
document.getElementById("setup").addEventListener("click", () => tryCatch(setup));
1415
1516
async function groupShapes() {
1617
await PowerPoint.run(async (context) => {
1718
// Groups the geometric shapes on the current slide.
1819
19-
// Get the current slide.
20+
// Get the shapes on the current slide.
2021
context.presentation.load("slides");
2122
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
22-
23-
// Get the shapes.
2423
slide.load("shapes");
2524
await context.sync();
2625
@@ -39,15 +38,44 @@ script:
3938
});
4039
}
4140
41+
async function moveGroup() {
42+
await PowerPoint.run(async (context) => {
43+
// Move the first shape group to the top-left of the current slide.
44+
45+
// Get the shapes on the current slide.
46+
context.presentation.load("slides");
47+
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
48+
slide.load("shapes");
49+
await context.sync();
50+
51+
const shapes: PowerPoint.ShapeCollection = slide.shapes;
52+
shapes.load("items/type,items/id");
53+
await context.sync();
54+
55+
// Move the first grouped shapes.
56+
const shapeGroups = shapes.items.filter((item) => item.type === PowerPoint.ShapeType.group);
57+
if (shapeGroups.length == 0) {
58+
console.warn("No shape groups on the current slide so nothing to move.");
59+
return;
60+
}
61+
62+
const firstGroupId = shapeGroups[0].id;
63+
const shapeGroupToMove = shapes.getItem(firstGroupId);
64+
shapeGroupToMove.top = 0;
65+
shapeGroupToMove.left = 0;
66+
await context.sync();
67+
68+
console.log(`Moved shape group with group ID: ${firstGroupId}`);
69+
});
70+
}
71+
4272
async function ungroupShapes() {
4373
await PowerPoint.run(async (context) => {
4474
// Ungroups the first shape group on the current slide.
4575
46-
// Get the current slide.
76+
// Get the shapes on the current slide.
4777
context.presentation.load("slides");
4878
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
49-
50-
// Get the shapes.
5179
slide.load("shapes");
5280
await context.sync();
5381
@@ -132,6 +160,9 @@ template:
132160
<button id="group-shapes" class="ms-Button">
133161
<span class="ms-Button-label">Group shapes</span>
134162
</button>
163+
<button id="move-group" class="ms-Button">
164+
<span class="ms-Button-label">Move group</span>
165+
</button>
135166
<button id="ungroup-shapes" class="ms-Button">
136167
<span class="ms-Button-label">Ungroup shapes</span>
137168
</button>

snippet-extractor-output/snippets.yaml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15230,11 +15230,9 @@
1523015230
await PowerPoint.run(async (context) => {
1523115231
// Ungroups the first shape group on the current slide.
1523215232

15233-
// Get the current slide.
15233+
// Get the shapes on the current slide.
1523415234
context.presentation.load("slides");
1523515235
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
15236-
15237-
// Get the shapes.
1523815236
slide.load("shapes");
1523915237
await context.sync();
1524015238

@@ -15471,11 +15469,9 @@
1547115469
await PowerPoint.run(async (context) => {
1547215470
// Groups the geometric shapes on the current slide.
1547315471

15474-
// Get the current slide.
15472+
// Get the shapes on the current slide.
1547515473
context.presentation.load("slides");
1547615474
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
15477-
15478-
// Get the shapes.
1547915475
slide.load("shapes");
1548015476
await context.sync();
1548115477

@@ -15716,11 +15712,9 @@
1571615712
await PowerPoint.run(async (context) => {
1571715713
// Ungroups the first shape group on the current slide.
1571815714

15719-
// Get the current slide.
15715+
// Get the shapes on the current slide.
1572015716
context.presentation.load("slides");
1572115717
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
15722-
15723-
// Get the shapes.
1572415718
slide.load("shapes");
1572515719
await context.sync();
1572615720

@@ -15751,11 +15745,9 @@
1575115745
await PowerPoint.run(async (context) => {
1575215746
// Ungroups the first shape group on the current slide.
1575315747

15754-
// Get the current slide.
15748+
// Get the shapes on the current slide.
1575515749
context.presentation.load("slides");
1575615750
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
15757-
15758-
// Get the shapes.
1575915751
slide.load("shapes");
1576015752
await context.sync();
1576115753

0 commit comments

Comments
 (0)