Skip to content

Scripting API

Box dimensions

from ArtisanPlugin.Scripting import DraftingApi as drafting

The overall envelope of a piece, the three numbers a caster or a packer needs: how wide, how deep, how tall. The objects you pass are meshed together at low resolution, and three linear dimensions are drawn around the resulting global bounding box. It is the ArtisanGenerateDimensionsByBox command with its selection prompt and its two options turned into arguments.

Usage

drafting.GenerateDimensionsByBox(objectIds, offset = 2.0, addBox = False)
ParameterDefaultMeaning
objectIdsThe objects to dimension, the command’s selection. At least one id is required; there is no fallback to the viewport selection
offset2.0Gap in millimetres between the geometry and the dimension lines, the command’s Offset option. Valid from 0 to 100
addBoxFalseTrue also adds the bounding box itself to the document as a Brep, the command’s Box option

offset has no “keep the default” sentinel: 0 means a zero gap, with the dimension lines flush against the box.

What it puts in the document

The three dimensions are placed against the bounding box of the analysis mesh:

  • Width in X, above the model — the dimension plane sits at the box’s maximum Y and maximum Z, with the dimension line offset beyond it.
  • Depth in Y, at the model’s right — the plane is rotated a quarter turn about Z and translated by offset.
  • Height in Z, at the model’s front — measured in the YZ plane, so it is the model’s real height, not a projected one.

Three other objects are left behind, exactly as the command leaves them:

  • The low-resolution analysis mesh used for the measurement, added as an ordinary mesh object.
  • A marker point at the origin of the depth dimension’s plane.
  • The bounding-box Brep, when addBox = True.

Delete the mesh and the point afterwards if you only wanted the annotations. Everything goes on the current layer, with the document’s current dimension style — unlike Ring dimensions, this method does not touch the style.

Each dimension is added only if it comes out geometrically valid, so a degenerate span — a perfectly flat plate has no height — is silently dropped rather than raising. Fewer than three dimensions is a normal outcome, not an error.

The return value

GenerateDimensionsByBox returns nothing (void). To find out what it produced, capture the document’s object ids before and after and take the difference:

import Rhino
from ArtisanPlugin.Scripting import DraftingApi as drafting, Transaction

doc = Rhino.RhinoDoc.ActiveDoc
before = set(o.Id for o in doc.Objects)

with Transaction.Begin("Box dimensions"):
    drafting.GenerateDimensionsByBox(ids, offset = 3.0, addBox = True)

created = [o for o in doc.Objects if o.Id not in before]

The Transaction is worth having anyway: it collapses the mesh, the point, the box and the dimensions into a single undo step.

Validation

Failures are exceptions, not a False:

ConditionError
No document openNo active document.
offset below 0 or above 100Offset must be between 0 and 100. (an ArgumentOutOfRangeException)
objectIds empty or NoneAt least one object id is required.
The objects cannot be meshed at low resolutionUnable to generate dimensions from the given objects.

Unlike the command, nothing pops a dialog: the meshing failure the command reports in a message box comes back here as a plain exception, so the method is safe to run unattended.