クエリ言語の活用

Nexus message

This documentation page references Altium NEXUS/NEXUS Client (part of the deployed NEXUS solution), which has been discontinued. All your PCB design, data management and collaboration needs can now be delivered by Altium Designer and a connected Altium 365 Workspace. Check out the FAQs page for more information.

 

What is a Query?

Perhaps the greatest challenge when working on a complex electronics design is managing a large number of design objects. From the components, net labels and text strings on the schematic sheets to the hundreds of components and tracks that make up the routing on the PCB,  you need to be able to access, review and edit those objects. Like most Windows applications, you can double-click on an object and edit its properties. This is fine for a single object, but not something you want to do if you need to edit 300+ component designator strings or change all the vias on the PCB. For these kinds of updates, you need to access multiple objects simultaneously. 

Underlying Altium NEXUS's schematic and PCB editors is a powerful query engine. By entering queries into this engine you can filter down to find and edit precisely those objects you require.

The powerful data filtering and editing system in Altium NEXUS lets you instruct the software to return a specified set of objects. This instruction is entered in the form of a query. A query is a string you enter using specific keywords and syntax, which will return the targeted objects. What you do with those objects is up to you. Perhaps you want to highlight them and dim out all other objects, or perhaps you want to browse or sort their properties and modify specific attributes they all share.

There are a number of places where you can apply a query but command central are the Filter panels shown in the images below. Press F12 to display/hide the Filter panel.

The PCB Filter and SCH Filter panels with queriesThe PCB Filter and SCH Filter panels with queries

The PCBLIB Filter and SCHLIB Filter panels with queries
The PCBLIB Filter and SCHLIB Filter panels with queries

The controls in the panel are used to define to which objects the query will be applied and how to handle the objects that pass the query, as well as those that fail.

Where Are the Query Results?

Now that you have written a query in the Filter panel, how do you access the objects returned by your query? There are two ways that objects can be accessed and edited in the Altium NEXUS environment.

  • Graphically - after applying a filter, the default behavior is to mask (fade and make non-editable) all objects that failed the query, leaving only those that passed. This mode is excellent for locating and reviewing objects in the workspace. Since the masked objects are not editable, commands like Ctrl+A (select all) only apply to the objects returned by the query.
  • List panel - the List panel (Shift+F12) is a spreadsheet-like view into your design data. By default, it displays all design objects but once a filter has been applied, it displays only the objects returned by the query. The List panel has standard spreadsheet-like behaviors for sorting and selecting, allowing you to edit single or multiple cells directly. 

The PCB List panel and SCH List panel display the results from the PSB/SCH queries in the previous section.The PCB List panel and SCH List panel display the results from the PSB/SCH queries in the previous section.

Highlighting Options

Whenever a query is applied (or the data filtering feature is otherwise used), each object within the target document becomes a member of that filtering action's results. However, how the objects in the results and the objects that are not in the results are subsequently displayed depends upon the highlighting option(s) selected in the Filter panel. There are three different highlighting options available and the options are totally independent of one another, so you can select one, two or all.

Zoom

When the Zoom option is enabled when the query is applied, the view of the target document is updated to display the region occupied by all of the objects that are in the results. Whether or not each remaining object is displayed in the updated view depends upon its location relative to that region, so each of those objects can end up being totally displayed, or partially displayed, or not even displayed at all. 

This option is often selected in conjunction with one or both of the other options. If the Mask option has not been enabled, objects that are not in the results will still be displayed in the graphical view if they are located within the updated boundaries. At first glance, selecting this option by itself might seem pointless, but there could be times when you want to update the graphical view so that this encompasses particular objects, while not changing the selected state or masked state of any of the document's objects.

Select

When the Select option is enabled, all of the objects that are in the results are in the selected state, while all of the remaining objects are not selected. Selected objects are displayed in a more distinctive manner as non-selected objects.

If the Select option is selected when the current query is applied, all of the objects which are members of the result set subsequently acquire a selected state, while all of the remaining objects (which are not members of the result set) acquire an unselected state instead. This option would typically be selected just prior to global editing procedures because only those objects which are currently selected have their properties updated at the time. But there are other occasions when the Select option can be useful, such as when particular objects are to be moved, copied or deleted.

Mask

The Mask highlighting option determines the updated masked property of objects in the target document. When selected, all of the objects that are in the results are masked, while all of the remaining objects are unmasked. The main aspect of masked objects is that they and their properties are not capable of being edited. (Masked objects are displayed as dimmed in the list view, but are not displayed in the list view unless the all objects option is currently selected in the List panel.) The main aspect of masked objects is that the object and its properties are not capable of being edited.

The Query Builder

The PCB editor includes a dedicated Query Builder dialog. This dialog allows you to build complex queries by choosing test conditions from drop-down lists. An advantage of the Query Builder is that it lets you create a query that targets different kinds of objects.

The 'Building Query' dialog (part of the 'Query Builder' feature) assists those who are less experienced in specifying queries; a query is automatically generated whose contents correspond to the conditions specified by the designer.

The left-hand section in this dialog contains controls, whose purpose is to assist the designer in the task of specifying what properties are required for each of the document's objects to be returned by the query generated by this dialog. As each of those conditions is specified or edited, the contents of the corresponding query are updated and displayed in the dialog's right-hand section. If this dialog is then closed by clicking on its OK (or Apply) button, either the associated query will then be applied, or its contents will then be copied back to the Filter panel (depending upon how this dialog was invoked in the first instance).

The Query Builder dialog can be launched from the following places (as shown in the image below):

  • From the PCB Filter panel, click the Query Builder button to build a query and to load the string into the panel.
  • From the PCB Rules and Constraints Editor dialog, click the Builder button to build a query that defines to which objects this rule applies. 

When the Query Builder dialog is accessed from the PCB Rules and Constraints Editor dialog, it will display options that are suitable only for that rule kind.

The image below shows the Query Builder dialog being used to create a query that targets both pads and vias on the 5V net.

The Query Helper

The next step in building your query-writing skills is to use the Query Helper dialog (PCB version; SCH version). The Query Helper dialog includes a Query box in which you can enter the desired query, while also using the syntax buttons below the Query field (e.g., And, Or, <, Not,  Like, etc.,) as well as a complete list of all query keywords in the Categories field.

The 'Query Helper' dialog provides assistance for designers who want to specify their own queries. A brief description is provided for each keyword that is listed, but the online help can be accessed by pressing the F1 key while a keyword is highlighted. That invokes the Altium NEXUS Documentation Library dialog, which provides details of which objects within a document are returned by the highlighted keyword, how to use that keyword, and one or more examples of its usage.

The dialog can be accessed in the following ways:

  • Click the Helper button in the Filter panel.

PCB Filter panel access

SCH Filter panel access

The Helper button is available after clicking Advanced in the File-based Libraries Search dialog.

File-based Libraries Search dialog accessFile-based Libraries Search dialog access

Browse through the Categories of available keywords for the one you want. Use the Mask field if you are not sure what the exact keyword is. For example, in the schematic editor's Query Helper, entering *har in the Mask field will find keywords that apply specifically to harnesses, as shown in the image below. Note that the Mask field works on both the keyword Name field and the Description field, so it can be the quickest way to find possible keywords. 

If you press F1 when a keyword is highlighted or the cursor is within a keyword you have entered, documentation for that keyword will open. This is the most valuable resource for learning the basic behavior of each query keyword.  

Creating and Using Favorite Queries

Use the Query Helper dialog (described above) to create an expression. After it has been created and executed, it is added to the list of previously executed queries on the History tab of the Expression Manager dialog. To add it as a favorite, on the History tab of the Expression Manager dialog (PCB version; SCH version), select the desired favorite then click Add To Favorites. The query will then be displayed on the Favorites tab.

There are two ways to use your favorite queries.

  1. Select a favorite from the Favorites tab of the Expression Manager dialog then click Apply Expression.

 

  1. Click the Y shortcut key to open the queries pop-up menu (shown below) then select the desired favorite query.

 

To give a favorite query an appropriate name, click on a favorite on the Favorites tab of the Expression Manager dialog then click Rename or right-click then select Rename

Favorites are stored in the Expression Manager dialog (PCB version; SCH version). The dialog can be accessed by using the Favorites button in the Filter panel or by using the Y shortcut key then selecting Organize Favorites from the menu.


You also can define a shortcut key for a favorite by customizing the Filter menu. For more information on customizing the Altium NEXUS environment, see Configuring and Customizing Altium NEXUS.

Using Pre-packaged Examples

Both the schematic and PCB editors come with a set of pre-packaged example queries. To use the examples, press the Y shortcut key to display the Filter pop-up menu then hover over Examples to view the sub-menu.

When you select an entry in the sub-menu, the query behind that filter is applied. To view the actual query behind one of the examples, look in the History list after applying it. You also can access this list in the Filter pop-up menu.

To clear the filtering, press Shift+C in the design space.

Query Building Tools

Perhaps the easiest way to write a query is to have Altium NEXUS write it for you! You can do this by using either the Find Similar Objects dialog or the Query Builder dialog.

Find Similar Objects Dialog

When you use the Find Similar Objects dialog (PCB version; Schematic version), it generates a query to find the required objects. If the Create Expression option is enabled, that query will be displayed in the Filter panel. This is an excellent technique for learning different query keywords.

The Find Similar Objects dialog opens when you right-click on any unmasked object in your design document then select Find Similar Objects from the context menu.

Left image: PCB version; right image: SCH versionLeft image: PCB version; right image: SCH version

This dialog allows you to find objects similar to the one on which you right-clicked, then define which of the object's attributes that must be the same (or different) for a match. Suppose you wanted to change all GND pads in your design. You could right-click on one such pad, choose Find Similar Objects, then change the Net field from Any (the default setting) to Same. All of the GND pads will be selected when you click Apply in the dialog. If the Create Expression option is enabled, the following query would appear in the Filter panel: (ObjectKind = 'Pad') And (Net = 'GND').

As an example from a schematic, you can change the Color property of all Power Objects having a particular Text property (e.g. 'GND') within a document to the same value. For example, from a PCB, you can change the Hole Size property of all vias having a particular Via Diameter property within a document to the same value.

Clear Existing Option

Enable the Clear Existing option to clear any existing selection or editing mask before applying the search. Disable this option if you are performing successive searches and it is desirable for the results to accumulate.

Filter Toolbar

The Filter Toolbar is provided for PCB documents and allows you to mask all of the objects within a document except for those having a specified property, or for those forming part of a specified component. The right-most field of the toolbar is used to specify the contents of a query. You can enter the query in the field or you can use the drop-down to select from recent queries. It is not possible to specify which options to use when queries are applied from the Filter Toolbar and in all cases, any previous query is cleared, and the Mask and Zoom options are then used with the current query. To use query options, use the Filter panel, Query Builder dialog, Query Helper dialog, or Find Similar Objects dialog.

Logical Query Expression Operators

Below is a summary of the operators that can be used when defining logical query expressions with the query language.

Arithmetic Operators

Operator Description Example
+ Addition operator NetPinCount + NetViaCount
- Subtraction operator ArcStopAngle - ArcStartAngle
* Multiplication operator PadXSize_BottomLayer * PadYSize_BottomLayer
/ Division operator HoleDiameter / ViaDiameter
Div Integral division operator Color Div 65536
This calculates Color divided by 65536 and the fractional part of the result is discarded
Mod Modulus operator Color Mod 256
This calculates the remainder when Color is divided by 256, without determining the fractional part of the result

Logical Operators

Operator Description Example
And Logical AND operator IsPad And OnMultiLayer
To be returned, an object has to be a pad, and reside on the Multi-Layer layer
&& Logical AND operator
(lower precedence)
IsPad && OnMultiLayer
To be returned, an object has to be a pad, and reside on the Multi-Layer layer
Or Logical OR operator IsPad Or IsVia
To be returned, an object has to either be a pad, or a via
|| Logical OR operator
(lower precedence)
IsPad || IsVia
To be returned, an object has to either be a pad, or a via
Xor Logical EXCLUSIVE OR operator OnMultiLayer Xor (HoleDiameter <> 0)
To be returned, an object has to either be on the Multi-Layer layer and have a Hole Diameter that is zero, or not
be on the Multi-Layer layer and have a Hole Diameter that is not zero.
Not Logical NOT operator Not OnMultiLayer
To be returned, an object has to not be on the Multi-Layer layer

Comparison Operators

Operator Description Example
< Less Than operator HoleDiameter < 40
To be returned, an object has to have a Hole Diameter which is less than 40
<= Less Than Or Equal To operator HoleDiameter <= 40
To be returned, an object has to have a Hole Diameter which is less than, or equal to 40
>= Greater Than Or Equal To operator HoleDiameter >= 40
To be returned, an object has to have a Hole Diameter which is greater than, or equal to 40
> Greater Than operator HoleDiameter > 40
To be returned, an object has to have a Hole Diameter which is greater than 40
<> Not Equal To operator HoleDiameter <> 40
To be returned, an object has to have a Hole Diameter which is not equal to 40
= Equal To operator HoleDiameter = 40
To be returned, an object has to have a Hole Diameter which is equal to 40
Between...And... Inclusive range operator HoleDiameter Between 30 And 50
To be returned, an object has to have a Hole Diameter that is greater than, or equal to 30, and
less than, or equal to 50.
Like Like operator Name Like 'ADDR?*'
This returns objects having a Name property whose associated (text) string begins with ADDR and
which contains at least one more character

Wild Card Characters

Wild Card characters permit the provision of strings which are not exactly specified. These characters are typically used in conjunction with other characters, resulting in the provision of strings which are partially specified. A few exceptional keywords can accept string parameters that are not exactly specified, but for the most part, strings can only contain Wild Card characters when these are being compared by the Like operator.

Operator Description Example
? This can be replaced by a single character of any type Footprint Like 'DIP1?'
This returns objects which have a Footprint property of DIP10, or DIP12, or DIP14, etc.
* This can be replaced by any number of characters, each of which can be of any type Footprint Like 'SIP*'
This returns objects which have a Footprint property of SIP1, or SIP12, or SIP216, etc. (Any objects having a Footprint property of SIP are also returned, because '*' can also be replaced by no characters)

Boolean Strings

Operator Description Example
True This affirms the meaning of a Keyword IsPad = True
To be returned, an object has to be a pad
False This negates the meaning of a Keyword IsVia = False
To be returned, an object has to not be a via

Round Brackets and Order of Precedence

It is worthwhile taking a look at the order of precedence in place for the operators used in logical Query expressions. After all, without such knowledge, an expression may not target the objects required.

Round brackets have the highest precedence within an order of precedence that has been defined for the various operators, and which determines how queries are interpreted by the software (whenever the user has not provided round brackets). The sequence of this order, from highest to lowest, is as follows:

  1. Round brackets ()
  2. Not
  3. ^, *, /, Div, Mod, And
  4. +, -, Or, Xor
  5. =, <>, <, >, <=, >=
  6. &&, ||
This order of precedence is similar to that used in Pascal-type languages. Ambiguities are resolved by working from left to right. Round brackets are evaluated from inside to outside and equal levels are evaluated left to right.
It is highly advisable to use round brackets whenever there is any possibility, whatsoever, that the query might not be correctly interpreted. Generous usage of round brackets removes doubt and makes the resulting queries easier to read by others.

Global System Query Functions

Global system query functions shown in the Query Helper dialog
Global system query functions shown in the Query Helper dialog

This section details the query language keywords available in the schematic, PCB, and library documents in Altium NEXUS. For help on a specific query keyword, use the following collapsible sections or highlight (or click inside) any given keyword - in the Query Helper, a Filter panel, or the Query field of a PCB design rule - and press F1 to access its section right away.

For details about query language keywords available in specific editors and tools in Altium NEXUS, refer to the following pages:

Arithmetic Functions

Trigonometry Functions

Exponential and Logarithmic Functions

Aggregate Functions

System Functions

If you find an issue, select the text/image and pressCtrl + Enterto send us your feedback.
Content