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
Open the model in SpinFire (samples 01 and 07 open files themselves).
Open the script in the script editor and edit the Settings block at the top.
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 |
|---|---|
|
|
Select by type, properties, physical properties, bounding box, text report |
|
Stepping the YZ section plane along X, projection area, screenshot and DXF profile per step |
|
Render mode, color and transparency presets |
|
|
|
|
|
Looping |
|
|
|
Create at a picked point, read the matrix, rename, rotate, show, activate |
|
Walk the tree by path with |
|
Hide all, show named items and parents, screenshot, show all again |
|
Two or three planes, per-plane offsets, tilt, cut edges, reset all |
|
Move, rotate, scale, mirror, coordinate-system transfer, then undo |
|
|
|
|
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
...Datareturn types are .NET objects, printed withstr(). 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.
SelectItemreturns a Failed to get child item… message for a bad path.InsertLineandInsertShellresults carry the new shape’sID.SelectEdgereturns anEdgewithPoints.GetSectionCutEdgesreturns a result withCutPlaneEdgesandErrorMessage.Section planes (samples 03, 12).
ToggleSinglePlaneturns 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
SelectPointreturns (samples 05 and 14 still try several forms) and which pair of planesToggleTwoPlanesturns on.Sample 13 changes the model. It undoes its own transforms by default (
UNDO = True), but don’t save the file partway through.