Documentation
Go to AppSign InSign Up
    Getting Started
    • Introduction to Flux
    • What is Flux?
    • Quick Start
    • The Flux Method
    • Creating an Account
    • Flux for Organizations
    • Setting Up Your Browser
      • Mouse & Trackpad
      • Multi-Screen Operation
      • Keyboard Shortcuts
    • Your First PCB in Flux
      • DFM & Export
      • PCB Layout & Routing
      • Project Setup
      • Schematic
      • Export & Manufacturing
    • KiCAD to Flux
      • Layout
      • Parts & Libraries
      • Schematics
    • Eagle to Flux
    • EasyEDA to Flux
    • Upverter to Flux
    • Altium to Flux
    • Getting Help
    Tutorials
    • Tutorials
    • Getting Started With Flux
      • Customizing Flux
    • Flux Use Cases
      • AI Architecture Design
      • AI Component Research
      • AI Design Reviews
      • AI Testing & Debugging
      • AI Auto-Layout
      • Generative AI
    • Start Learning Flux, No Matter Your Skill Level
      • Advanced Designer
      • First Time Designer
      • Intermediate Designer
    • Power Regulator
      • 1 – Part Selection
      • 2 – PCB Layout
      • 2 – Schematics
    • Routing
      • High-speed Routing
      • High Density Designs (HDI)
      • Working with Polygons
    • Adding Components to the Library
      • Publishing Components to the Library
      • Creating Components from Scratch
      • Importing Components
      • Working with Footprints
      • Working with Symbols
    • What is a Module?
      • Module Design Best Practices
      • Creating Modules
      • Using Modules
    • Generic Components
      • Creating a generic part
    • Copper Fills Tutorial
      • Creating Copper Cutouts
    • Board Outline Shape and Size
    • The Toolbar
    • Using Layout Rules
    • Intro to collaboration
    • Embedding a Flux Project
    • Reviewing component updates
    • Version Control Deep Dive
    • Custom Shapes
    • AI-Assisted Design with Flux
    • PCB Design Reviews (DRC)
    • Component Placement
    • Component Procurement
    • Multi-Layer PCB Design
    • Working with Ground Signals
    • Reusing Projects
      • Useful links
    Reference
    • Flux Context Menu
    • Calculator Tool
    • Change Project Name
    • Code Tool
    • Convert to component
    • Flux ACUs
    • Overview
    • Data Portability
    • Delete & Archive Projects
    • Design Rule Check (DRC)
    • Expressions
    • File Tool
    • FMEA Report Generation
    • Gerber Exports
    • Help Tool
    • Special Part Types
    • JEP30 PartModel Import/Export
    • Knowledge Base
    • Library Tool
    • Managing Units
    • Measuring Distances
    • Model Selection
    • Nets and Traces
      • Curved Traces
      • Impedance Control
      • Trace Width
    • Object Types
      • AssetNode
      • ControlNode
      • ElementNode
      • ElementTerminalNode
      • OutputNode
      • PropertyNode
      • RouteNode
      • RouteTerminalNode
    • Pads & Holes
    • Passive Component Consolidation
    • Layout Rules Reference
      • Layout Rules List
      • Object-Specific Layout Rules
      • Selector-Based Layout Rules
      • Layout Rules Inheritance & Precedence
      • Layout Rules Modifiers
    • Polygons
    • Comments
    • Cursors
    • Forking & Cloning
    • Copper Fills
    • Importing Schematics
    • Importing Components
    • Schematic Inspector
      • Assets Panel
      • Pricing & Availability Panel
      • Properties Panel
      • Simulation Panel
    • The Library
    • Project Launcher
      • New Blank Project
    • Layout Object Tree
      • PCB Object Types
    • Schematic Object List
    • The PCB Editor
      • Locking
      • Layer View Control
      • Positioning & Routing
      • Selecting Objects
      • Stackup Editor
    • Permission Tiers
    • Preloaded Examples
    • The Profile Page
      • Featured Projects
    • The Schematic Editor
      • Positioning & Wiring
    • Global Search
    • Sharing & Permissions
    • History & Version Control
    • Silkscreen
    • Simulator Tool
    • Star a Project (Favorite)
    • Vias
      • Smart Vias
    Copilot
    • Copilot Overview
    • Model Selection
    • Flux ACUs
    • Knowledge Base
    • Flux Context Menu
    • Calculator Tool
    • Code Tool
    • File Tool
    • Help Tool
    • Library Tool
    • Simulator Tool
    • FMEA Report Generation
    • Passive Component Consolidation
    FAQ
    • Schematic Editor
    • General FAQs
    • Flux and AI FAQs
    • PCB Editor FAQs
    • Parts and Modules
    • Pricing
    • Private and public projects
    • Data security and IP protection
    • When things go wrong: Errors and how to handle them
      • Lost connection
    Legal
    • Terms of Service
    • Privacy Statement
    • Main Services Agreement
    • Subprocessors

Reference

Expressions

Reference

Expressions


Flux features a powerful math expression engine within the Code editor, properties, and PCB layout rules that give it spreadsheet-like superpowers.

Overview

Expressions allow you to input math functions as values in many different contexts, including the Code editor, object properties and object rules. Learn how to leverage expressions to create faster and more efficient designs.

Getting Started

In this document, we'll cover the different use-cases where you can incorporate expressions:

  • What is an Expression? learn how to integrate expressions in your project
  • Expression Results: learn how Flux shows the result of an expression
  • Basic expressions: learn how to create basic math operations and unit management.
  • Advanced expressions: learn how to work with more advanced math functions and expressions.
  • Functions: learn how to use Flux-specific additional functions.
  • Accessing object data: learn how to access properties and rules inside objects.
  • Accessing project data: learn how to access project data like a URL or description

What is an Expression?

An expression is a way to input dynamic data into a property or rule. The expression will be evaluated in real time to calculate the value of the property or rule. Let's consider the following example:

Example: Position Rule

An element's position can be defined by modifying the "Position Y" rule. The normal way would be to simply type the final position in the rule, for example 20mm

Using an expression, we could calculate the "Position Y" rule based on another rule, like "Position X". It would look like this:

Expression Results

The result of the expression will be shown right below whenever possible. This is usually the case when using expressions in properties or object-specific rules, as there is always a single result for the expression.

But when using an expression on a selector-based rule, there could be multiple results. In that case, Flux won't show the result of the expression. You will see the Outputs multiple values legend instead.

Basic Expressions

//////// Expressions with units ////////
//Example 1 - Basic unit workflow
= 12mV
//This example returns: 0.012 


// Example 2 - Convert units
= 22ohm to mOhm
//This example returns: 0.000022


//Example 3 - Flux uses default units if none are specified
= 22mm + 1
//This example returns: 1.866142inches

//////// Expressions with basic math ////////
//Example 4 - Basic Math
= 22deg * 2
//This example returns: 44deg

Advanced Expressions

Flux supports most of the Math.js expressions syntax.

//////// Working with advanced math formulas ////////
// Example 1 - Sine function
= sin(45 deg)
// This example returns: 0.7071067811865475

// Example 2 - Mixed math and units
= 9.81 m/s^2 * 5 s to mi/h
// This example returns: 109.72172512527


//////// Working with strings ////////
// Example 1 - Strings can be used in the evaluate function, to parse expressions inside the expression parser
= evaluate("2 + 3")
//This example returns: 5

Flux-specific Function Helpers

We've added a few additional electronics-oriented functions that you might find useful.

//////// Working with the Function ledBallast ////////
// Example 1 - Calculate the current-limiting resistor necessary for a 0.02A current flow and 2.9V voltage drop (Vsupply - Vforward)
= ledBallast(0.02, 2.9) 
//This example returns: 145ohm


//////// Calculating E series values for resistors ////////
//////// Available functions: toE6, toE12, toE24, toE48, toE96 and toE192 ////////
// Example 2 - Round 17 to nearst E6 type Resistor 
= toE6(17)
//This example returns: 15

Accessing Object Data

Accessing object data differs depending on if you're trying to access the data from within a layout rule or an object property.

Accessing Object Data from a Rule

If you're trying to access object data within a layout rule, the .thisdirective will have the following structure:

this: {
    uid: string;
    parentUid: string;
    type: string;
    designator: string;
    rules: {[key: string]: PcbLayoutRuleValue};
    activeRules: {[key: string]: PcbLayoutRuleValue};
    bakedRules?: IPcbLayoutBakedData;
    
    // element represents the associated element the node belongs to
    element?: {
        designator?: string;
        defaultPropertyValue?: string;
        properties: {[pascalCasePropertyName: string]: PropertyValues};
        part: {
            name?: string;
            url?: string;
        };
    };

Examples

// Example 1 - Get the objects uid
= this.uid
// This example returns: "<your objects uid>"

// Example 2 - Get the objects type
= this.type
// This example returns: "element"

// Example 3 - Get the objects position rule
= this.rules.position
// This example returns: "12mm 3mm"

// Example 4 - Get an object's element property called ManufacturerPartNumber
// property names will be convert to Pascal case. eg. "My property name" becomes "MyPropertyName"
= this.element.properties.ManufacturerPartNumber
// This example returns: "<Manufacturar Part Number>"

// Example 5 - get the objects element part name
= this.element.part.name
// This example returns: "Samsung Resistor"

Accessing Object Data from a Property

If you're trying to access object data within a property, the .thisdirective will have the following structure:

this: {
    designator?: string;
    defaultPropertyValue?: string;
    properties: {[pascalCasePropertyName: string]: PropertyValues};
    part: {
        name?: string;
        url?: string;
    };
   
    // Careful, not all elements have an associated node
    node?: {
       uid: string;
       parentUid: string;
       type: string;
       designator: string;
       rules: {[key: string]: PcbLayoutRuleValue};
       activeRules: {[key: string]: PcbLayoutRuleValue};
       bakedRules?: IPcbLayoutBakedData;
    };
}

Examples

// Example 1 - Get the object's designator
= this.designator
// This example returns: "<your objects designator>"

// Example 2 - Get an object's property called ManufacturerPartNumber
// Property names will be convert to Pascal case. eg. "My property name" becomes "MyPropertyName"
= this.properties.ManufacturerPartNumber
// This example returns: "<Manufacturar Part Number>"

// Example 3 - Get the object's node UID
= this.node.uid
// This example returns: "<UID>"

// Example 4 - Get the object's node rule called Position
= this.node.rules.position
// This example returns: "<Element position>"

Accessing Project Data

Project Data Schema

project: {
  	name: string;
    description: string;
    properties: {[pascalCasePropertyName: string]: PropertyValues};
    url: string;
    slug: string;
    owner: {
        handle: string;
        url: string;
    };
    changeHistory: {
        currentChangeUid: string;
        currentChangeShortUid: string;
    };
}

Examples

// Example 1 - get the project's name
= project.name
// This example returns: <your projects name>

// Example 2 - get the project's description
= project.description

//returns <your projects description>
  
// Example 3 - get the project's properties
// property names will be convert to Pascal case. eg. "My property name" becomes "MyPropertyName"
= project.properties.MyPropertyName
// This example returns: <my properties value>

// Example 4 - get the project's url
= project.url
// This example returns: <url of the project>

// Example 4 - get the project's slug
= project.slug
// This example returns: <slug of the project>

Previous

Design Rule Check (DRC)

Next

File Tool