@@ -9,18 +9,17 @@ api_set:
9
9
script :
10
10
content : |
11
11
document.getElementById("group-shapes").addEventListener("click", () => tryCatch(groupShapes));
12
+ document.getElementById("move-group").addEventListener("click", () => tryCatch(moveGroup));
12
13
document.getElementById("ungroup-shapes").addEventListener("click", () => tryCatch(ungroupShapes));
13
14
document.getElementById("setup").addEventListener("click", () => tryCatch(setup));
14
15
15
16
async function groupShapes() {
16
17
await PowerPoint.run(async (context) => {
17
18
// Groups the geometric shapes on the current slide.
18
19
19
- // Get the current slide.
20
+ // Get the shapes on the current slide.
20
21
context.presentation.load("slides");
21
22
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
22
-
23
- // Get the shapes.
24
23
slide.load("shapes");
25
24
await context.sync();
26
25
@@ -39,15 +38,44 @@ script:
39
38
});
40
39
}
41
40
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
+
42
72
async function ungroupShapes() {
43
73
await PowerPoint.run(async (context) => {
44
74
// Ungroups the first shape group on the current slide.
45
75
46
- // Get the current slide.
76
+ // Get the shapes on the current slide.
47
77
context.presentation.load("slides");
48
78
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
49
-
50
- // Get the shapes.
51
79
slide.load("shapes");
52
80
await context.sync();
53
81
@@ -132,6 +160,9 @@ template:
132
160
<button id="group-shapes" class="ms-Button">
133
161
<span class="ms-Button-label">Group shapes</span>
134
162
</button>
163
+ <button id="move-group" class="ms-Button">
164
+ <span class="ms-Button-label">Move group</span>
165
+ </button>
135
166
<button id="ungroup-shapes" class="ms-Button">
136
167
<span class="ms-Button-label">Ungroup shapes</span>
137
168
</button>
0 commit comments