.swp macro

Write Mass Properties: mass and volume into properties

Measures the model and writes mass, volume, surface area and centre of mass into custom properties, so a BOM or a drawing note can read them. Parts and assemblies only — drawings have no geometry to...

Properties

PRT PartsASM Assemblies

Download Write Mass Properties.swp Get SwMacroFlow

Put the downloaded file in this folder, then open SwMacroFlow and choose it from the library.

%LOCALAPPDATA%\SwMacroFlow\macros

Runs per file — point the scope at a folder and it measures each document in turn.

Inputs

FieldPurpose
MassPropertyProperty to write the mass into. Defaults to Mass. Blank skips it.
VolumePropertyProperty for the volume. Blank skips it.
SurfaceAreaPropertyProperty for the surface area. Blank skips it.
CentreOfMassPropertyProperty for the centre of mass, written as x, y, z. Blank skips it.
UnitsKilograms and millimetres (default), Grams and millimetres, Kilograms and metres, or Pounds and inches.
DecimalsDigits after the decimal point. Defaults to 3.
ScopeActive configuration (default), File, or File and active configuration.

At least one property name must be filled in, or the macro reports that there is nothing to write.

Mass belongs to the configuration

A part with a Long and a Short configuration has two different masses. The values written are the ones for whichever configuration is active when the macro runs, which is why Scope defaults to the active configuration rather than the file-level store.

If you need every configuration's mass, that needs a macro that activates each one in turn and rebuilds — a different and much slower job than this one.

Units are converted, not read from the document

SOLIDWORKS is asked for system units — kilograms and metres — and the macro converts from there. The numbers therefore do not depend on how each document happens to have its units configured, which is what makes a folder of mixed documents come out consistent.

Volume and surface area follow the chosen length unit: Kilograms and millimetres writes mm³ and mm².

The decimal point is always a full stop

Format uses the machine's regional settings, so a German workstation would otherwise write 1,234 into a property — which a BOM or a downstream CSV then reads as two columns or as a thousands group. This macro detects the locale separator and normalises it to . every time.

Results

OutcomeMeaning
OKWritten and saved. Reports how many properties changed, and the mass.
WarningEvery value already matched what the document holds. Nothing was saved.
ErrorA drawing, read-only, never saved, no property names given, no solid bodies to measure, or the save failed.

Unchanged values are not rewritten. Re-running over a folder whose geometry has not moved saves nothing and dirties nothing — which matters, because a needless save changes every file's timestamp and, in a PDM system, every file's version.

Chaining

Place it before any export or BOM macro so the exported files carry the measured values. It saves the document, and does not close or rebuild it.

Pair it with Export Properties to CSV as the last link to get a weights table for the whole folder in one pass.