Selector-Based Layout Rules

As opposed to Object-Specific Layout Rules, selector-based rules can apply to more than one object. Selectors choose the objects that a rule applies to. The selector syntax is based on the CSS Selector Syntax. If you use other PCB design tools, selectors are similar to queries.

Adding a selector-based rule

Ask Flux to create a ruleset. Describe the objects that the rules apply to and the rule values.

Create a ruleset that sets the trace width of every net to 0.2 mm.
Create a ruleset for all pads of the connector J1 with a 0.25 mm keep out.
Create a ruleset that sets the font size of every designator text to 0.8 mm.

You can also do it in the editor.

To create a ruleset:

  • Navigate to the PCB editor of your project

  • Select the "Rules" tab in panel on the left of the screen

  • Choose the "New Ruleset" button and new item will appear underneath the project rules titled "New Ruleset"


Once you select that new ruleset, you will notice that a new panel appears on the right side of the canvas. This is where you will determine the selectors that determine what objects are affected and the rules that will apply to the objects

  • Select "Edit" under the "Layout Rules" section of the right-hand panel and then click "Add".

  • Add the rules that you wish to define in your currently selected ruleset.

  • Select the value for each of the added rules.

Highlighting

To help you understand what you're selecting, Flux will highlight objects that match your selector. Once you finish typing, bounding boxes will appear on the canvas and in the Objects list.


Case Sensitive

Selectors are case sensitive. For example, in the above screenshot, only trace will select all traces for you, but Trace will not select anything.

Selector types

Type Selector

Syntax

What it selects

objectname

Selects all objects that have the specified object type.

Example

This PCB project has two resistors and a trace. Since the object type of the resistors is element, the element selector is selecting them and applying a rule, which is rotating them. The trace, however, is unaffected, since it isn't an element type.


Info

You must use specific object types, such as layoutor trace. See a full list of all the object type.

Designator Selector

Syntax

What it selects

#idname

Selects an object based on the value of its designator. There should be only one object with a given designator in a project. This is similar to the CSS #id Selector.

Example: #R2 will match the object that has the designator "R2".


Note: Use unique designators. If both of these resistors have the designator "R2", #R2 selects both of them.


Property Selector

Selects all objects that have the specified property.

This kind of selector has different operations that let you customize selections.

  1. Direct Select

  2. Exact Value Match

  3. Partial Match - One word

  4. Partial Match - Whole word or followed by a hyphen

  5. Partial Match - Prefix

  6. Partial Match - Suffix

  7. Partial Match - Occurrence

  8. Configure case sensitivity for matching

1. Direct Select

Syntax

What is selects

[prop]

Selects objects that have a property named prop.

Details: Only properties with set values will be selected. For example, if you had a resistor with property "Resistance" but with an empty value, then [Resistance] does not select the resistor.


To select properties with multiple words, omit the spaces between the words. For example, to select objects that have set values for "Manufacturer Name" property, type [ManufacturerName] .


2. Exact Value Match

Syntax

What it selects

[prop="value"]

Selects objects that have a property named prop whose value is exactly value.

Example

Two resistors come from different manufacturers. To select only one of them:

  1. R1 with "Manufacturer Name" = "Microchip"

  2. R2 with "Manufacturer Name" = "Texas Instruments"

Typing [ManufacturerName="Texas Instruments"] will select R2.


If the value has multiple words, you must wrap it inside a double quote. However, if the value is a single word (i.e. with no space in between), you can omit the double quotes. For example, to select R1 in the above example, both selectors work:

  1. [ManufacturerName="Microchip"]

  2. [ManufacturerName=Microchip]

  3. Always wrap the value in double quotes, so that the value is distinct from the case sensitivity indicator (see the last two topics of this section below)

3. Partial Match - One word

Syntax

What it selects

[prop~="value"]

Selects objects that have a property named prop whose value contains value.

Example

Set up R1 and R2 as follows:

  1. R1 with "Manufacturer Name" = "Microchip"

  2. R2 with "Manufacturer Name" = "Texas Instruments"

Typing [ManufacturerName~="Texas"] will select R2 because "Texas Instruments" contains the word "Texas".


Important Notes:

  1. You must wrap the value in double quotes. In other words, [ManufacturerName~=Texas] might not always work.

  2. This syntax only matches complete words. So an incomplete word like ManufacturerName~="Texa"] won't select anything because "Texas Instruments" doesn't contain word "Texa".

4. Partial Match - Whole word or followed by a hyphen

Syntax

What it selects

[prop|="value"]

Selects objects that have a property named prop whose value can be exactly value or can begin with value immediately followed by a hyphen. It is often used for language subcode matches.

Example

Set up R1 and R2 as follows:

  1. R1 with "Manufacturer Name" = "Microchip", and no other properties

  2. R2 with

    1. "Manufacturer Name" = "Texas Instruments"

    2. "Manufacturer Part Number" = "N-123"

    3. "Datasheet URL" = "Texas" - just for demoing purpose

[ManufacturerName|="Texas"] will NOT select R2, because the value of "Manufacturer Name" is not "Texas"


[ManufacturerPartNumber|="N"] will select R2.


[DatasheetURL|="Texas"] will select R2.


Important Notes:

  1. You must wrap the value in double quotes. In other words, [DatasheetURL|=Texas] might not always work.

  2. The value has to be a whole word, either alone, or followed by a hyphen (-).

5. Partial Match - Prefix

Syntax

What it selects

[prop^="value"]

Selects objects that have a property named prop whose value is prefixed (preceded) by value.

Example

Set up R1 and R2 as follows:

  1. R1 with "Manufacturer Name" = "Microchip"

  2. R2 with "Manufacturer Name" = "Texas Instruments"

Then, [ManufacturerName^="Tex"] will select R2.


Important Notes

  1. Since this is a prefix match, it is not required to match the whole word. Any value that begins with the specified prefix will match.

  2. Spaces can be included in the prefix. For example, [ManufacturerName^="Texas "] will also select R2 in this case.

6. Partial Match - Suffix

Syntax

What this selects

[prop$="value"]

Selects objects with a property named prop whose value is suffixed (followed) by value.

Example

Set up R1 and R2 as follows:

  1. R1 with "Manufacturer Name" = "Microchip"

  2. R2 with "Manufacturer Name" = "Texas Instruments"

Then, [ManufacturerName$="ments"] will select R2.


Since this is a suffix match, it is not required to match the whole word. Any value ending with the specified suffix will match.

7. Partial Match - Occurrence

Syntax

What this selects

[prop*="value"]

Selects objects with a property named prop whose value contains at least one occurrence of value within the string.

Example

Set up R1 and R2 as follows:

  1. R1 with "Manufacturer Name" = "Microchip"

  2. R2 with "Manufacturer Name" = "Texas Instruments"

Then, [ManufacturerName*="c"] will select R1, because "Microchip" contains the letter "c".


Details

  1. Since this is an occurrence match, it is not required to match the whole word. Any value containing the specified string will match.

  2. Any length of value may be used. This example uses "c".

8. Configure case sensitivity for matching

Syntax

What this selects

[prop operator value i]

Adding an i (or I) before the closing bracket causes value to be compared case-insensitively (for characters within the ASCII range).

[prop operator value s]

Adding an s (or S) before the closing bracket causes value to be compared case-sensitively (for characters within the ASCII range).

Explanation

By default, value matches are case sensitive. For example, set up R1 and R2 as follows:

  1. R1 with "Manufacturer Name" = "Microchip"

  2. R2 with "Manufacturer Name" = "Texas Instruments"

[ManufacturerName*="i"] will only match R1 but not R2. R2 has an uppercase letter "I", which does not match. And because this is the default setting, [ManufacturerName*="i"] is equivalent to [ManufacturerName*="i"s] .


If you add an "i" at the end, [ManufacturerName*="i"i] will select both R1 and R2.



Grouping Selectors

Selector List

Syntax

What this selects

A, B

The , selector is a grouping method that selects all the matching objects.

Example

Set up R1 and R2 as follows:

  1. R1 with "Manufacturer Name" = "Microchip"

  2. R2 with "Manufacturer Name" = "Texas Instruments"

#R1, [ManufacturerName="Texas Instruments"] will select both R1 and R2.



Combinators

Descendant Combinator

Syntax

What this selects

A B

The " " (space) combinator selects objects that are descendants of the first object.

Example

The following example has three pads on a board. One of them is under "Components" (which is a container object), and the other two are under the Layout object. There are also two resistors under "Components", and each resistor has two pads in their sub-layouts.

Typing #R1 pad will only select the pad under resistor R1, because it selects all pads that are descendants of the component with designator "R1".


This selector selects descendants of the first object. In the example above, layout pad selects all three pads because all three pads are descendants of the Layout node.


Child Combinator

Syntax

What this selects

A > B

The > combinator selects objects that are direct children of the first object.

Example

This example uses the setup from Descendant Combinator above.

The selector layout > pad selects only the two pads that are directly under the Layout node, because it looks for direct children.


Basic Examples

Below is a series of basic examples that involve using selector syntax. See further below for more advanced examples that may involve multiple syntax points.

Setting Text Size for Selected Capacitors

Ask Flux to create this ruleset:

Set the font size of the text of C2, C4, and C6 to 0.6 mm with one ruleset.

To create it in the editor, use this selector and rule:

Selector input: #C2 text, #C4 text, C6 text

Applied rules: Font Size

  • This sets the text size for components C2, C4, and C6

  • The space between C2 and text signifies the children of the C2 elements

  • The comma acts as a logical addition or inclusive disjunction, essentially adding more elements to select

Note

Objects that can be selected in this method include: net, trace, pad, text


Setting Trace Width for All Nets

Ask Flux to create this ruleset:

Create a ruleset that sets the trace width of all nets to 0.25 mm.

To create it in the editor, use this selector and rule:

Selector input: net

Applied rules: Trace Width

  • This selects all net objects in the layout and applies the Trace Width Rule

Setting Font Size of Specific Text

Ask Flux to create this ruleset:

Set the font size of all objects whose name contains VALUE to 0.5 mm.

To create it in the editor, use this selector and rule:

Selector input: [name*=VALUE]

Applied rules: Font Size

  • This finds all objects with a property called name that contains the word VALUE

  • The designer added this property to these objects earlier

Setting Keep Out Clearances for a Component’s Pads

Ask Flux to create this ruleset:

Set a 0.3 mm keep out and a 0.2 mm keep out minimum on the pads of C1.

To create it in the editor, use this selector and rule:

Selector input: #C1 pad

Applied rules: Keep Out, Keep Out Minimum

  • This sets the keep out values only for the pads of C1

  • C1 was selected using the #, all of its children were selected using the space, and then just the pads was selected using the pad input

Selecting Based off Components’ Other Properties

Ask Flux to create this ruleset:

Create a ruleset that selects every component with Hirose in its Manufacturer Name property.

To create it in the editor, use this selector and rule:

Selector input: [Manufacturer Name*=Hirose]

  • This will select all component’s that have a Manufacturer Name property, that contains the text Hirose


Setting Trace Width and Keep Out for Microstrip Traces

Ask Flux to create this ruleset:

Set the trace width of the microstrip nets RF1 and RF2 to 0.3 mm and their keep out to 0.5 mm.

To create it in the editor, use this selector and rule:

Selector input: #RF1,#RF2

Applied rules: Keep Out, Trace Width

  • Nets RF1 and RF2 were specifically named as they are microstrip traces and need special care

  • Another method: adding an RF property set to TRUE for necessary components, then create a selector rule with selector input: [RF*=TRUE]


Setting Custom Solder Mask for all Component-Unrelated Pads

Ask Flux to create this ruleset:

Set a 0.05 mm solder mask expansion on every pad that is not part of a component.

To create it in the editor, use this selector and rule:

Selector input: layout>pad

  • This selector input selects all direct children of the layout that are pads. Because pads that are part of components are children of the components, which in turn are children of the layout, they are NOT selected. Rather, going one step down the hierarchy from the layout root, all designer-added additional pads will be selected, NOT related to components.

  • Component pads are children of the components themselves

  • If instead was a space between layout and pad then all pads in the layout (regardless of location in the hierarchy) will be selected.

Advanced Examples

Setting Custom Size of Text for Specific Manufacturers

Selector input: [ManufacturerName$="ments"] text

Applied rules: Font size

  • This will select the text size of all components with a manufacturer name that contains "ments" .