Skip to content

Getting Started with Custom ERC Checks

Custom ERC Check lets you run your own Python-based Electrical Rule Check logic against project data from Altium 365.

This page is the starting point for workspace admins who want to:

  • understand the execution model of a custom ERC script
  • load project data such as components, pins, nets, and parameters
  • report rule violations in Altium 365
  • build a first working script and then extend it into a real production rule

For the complete reference, see:

How a Custom ERC Script Works

Each custom ERC script must define an onExecute(context, input_parameters) function.

At runtime, the platform calls this function and expects it to return a ValidationResult containing any violations found.

  1. Loads design data for the current project.
  2. Applies one or more validation rules.
  3. Adds violations to the result and returns it.

How to Add Your First Custom Script

Note: Before creating your first script, make sure your organization has a valid license for Custom ERC Checks.

To add a new custom ERC script in Altium 365:

  1. Open Admin.
  2. Go to Customization.
  3. Select the Electrical Rule Checks tab.
  4. Click Add.
  5. Enter a name for the new ERC check.
  6. In the Assigned column, click Assign and then select Create Script.

Custom ERC check creation dialog

The script editor opens with a default ERC script template. Save the script, then use Test Run to execute it.

When prompted, enter the target project ID, for example 35F834EB-D99C-4833-ABAC-B2217332896F.

Test Run project prompt

While the script is running, use these tabs in the editor to inspect the result:

  • Console: developer-oriented output for progress tracking and debugging
  • Response: execution result, including the violations detected for the selected project

Console and Response tabs in Test Run output

Minimal Template

Use the following script as a starting point:

from altium import ExecutionContext
from altium_api import load_project_data, ValidationResult, ProjectData


def _sample_erc_check(project_data: ProjectData) -> ValidationResult:
    """Example of check for developing ERC scripts.

    Args:
        project_data: Access to project data like nets, components, and pins.

    Returns:
        ValidationResult: Contains the violations identified by the function.
    """

    print(f"Sample template check started: components={len(project_data.components)}")

    validation_result = ValidationResult()

    if project_data.components:
        validation_result.add_violation(
            "Example validation violation (template example)",
            project_data.components[0],
        )
    else:
        print("No components found, so the sample violation was skipped")

    return validation_result


def onExecute(context: ExecutionContext, input_parameters: dict) -> ValidationResult:
    """Template entrypoint to start developing custom scripts.

    Args:
        context: Connection execution context for Altium 365.
        input_parameters: Script input parameters used by load_project_data.

    Returns:
        ValidationResult: Contains the violations recognized by the script.
    """

    print("Fetching design data")
    project_data = load_project_data(context, input_parameters)

    validation_result = _sample_erc_check(project_data)

    return validation_result

Understand the Building Blocks

onExecute

This is the required entrypoint.

  • context is provided by the platform and is used when the script loads project data.
  • input_parameters contains the project information needed to load the design data.
  • the function must return ValidationResult

If your script does not expose onExecute, or returns the wrong type, it will not behave as a valid custom ERC check.

load_project_data

load_project_data(context, input_parameters) is the standard way to fetch project information before running your rule logic.

It returns a ProjectData object, which gives access to the design model used by your script.

ValidationResult

Use ValidationResult to accumulate rule violations.

The typical pattern is:

result = ValidationResult()
result.add_violation("Description of the issue", related_object)
return result

The related object should be a supported design object such as a component, net or pin.

Main APIs to Learn First

When writing custom ERC checks, the two most important API areas are design_data and utils.

design_data

The design_data module defines the project model your script works with. You will usually access these types through altium_api.

Start with these concepts:

  • ProjectData: root object for the loaded design
  • Component: logical schematic component, with designator, comment, description, parameters, and pins
  • Net: electrical connection with a name and connected items
  • Pin: pin-level access, including connected net and owning component
  • Parameter: name/value parameter attached to a design object

Typical examples:

for component in project_data.components:
    print(component.designator, component.comment)

for net in project_data.nets:
    print(net.name)

Use Altium API as the main reference for ProjectData and related design objects.

utils.py

The utils module contains helper functions and constants that are useful when building rules. These helpers reduce boilerplate and keep checks focused on validation logic instead of string parsing or component classification.

Examples of what utils can help with:

  • classify a component by function
  • determine whether a net is power, ground, chassis, or USB
  • read and parse parameter values
  • infer capacitance or voltage-related values from design metadata

Example:

from altium_api import utils


def find_ground_nets(project_data: ProjectData) -> list[str]:
    return [net.name for net in project_data.nets if utils.is_ground_net(net)]

Use Utilities when you need reusable helpers before implementing custom parsing or matching logic yourself.

A Practical Development Flow

The simplest way to build a custom ERC rule is to start small and iterate:

  1. Copy the minimal template.
  2. Load the project with load_project_data.
  3. Pick one narrow rule, for example checking a parameter, net name, or component classification.
  4. Add violations with a clear message and the design object that caused the issue.
  5. Expand the script once the first rule produces the expected output.

Example of a more realistic validation loop:

from altium import ExecutionContext
from altium_api import load_project_data, ValidationResult, ProjectData, utils


def check_missing_voltage(project_data: ProjectData) -> ValidationResult:
    result = ValidationResult()

    for component in project_data.components:
        if utils.classify_component(component) == utils.ComponentClassification.IC:
            voltage = utils.get_param_value(component, "Voltage")
            if not voltage:
                result.add_violation(
                    f"Missing Voltage parameter on {component.designator}",
                    component,
                )

    return result


def onExecute(context: ExecutionContext, input_parameters: dict) -> ValidationResult:
    project_data = load_project_data(context, input_parameters)
    return check_missing_voltage(project_data)

Good Practices for Customer Scripts

  • Keep onExecute small and move rule logic into helper functions.
  • Start with one rule per function so behavior stays easy to test and review.
  • Use print() for quick debugging output in the Console tab while developing.
  • Prefer helper functions from utils before adding custom heuristics.
  • Attach each violation to the most relevant design object so the result is actionable.
  • Return an empty ValidationResult when no violations are found.

Once the template is clear, continue with these pages:

  • Altium API: public API surface, including ProjectData, Component, Net, and load_project_data
  • Utilities: helper functions and constants for common ERC patterns
  • Checks API: reference for ValidationResult
  • Documentation Home: docs landing page

These references are intended to be used alongside this getting-started guide: start here for the workflow, then use the API pages while implementing real checks.

🔧