Example 1 — Rectangle with Parameters
The default starter template creates a centered rectangle with five @param values: width, height, fill color, line thickness, and line color. It demonstrates the fundamental structure of every parameterized shape script.
Result
Code
// @help https://ppptools.happy-pc.ch/help/de/ase-beispiel-rechteck
/* PARAMS */
// @param float Breite "Width (pt)" default=200 min=10 max=2000 tooltip="Rectangle width in points"
// @param float Hoehe "Height (pt)" default=100 min=10 max=2000 tooltip="Rectangle height in points"
// @param color Fuellfarbe "Fill color" default=#4472C4 tooltip="Fill color of the rectangle"
// @param float Liniendicke "Line thickness (pt)" default=1.5 min=0 max=20 tooltip="Border line thickness (0 = no border)"
// @param color Linienfarbe "Line color" default=#2E4A7A tooltip="Color of the border line"
// @param bool Zentrieren "Center on slide" default=true tooltip="Center rectangle horizontally and vertically on the slide"
/* END PARAMS */
// ── Rectangle with parameters ─────────────────────────────────────────
float w = (float)(double)Params["Breite"];
float h = (float)(double)Params["Hoehe"];
var fillColor = (System.Drawing.Color)Params["Fuellfarbe"];
float lineW = (float)(double)Params["Liniendicke"];
var lineColor = (System.Drawing.Color)Params["Linienfarbe"];
bool zentrieren = (bool)Params["Zentrieren"];
float x = zentrieren ? (ppptools.SlideWidth - w) / 2f : 100f;
float y = zentrieren ? (ppptools.SlideHeight - h) / 2f : 100f;
var oShape = ppptools.AddRect(x, y, w, h);
oShape.Name = "MyRectangle";
oShape.Fill.ForeColor.RGB = System.Drawing.ColorTranslator.ToOle(fillColor);
if (lineW <= 0)
{
oShape.Line.Visible = (dynamic)0; // msoFalse = no border
}
else
{
oShape.Line.Visible = (dynamic)(-1); // msoTrue
oShape.Line.Weight = lineW;
oShape.Line.ForeColor.RGB = System.Drawing.ColorTranslator.ToOle(lineColor);
}
Parameter Dialog
When you run the snippet, this dialog appears with the configured values:
| Parameter | Type | Default | Description |
|---|---|---|---|
| Width (pt) | Float | 200 | Rectangle width in points |
| Height (pt) | Float | 100 | Rectangle height in points |
| Fill color | Color | #4472C4 | Fill color of the rectangle |
| Line thickness (pt) | Float | 1.5 | Border thickness (0 = no border) |
| Line color | Color | #2E4A7A | Color of the border line |
| Center on slide | Bool | ✓ | Center rectangle on slide (otherwise placed at 100/100 pt) |
Step-by-Step Explanation
1. @help and @param Definitions
// @help https://ppptools.happy-pc.ch/help/de/ase-beispiel-rechteck
// @param float Breite "Width (pt)" default=200 min=10 max=2000
The @param lines are parsed by the Advanced Snippet Editor and automatically generate the parameter dialog before execution. Each definition contains:
- Type:
float,color,string,bool,int,enum - Name: Internal identifier (no spaces) — used as the key in
Params["…"] - Label: Display name shown in the dialog (in quotes)
- default: Default value
- min / max: Allowed value range (for
float/intonly) - tooltip: Explanatory text shown on hover in the dialog
2. Reading Parameter Values
float w = (float)(double)Params["Breite"];
var fillColor = (System.Drawing.Color)Params["Fuellfarbe"];
Params is a Dictionary<string, object>. The double cast (float)(double) is required because numeric params are stored internally as double. For color params, Params[…] directly returns a System.Drawing.Color object.
3. Centering on the Slide
float x = (ppptools.SlideWidth - w) / 2f;
float y = (ppptools.SlideHeight - h) / 2f;
ppptools.SlideWidth / ppptools.SlideHeight return slide dimensions in points (standard 16:9 = 720 × 405 PT). This ensures the rectangle is always centered regardless of slide format or chosen size.
4. Creating the Shape and Setting the Color
var oShape = ppptools.AddRect(x, y, w, h);
oShape.Fill.ForeColor.RGB = System.Drawing.ColorTranslator.ToOle(fillColor);
PowerPoint stores colors as OLE integers (BGR byte order). ColorTranslator.ToOle() correctly converts System.Drawing.Color to this format.
5. Conditionally Showing the Border
if (lineW <= 0)
oShape.Line.Visible = (dynamic)0; // msoFalse — no border
else
{
oShape.Line.Visible = (dynamic)(-1); // msoTrue
oShape.Line.Weight = lineW;
oShape.Line.ForeColor.RGB = System.Drawing.ColorTranslator.ToOle(lineColor);
}
The (dynamic) cast is required in Roslyn scripts because Line.Visible is of type MsoTriState — a COM enum that cannot be set directly as true/false in Roslyn. 0 = msoFalse, -1 = msoTrue.
Key Patterns in This Example
(float)(double)Params[…]— required for float/int parameters (stored internally asdouble)(System.Drawing.Color)Params[…]— direct cast for color parametersColorTranslator.ToOle()— for all color assignments to PowerPoint shapes(dynamic)0/(dynamic)(-1)— forMsoTriStatepropertiesppptools.SlideWidth/SlideHeight— slide dimensions for centering
Next: Example 2 — Circle