Script Samples

Fifteen small, self-contained scripts for SpinFire’s Python.NET scripting engine. They were written against the spinfireapi source and the reference pages in this space, and aimed at Filter.CATPart, a CATIA V5 R17 part. Each page explains what the script does, lists its settings and the API functions it uses, and includes the full source.

Note

New to scripting? Read Getting Started with spinfireapi first. For the sample that ships with SpinFire, see Sample Script — Calculate Cylindrical Radius.

Sample Model

All the samples are written for Filter.CATPart, a filter housing modelled in CATIA V5 R17, in millimetres. It is installed with SpinFire Insight, in the Samples\CATIA V5\Aquo Bottle folder of your SpinFire Insight installation (for example, C:\Program Files\SpinFire\SpinFire Insight\Samples\CATIA V5\Aquo Bottle\Filter.CATPart). Copy it to C:\temp\Models, which is the folder every sample uses by default. You can then run the samples exactly as written. They also work on other models, but tree paths, item names and sizes will differ.

How to Use Them

  1. Open the model in SpinFire (samples 01 and 07 open files themselves).

  2. Open the script in the script editor and edit the Settings block at the top.

  3. Click Run and watch the Python.NET Console for output.

All scripts default to C:\temp\Models for input and output. Change the Settings block to use another folder. The scripts can’t run outside SpinFire, because spinfirecontext.ScriptManager is only set by the host. SpinFire’s embedded interpreter is Python 3.9.

Samples

Sample

What it shows

Sample 01 — Open And Snapshot Views

OpenFile, standard views, ExportImage

Sample 02 — Part Report

Select by type, properties, physical properties, bounding box, text report

Sample 03 — Section Cut Sweep

Stepping the YZ section plane along X, projection area, screenshot and DXF profile per step

Sample 04 — Appearance Presets

Render mode, color and transparency presets

Sample 05 — Point To Point Distance

SelectPoint twice, distance math, InsertLine

Sample 06 — Surface Bounding Box Overlay

SelectSurface, surface.Points, drawing with InsertPolyline

Sample 07 — Batch Thumbnails

Looping OpenFile / ExportImage / CloseFile over a folder

Sample 08 — Show Vertex Normals

surface.Points and surface.VertexNormals, drawing normals with InsertLine

Sample 09 — Coordinate System Workflow

Create at a picked point, read the matrix, rename, rotate, show, activate

Sample 10 — Assembly Tree Walker

Walk the tree by path with SelectItem, save an outline, rename by path

Sample 11 — Isolate And Restore

Hide all, show named items and parents, screenshot, show all again

Sample 12 — Section Box

Two or three planes, per-plane offsets, tilt, cut edges, reset all

Sample 13 — Transform And Mirror

Move, rotate, scale, mirror, coordinate-system transfer, then undo

Sample 14 — Markup Shapes

InsertShell cube and pyramid, leader line, delete individually by ID

Sample 15 — Edge Picker

SelectEdge, length, end points, straight or curved with radius, highlight

Tools

Probe — Return Values is a diagnostic script rather than a sample. It prints the type and members of the results that the reference didn’t document. It has been run once, and its findings are on the Classes page. Re-run it after a SpinFire upgrade to check for changes.

Things to Know

  • Result objects (sample 02). The ...Data return types are .NET objects, printed with str(). Pull out specific fields once you know their names.

  • Return values (samples 10, 12, 14, 15). These samples now read the fields the probe confirmed. SelectItem returns a Failed to get child item… message for a bad path. InsertLine and InsertShell results carry the new shape’s ID. SelectEdge returns an Edge with Points. GetSectionCutEdges returns a result with CutPlaneEdges and ErrorMessage.

  • Section planes (samples 03, 12). ToggleSinglePlane turns on the YZ plane, which moves along X, so sample 03 now sweeps YZ. Toggles flip the current state, so start with section planes off.

  • Still unconfirmed: what SelectPoint returns (samples 05 and 14 still try several forms) and which pair of planes ToggleTwoPlanes turns on.

  • Sample 13 changes the model. It undoes its own transforms by default (UNDO = True), but don’t save the file partway through.