Introduction to the Query Language (Part 2)
Building your Query Writing Skills
How can you learn to write queries? Like anything new, it takes practice.
Altium Designer includes valuable resources for learning the query language. The first is a set of example queries that are included as part of the installation. The second is a group of tools that generate queries based on your input. The third is the Query Helper, which lists all query keywords and helps you build up a query. The final source in learning the query language is in the online help.
Example and Favorite Queries
Both the schematic and PCB editors come with a set of pre-packaged example queries.
To try these, press the Y shortcut key to display the Filter popup menu, where you can select the Examples sub-menu.
When you select an entry in the menu the query behind that filter is applied
(press Shift+C to clear it).
To view the actual query behind one of the examples look in the History list after applying it, you can access this list in the Filter popup menu too.
You can also keep favorite queries and re-use them later. Favorites are stored in the Expression Manager dialog.
There are a number of ways to access this dialog:
· via the Favorites button in the Filter panel
· by selecting the Organize Favorites menu entry after pressing the Y shortcut key.
The great thing about favorites is that they are automatically displayed in the Filter menu,
giving you instant access to up to ten favorite queries.
Query Building Tools
Perhaps the easiest way to write a query is to get Altium Designer to write it for you!
There are two ways of doing this, using the Find Similar Objects dialog, or the Query Builder.
- Find Similar Objects dialog
When you use the Find Similar Objects dialog it generates a query to find the required objects. If the Create Expression option is enabled then that query will be displayed in the Filter panel.
This is an excellent technique for learning different query keywords.
The Find Similar Objects dialog appears when you right-click on any unmasked object in your design document and select Find Similar Objects from the context menu. The idea with this dialog is that it lets you find objects similar to the one you’re right-clicked on, where you define which of the object's attributes that must be the same (or different) for a match.
Suppose for example you wanted to change all vias with 15-mil drill size in your design. You could right-clicking on one such via, choose Find Similar Objects, then change the Hole size from Any (the default setting) to Same. All of the 150mil vias will be selected when you Apply from this dialog, and if the Select Matching option is enabled you can use the Inspector to make the change across the entire selection.
If the Create Expression option is enabled in the Find Similar Objects dialog then the following query would appear in the Filter panel:
(ObjectKind = 'Via') And (HoleDiameter = AsMils(15))
The Query Builder
The PCB editor also includes a dedicated Query Builder. This tool lets you 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, for example the Figure below shows the Builder being used to create a query that targets both pads and vias on the CALCUB_VP5 net.
The Query Builder can be launched from a number of places.
· Click the Builder button in the Filter panel to build a query and the string loaded into the panel.
· Click the Builder button when you are editing a design rule to build a query that defines which objects this rule must apply to.
You can also call up the Builder directly in the design workspace,
· either by pressing the Shift+B shortcut keys,
· or right-clicking in the workspace and choosing Build Query from the context menu.
When you run the Builder in the workspace it will look different from when it is run from the Filter panel or Rules dialog, in the workspace it applies the query immediately so it includes display-type controls, whereas from the Filter panel or Rules dialog it creates the query string instead.
Note also that the right-click option is context sensitive, the options available will change depending on what object you right-clicked on. Running the Builder from the Design Rules dialog is also context sensitive, it will only give you options that are suitable for that rule kind.
Query Helper
The next step in building your query-writing skills is to use the Query Helper. Accessed via the Helper button in the Filter panel, the Query Helper includes a query editing box at the top, syntax buttons like And and Or in the mid-region of the dialog, as well as a complete list of all query keywords below that.
Browse through the different 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 * par in the Mask field will show you the dozen or so keywords that apply to parameters specifically, while* par will pick up keywords for both parameters and parts. 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 typed in, an online help description for that keyword will open. This is the most valuable resource for learning the basic behavior of each query keyword. Here you will learn the nuances of that keyword, such as keywords that return children objects, parent objects or both.