Skip to content

Scripting API

Gems list CSV

from ArtisanPlugin.Scripting import DraftingApi as drafting

The stone list the buyer and the setter both need, as a file rather than as drawing: every distinct gem in the piece with its shape, dimensions, carat weight and how many of it there are. The tool walks the document’s gems, groups identical stones and counts them, then writes the result as a semicolon-delimited CSV - the ArtisanGemsListToExcel command without its save-file dialog.

Usage

written = drafting.ExportGemsList(path, onlySelection = False, useSystemDecimals = False)
ParameterDefaultMeaning
path-Destination file. .csv is appended when the extension is missing
onlySelectionFalseTrue = only the currently selected gems; False = every visible gem in the document
useSystemDecimalsFalseFalse = invariant formatting, decimal point (the command’s “Force Point”); True = the system’s decimal separator, e.g. a comma on a Spanish machine

Returns the full path actually written, as a string - use it rather than the path you passed in, since the tool normalises it.

The file

One header line followed by one line per distinct gem, separator ;, no quoting:

Shape;Size X;Size Y;Carats;Quantity;Total Carats
ColumnContents
ShapeThe gem shape, as the kernel names it
Size X, Size YThe stone’s two dimensions in millimetres, up to three decimals
CaratsCarat weight of a single stone, rounded to three decimals
QuantityHow many identical stones were grouped into this row
Total CaratsThe rounded single-stone carats multiplied by Quantity

Total Carats is computed from the already rounded per-stone value, so it matches the printed Carats column exactly rather than the full-precision weight.

Identical stones are grouped and counted by the same rule the command uses; hidden gems are skipped unless you are exporting the selection.

Path handling

The path is resolved to an absolute one first, so a relative path lands wherever Rhino’s working directory is - pass an absolute path if that matters. If the extension is not .csv (case-insensitively) then .csv is appended - "C:\out\gems" becomes "C:\out\gems.csv", and "C:\out\gems.txt" becomes "C:\out\gems.txt.csv". Missing folders in the path are created. An existing file is overwritten without warning.

Errors

Throws InvalidOperationException “No active document.” with no document open, and ArgumentException “A destination file path is required.” when path is null, empty or whitespace.

Writing a file is not a document mutation, so no Transaction is needed here.