← LibrarySolidWorks Custom Properties and Configurations Through the APIEngineering · ComputersLesson 8/10← PrevNext →
ArticlePublished 4 Aug 20268 min readBy Kevin JoginSolidWorks APIcustom propertiesconfigurationsmetadata

Engineering / Computers / Part 7 of 9

Custom Properties & Configurations

Custom properties are where CAD meets the rest of the business. Part numbers, materials, finishes, revisions and project codes flow from here into bills of materials, drawings, purchasing and the ERP system. It is the least glamorous corner of the API and, in most organisations, by some distance the most valuable.

  • Part 7 · Applied
  • Document vs configuration
  • Raw vs evaluated
  • Schema governance

KL-ENG-COMP-1507 · KEVOS® Knowledge Library · Australian English

A property that is wrong in a model is wrong in the bill of materials, on the drawing, in the purchase order and in the ERP record. Errors here propagate further than geometry errors and are caught later. Automation that audits and enforces a property schema pays back faster than almost anything else you can build.

2Scopes — document-level and configuration-specific
2Values per property — raw expression and evaluated result
1Schema, ideally, controlled like any other engineering standard

01Two scopes, and why the distinction matters

Properties exist at two levels, and confusing them is the most common defect in property automation.

Document-level properties Belong to the file as a whole. Appropriate for anything true of every configuration — drawn-by, project code, source standard, design authority.
Configuration-specific properties Belong to one configuration. Appropriate for anything that varies between them — part number, description, length, mass, finish. In a family of sizes this is almost everything that matters.
Cut-list properties A third scope in weldments and sheet metal, attached to cut-list folders. Reached through the folder feature rather than the document, and easy to miss entirely when auditing a weldment.

The manager is obtained from the document extension, naming the configuration you want. An empty string returns the document-level manager; a configuration name returns that configuration's.

C#both scopes, and every configuration
ICustomPropertyManager docProps =
    swModel.Extension.get_CustomPropertyManager("");          // document level

foreach (string configName in (string[])swModel.GetConfigurationNames())
{
    ICustomPropertyManager cfgProps =
        swModel.Extension.get_CustomPropertyManager(configName);
    // ... audit or update this configuration
}
The classic audit failure

A tool that checks only document-level properties will report a perfectly configured family of parts as having no part numbers at all, because the part numbers are configuration-specific. Always audit both scopes, and report which scope each result came from.

02Reading properties

Every property has two values, and the difference between them is the source of most confusion.

The raw value

What is stored — which may be a literal string, or an expression linking to a dimension, a mass property or another property. This is what you must preserve if you rewrite a property you did not author.

The evaluated value

What the expression currently resolves to. This is what appears on the drawing and in the bill of materials, and it is what an audit should compare against a requirement.

The current read call returns both, together with flags indicating whether the value resolved and whether it is linked. A cached option controls whether values come from stored data or are re-evaluated; cached reads are faster across many configurations, and non-cached reads are correct when something has just changed.

Get6
Reads one property by name, returning raw and evaluated values plus resolution and link flags. Earlier numbered variants remain in older releases.
GetAll3
Reads everything at once as parallel arrays — names, types, values, evaluated values and link flags. Far faster than repeated single reads.
GetNames
Just the names. Enough for an existence audit and the cheapest call of the three.
Count
How many properties exist in this scope.
Existence checking

There is no dedicated "does this property exist" call. Read the names and test membership, or attempt a read and interpret the result. Checking against the name list is clearer and avoids relying on the failure behaviour of a read.

03Writing properties

Two calls write, and choosing between them correctly avoids most of the trouble in property automation.

Choosing between the add and set operations
Add3Set2
Property does not existCreates itFails
Property existsBehaviour follows the add option suppliedUpdates the value
Type is specifiedYes — text, date, number, yes/no or doubleNo — keeps the existing type
Use whenYou cannot be certain the property existsYou have already confirmed it exists and the type is right

The add call takes an option controlling what happens when the property already exists — replace the value, create only if new, or delete and recreate. That option is the real behaviour switch, and it should be chosen deliberately for each tool rather than copied from an example.

C#write, then check the result code
int result = cfgProps.Add3(
    "PartNumber",
    (int)swCustomInfoType_e.swCustomInfoText,
    "KV-1042-03",
    (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue);

if (result != (int)swCustomInfoAddResult_e.swCustomInfoAddResult_AddedOrChanged)
    log.Add($"property write failed, code {result}");
Type mismatches fail quietly

The result code distinguishes success from a generic failure and from a type mismatch against either the existing property or the type you specified. Code that ignores the return value will report a successful run over a hundred files while having changed nothing. Test it, log it, and count the failures in your summary.

Do not overwrite a linked expression

Writing a literal over a property whose raw value was an expression destroys the link silently. If a tool may encounter authored expressions, read the raw value first and skip anything that is linked unless breaking the link is the explicit purpose of the tool.

04Deleting, and the discipline around it

Deletion is a single call taking the property name, in whichever scope's manager you are holding. The technical part is trivial; the operational part is not.

  • Report before you delete. Run the tool in a reporting mode first and circulate the list. Properties nobody recognises are often relied upon by a downstream system nobody remembers configuring.
  • Delete from the right scope. Deleting a document-level property does not remove a configuration-specific property of the same name, and the visible result may not change at all.
  • Record what was removed. Name, scope, raw value and file, written to a log. This is the only route back if a deletion turns out to have been wrong.
  • Never delete on a partial match. Name comparison should be exact and case-defined. A prefix rule will eventually catch something it should not.
Bulk deletion is irreversible

There is no undo across a batch of files. A tool that deletes properties across a directory tree should be treated as a data-migration operation: dry run, review, backup, execute, verify. If that sounds disproportionate, consider what a wrongly removed part number costs once it has reached a purchase order.

05A property audit tool

The highest-return tool most engineering businesses can build. It reads everything, changes nothing, and produces a defect list that funds everything after it.

1Define the schemaWhich properties are required, in which scope, with which type and permitted values.
2TraverseWalk the assembly using Part 6 and visit every unique component document.
3Read both scopesDocument-level and every configuration — and cut-list folders in weldments.
4CompareMissing, empty, wrong type, value outside the permitted list, or unexpectedly linked.
5ReportOne row per exception, with file, scope, property, found value and expected condition.
Exception classes worth separating in the report
ClassMeaningUsual response
MissingRequired property absent from the scopeAdd it — the safest automated correction
EmptyPresent but blankNeeds a human; the value is not derivable
Wrong scopePresent, but at document level where the schema requires configuration levelMove it, preserving the value
Wrong typeText where a number is required, or the reverseRecreate with the correct type, preserving the value
Not permittedValue outside the controlled listReview; often reveals a list that needs extending
Unresolved linkExpression that no longer evaluatesInvestigate — usually a renamed dimension or deleted feature
Separate finding from fixing

Build the audit as its own tool and keep it that way. A corrective tool can consume its output, but the two should remain separable so the audit can be run at any time by anyone, including on files nobody wants modified.

06Treat the schema as a controlled document

The technical work here is straightforward. What makes property automation succeed or fail is whether the organisation has agreed what the properties are.

Write the schema down

Name, scope, type, whether it is mandatory, permitted values, and which downstream system consumes it. One table. Without it, every tool encodes a different opinion.

Fix the names first

Property names are matched exactly. A schema containing both a singular and a plural form of the same idea guarantees permanent inconsistency.

Name the consumer

Recording which system reads each property tells you what a change will break, and stops properties nobody uses accumulating indefinitely.

Version it

When the schema changes, existing files do not. A version marker in the schema, and a migration plan, prevent an audit reporting thousands of false exceptions.

Put it in the templates

Properties present in the part, assembly and drawing templates cost nothing to maintain and remove the largest source of missing-property exceptions at the origin.

Audit continuously

A weekly scheduled run that emails the exception count turns data quality into a tracked measure rather than a periodic crisis.

07Quick reference

IModelDocExtension::CustomPropertyManager
Returns the manager for a named configuration; an empty string gives the document-level manager.
IModelDoc2::GetConfigurationNames
Every configuration name — the loop for a full property audit.
ICustomPropertyManager::Add3
Creates or updates a property with an explicit type and an add option. Returns a result code.
ICustomPropertyManager::Set2
Updates an existing property. Fails where it does not exist or the type disagrees.
ICustomPropertyManager::Get6
Reads raw and evaluated values plus resolution and link flags. Earlier numbered variants exist.
ICustomPropertyManager::GetAll3
Reads every property at once as parallel arrays. Preferred for auditing.
ICustomPropertyManager::GetNames
Names only — sufficient and cheapest for existence checks.
ICustomPropertyManager::Delete2
Removes a property by exact name from the current scope.
ICustomPropertyManager::Count
Number of properties in the scope.
swCustomInfoType_e
Text, date, number, yes/no and double.
swCustomPropertyAddOption_e
Replace the value, create only if new, or delete and recreate.
swCustomInfoAddResult_e
Result codes distinguishing success from generic and type-mismatch failures.

Continue learning

Traversing SolidWorks Assemblies and Feature TreesArticle · ComputersNEXT LESSON →SolidWorks Drawing Automation: Creation, Views and PrintingArticle · ComputersSolidWorks PropertyManager Pages: Building Native User InterfaceArticle · ComputersSolidWorks Add-ins: Structure, Registration and DeploymentArticle · Computers