Advanced Snippet Editor
The Advanced Snippet Editor lets you create PowerPoint shapes directly with C# code, test them live, and save them as snippets in the library. Scripts are executed at runtime using Roslyn (Microsoft C# Scripting).
No Support
The Advanced Snippet Editor is intended for experienced users with C# knowledge.
PPPTools provides no support for custom scripts.
Faulty scripts can have unexpected effects on the open presentation.
How to Open
- Burger menu ≡ → Advanced Snippet Editor
- or: Ribbon → Content Manager → Advanced Snippet Editor
The task pane opens automatically in wide mode.
Interface
| Area | Description |
|---|---|
| Line numbers | Narrow panel to the left of the code field — shows line numbers in sync while scrolling |
| Code field | Enter or paste a C# script |
| Cursor position | Shows current line and column (right side of toolbar: Ln 1 Col 1) |
| Error panel | Shows compiler and runtime errors (appears automatically on error) |
Toolbar
The toolbar is organized into button groups. Buttons with a small arrow ▾ open a dropdown with options.
Run & Save
| Button | Function |
|---|---|
| ▶ Run | Execute the script on the active slide |
| 💾 Save ▾ | Dropdown: save snippet locally or upload as draft to the public library |
Dropdown «💾 Save»:
| Option | Description |
|---|---|
| Save as Snippet | Run script, generate preview image, enter metadata and save locally |
| Upload as Draft | Send snippet as draft to the public library (for admin review and approval) |
Analyse & Code
| Button | Function |
|---|---|
| 📂 Load | Load the code of an existing snippet into the editor |
| 🔍 Analyse ▾ | Dropdown with analysis and code tools |
Dropdown «🔍 Analyse»:
| Option | Description |
|---|---|
| Analyse Code | Statically analyse the script: show recognized @param definitions, compiler warnings and errors in a dialog |
| Generate Code (replace) | Generate ppptools.* code from the selected shape and replace the editor content (only if empty or showing the starter template) |
| Generate Code (append) | Append the generated code to the existing editor content (with a separator comment) |
| Show Nodes | Visualize the key points of the selected shape with colored markers on the slide |
| Reset Editor | Reset code to the starter template and clear the error panel |
Line Numbers & Cursor Position
The narrow panel to the left of the code field automatically shows line numbers — synchronized with vertical scrolling. The current cursor position is shown on the right side of the toolbar:
Ln 12 Col 5
The display updates on every cursor movement.
Available Variables
The following variables are available directly in the script:
| Variable | Type | Description |
|---|---|---|
ppptools |
AdvancedScriptHelper |
All PowerPoint operations (shape creation, selection, Boolean ops, styling …) |
Params |
SnippetParamBag |
Parameter values from the @param dialog (for parameterized snippets) |
No direct COM access
oSlide and aPowerPoint are not available in scripts — all operations go through
ppptools.* methods. This prevents uncontrolled access to the PowerPoint application.
ppptools Methods (Overview)
→ Full reference with parameters and code examples: PPPTools Reference
| Category | Methods |
|---|---|
| Slide | SlideWidth, SlideHeight |
| Create | AddShape, AddRect, AddOval, BuildFreeform, AddPolygon, AddPolyline |
| Selection | GetSelected, GetSelectedRange |
| Boolean ops | Union, Intersect, Combine, Subtract |
| Grouping | GroupSelected, Group |
| Duplicate | Duplicate |
| Z-Order | SendBackward, BringForward, SendToBack, BringToFront |
| Flip | FlipH, FlipV |
| Position | CenterOnSlide, Scale |
| Styling | SetFill, SetGradient, SetLine, HideLine, SetText |
| Animations | AddAnimation |
Important Scripting Rules
Roslyn scripts run in a special context. The following rules must be followed to avoid compiler errors:
Use var / dynamic instead of Shape
The type Shape exists in two namespaces simultaneously (Microsoft.Office.Core and Microsoft.Office.Interop.PowerPoint) — this causes a compiler error.
// ❌ Error — ambiguous reference (when Shape types are used mixed)
Shape oRect = ppptools.AddRect(...);
// ✅ Correct
var oRect = ppptools.AddRect(...);
Use local functions instead of Action<T>
Action<> is in the System namespace, which is not automatically imported.
// ❌ Error
Action<Shape> style = sh => { sh.Fill.ForeColor.RGB = ...; };
// ✅ Correct — local void function
void ApplyStyle(dynamic sh)
{
sh.Fill.ForeColor.RGB = ...;
}
Selection for Boolean operations
List<Shape> cannot be used directly due to the namespace conflict. Select shapes using .Select() instead:
// ✅ Correct
oShape1.Select(MsoTriState.msoTrue); // first shape: Replace = true
oShape2.Select(MsoTriState.msoFalse); // additional shape: Replace = false
ppptools.Union();
dynamic oResult = ppptools.GetSelected(); // retrieve result shape
Examples
Each example has its own page with a visual preview, full code, and step-by-step explanation.
Foundation examples (Boolean operations):
| # | Example | Topics |
|---|---|---|
| 1 | Rectangle | ppptools.AddRect, fill color, removing the border |
| 2 | Circle | ppptools.AddOval, center-point calculation, border color |
| 3 | Union | Selection pattern, ppptools.Union(), ppptools.GetSelected() |
| 4 | Square with Hole | ppptools.Combine(), true geometric holes |
| 5 | Gear Wheel | Chaining 3 Boolean ops, Adjustments[1], all tooth counts |
Full parameterized examples (all ppptools methods):
| Example | ppptools Methods |
|---|---|
| Gear Wheel (parameterized) | AddShape, AddOval, GetSelected, GetSelectedRange, Union, Intersect, Combine, SlideWidth/Height |
| Post-it (parameterized) | BuildFreeform, AddRect, GetSelected, Duplicate, Intersect, Subtract, FlipH, SendBackward, SetGradient, HideLine, Group |
| Persona (parameterized) | BuildFreeform, AddOval, AddRect, Group, Scale, SlideWidth/Height |
Workflow
Generate Code from a Selected Shape
The Generate Code (replace) and Generate Code (append) options read the currently selected shape in PowerPoint and produce immediately executable ppptools.* code.
Replace vs. Append:
| Option | Behavior |
|---|---|
| Generate Code (replace) | Editor is empty or shows only the starter template → code is inserted directly, replacing the content |
| Generate Code (append) | Existing code is preserved → new code is appended with a separator comment |
What is generated:
| Shape type | Generated code |
|---|---|
| Rectangle | ppptools.AddRect(...) |
| Oval / Circle | ppptools.AddOval(...) |
| Other AutoShape | ppptools.AddShape(MsoAutoShapeType.xxx, ...) |
| FreeForm (straight segments only) | ppptools.AddPolygon(new float[]{...}, new float[]{...}) |
| FreeForm (with curves) | ppptools.BuildFreeform(...) + AddNodes(...) |
| Group | Recursive code for all members + ppptools.Group(...) |
| Fill | ppptools.SetFill(...) or ppptools.SetGradient(...) |
| Line | ppptools.SetLine(...) or ppptools.HideLine(...) |
| Text | ppptools.SetText(...) |
| Animations | ppptools.AddAnimation(...) + timing |
Ideal workflow
Draw a shape manually in PowerPoint → Generate Code (replace) → the editor shows the exact code
to recreate it → adjust parameters → ▶ Run to test → 💾 Save as Snippet.
Show Nodes
The Show Nodes option places colored markers directly on the slide for each key point of the selected shape.
FreeForm Shapes
For FreeForm shapes, each node is labeled with its coordinates, index, segment type (Line / Curve) and editing type (Corner / Auto).
Color coding:
| Color | Meaning |
|---|---|
| 🟢 Green | Start node (index 0) |
| 🔴 Red | Intermediate nodes |
| 🔵 Blue | Last node |
Standard Shapes (Rectangle, Oval, AutoShape …)
For standard shapes, the 4 corner points (TL / TR / BR / BL) and the center point (C) are displayed:
| Marker | Position | Shape |
|---|---|---|
| TL / TR / BR / BL | Corners | Small blue circle |
| C | Center | Small orange diamond |
An info label above the shape shows name, type and dimensions.
Clean up
Delete the markers after analysis: select all shapes named Node_*, NodeLabel_* or NodeInfo_* and delete them, or use Ctrl+Z to undo.
Analyse Code
The Analyse Code option statically checks the current script and shows the result in a dialog:
- Recognized
@paramdefinitions (name, type, default value) - Compiler warnings
- Compiler errors
Useful to verify that all @param declarations are correct before running the script.
→ More about @param: Parameterized Snippets
Testing a Script
- Enter code in the code field or load an existing snippet via 📂 Load
- Click ▶ Run — the shape appears on the active slide
- If errors occur: read the error panel, fix the code, run again
- Delete test shapes manually (Delete key)
Note
A presentation must be open with an active slide.
Saving as a Snippet
- Click 💾 Save ▾ → Save as Snippet
- The script runs — newly created shapes are detected automatically
- A preview image is generated from the new shapes
- Shapes are deleted after the preview is exported
- Metadata dialog: enter Name*, Category, Tags, Description etc.
- Click Save — the snippet appears immediately in the gallery
Uploading as a Draft to the Public Library
Finished snippets can be sent directly from the editor as a draft to the public library:
- Click 💾 Save ▾ → Upload as Draft
- The script runs and a preview image is generated
- Fill in the metadata dialog (Name*, Category, Tags, Description)
- The snippet is sent to the library server as a Draft
- An admin reviews and publishes the snippet
Draft status
After uploading, the snippet is not yet public — it must first be reviewed and approved by an admin.
Microsoft Documentation
| Topic | Link |
|---|---|
| All shape types (MsoAutoShapeType) | learn.microsoft.com |
| Shapes.AddShape method | learn.microsoft.com |
| Shape object (all properties) | learn.microsoft.com |
| FillFormat (fill) | learn.microsoft.com |
| LineFormat (border) | learn.microsoft.com |