Scripting API
Global thickness
from ArtisanPlugin.Scripting import AnalyzeApi as analyze
Where ThicknessAt answers “how thick is it here”, GlobalThickness answers “where is this piece thinnest”. It meshes the objects at high resolution and measures the wall thickness at every vertex of that analysis mesh, giving you the statistics and the list of offending spots that the ArtisanGlobalThickness command can only paint on screen. This is the pre-casting check: run it over a finished ring, get the minimum wall and the percentage of the surface below your foundry’s limit, and decide whether to thicken before you export.
Usage
r = analyze.GlobalThickness(objectIds, thinThresholdMm = 0, colorize = False)
| Parameter | Default | Meaning |
|---|---|---|
objectIds | - | Objects to analyse; meshed together on every call |
thinThresholdMm | 0 -> tool default 0.6 | Walls thinner than this count as thin spots, mm. 0 keeps the command’s default of 0.6 mm |
colorize | False | True also adds a vertex-coloured copy of the analysis mesh to the document |
All values in and out are millimetres. Per the house convention, 0 for the threshold means “keep the tool default” - it does not mean “no threshold”. A negative threshold throws ArgumentOutOfRangeException with "Threshold must be >= 0.".
What comes back
GlobalThicknessResult:
| Field | Meaning |
|---|---|
MinMm | Thinnest measured wall, mm. 0 when nothing was measurable |
MaxMm | Thickest measured wall, mm |
AverageMm | Mean over the measurable samples, mm. 0 when nothing was measurable |
SampleCount | Number of mesh vertices that produced a valid measurement |
UnmeasurableCount | Number of vertices where no opposite wall was found |
ThinPercentage | Percentage of the measurable samples below the threshold - the figure the command prints on the command line. Note the denominator is SampleCount, not the total vertex count |
MeshId | Guid of the colourised mesh when colorize = True, otherwise Guid.Empty |
ThinSpots | The measurable vertices below the threshold, thinnest first, capped at the worst 100 |
Each entry of ThinSpots is a ThinSpot:
| Field | Meaning |
|---|---|
Point | The vertex position on the analysis mesh, as a Point3d |
ThicknessMm | The wall thickness measured there, mm |
The cap matters: if a piece has thousands of thin vertices, ThinSpots still holds only 100 of them. Use ThinPercentage and SampleCount to judge how widespread the problem is, and ThinSpots to find where to start.
Does it mutate the document?
With colorize = False - the default - no. It is a pure measurement: nothing is added, nothing is changed, no licence is checked, and MeshId comes back as Guid.Empty.
With colorize = True it adds one mesh object to the document: a duplicate of the analysis mesh carrying one vertex colour per vertex, in the command’s own palette - red for thin, green for acceptable, black for vertices where no wall could be measured. This is the same mesh the command’s KeepMesh = Yes exit leaves behind. It is a document mutation, so wrap the call in a Transaction, and expect a licence check: colorize = True calls the licence gate up front and fails the whole call if the licence is invalid. The views are redrawn once the mesh is added.
To be plain about the old wording: the call produces stats and thin spots always, and the colorised mesh only when you ask for it.
from ArtisanPlugin.Scripting import AnalyzeApi as analyze, Transaction
with Transaction.Begin("Global thickness"):
r = analyze.GlobalThickness(ids, thinThresholdMm = 0.8, colorize = True)
print("min %.2f mm, %.1f%% thin over %d samples" % (r.MinMm, r.ThinPercentage, r.SampleCount))
for s in r.ThinSpots[:5]:
print(round(s.ThicknessMm, 2), s.Point)
Delete the mesh by its MeshId when you are done with it - it is an ordinary document object.
Cost and errors
This is a long operation on dense geometry: one ray cast per vertex of a high-resolution mesh. A full ring with pavé can take a noticeable while, and the mesh is rebuilt on every call, so measure once and reuse the result rather than calling it in a loop.
It throws:
InvalidOperationException-"No active document."ArgumentOutOfRangeException-"Threshold must be >= 0."ArgumentException-"At least one object id is required."InvalidOperationException-"Could not build an analysis mesh from the given objects."