pcb-rnd knowledge pool


Practical Query examples

query_examples by Tibor 'Igor2' Palinkas on 2018-03-28

Tags: howto, query, example, padstack

node source



Abstract: Practical examples on using the query language (advanced search).

  Use these query expressions either in the advanced search, or as an action to select matching objects, like this, within ' quotes:

query(select, '



The examples below will contain the expression part only.

All "pins" and "pads" without solder mask opening

Assume all pins and pads are implemented as padstacks (so called light terminals ). A query that list any padstack that has no solder mask shape on top or bottom:

(@.type == PSTK) && (@.shape.top_mask == "") && (@.shape.bottom_mask == "")

The above query will also list padstacks used as vias. Some boards may need via copper exposed, other boards may need tented vias (vias covered by the mask). In the latter case, "vias" should be excluded from the search. But pcb-rnd doesn't know the difference; to distinguish between "via" and "pin"/"pad" the user can assume that anything with a terminal ID is a pin or pad. An object has a terminal ID if its "term" attribute exists and is non-empty. Extending the search to include only light terminals that have no mask cutout:

(@.type == PSTK) && (@.a.term != "") && (@.shape.top_mask == "") && (@.shape.bottom_mask == "")

Shortcoming: if a padstack has a copper shape on the top copper layer and a mask cutout on the bottom copper layer, the above search will not select it, because it only cares about whether the padstack has mask cutout. This may let such broken padstacks go unnoticed. It is possible to describe this case too: select any padstcak terminal that has top copper but no top mask:

(@.type == PSTK) && (@.a.term != "") && (@.shape.top_copper != "") && (@.shape.top_mask == "")

A similar expression can be crafted for the bottom side, and the two can be combined with an "OR" (written as "||"):

(@.type == PSTK) && (@.a.term != "") && (
    ((@.shape.top_copper != "") && (@.shape.top_mask == ""))
 || ((@.shape.bottom_copper != "") && (@.shape.bottom_mask == ""))

This reads as: "any padstack that is a terminal and either (has top copper without top mask) or (has bottom copper without bottom mask)."

List DNP subcircuit refdes'

The following one-liner prints the refdes of subcircuits having the DNP attribute set to "true" and <void> for all other objects. Using together with pcb-rnd --gui batch and grep -v , it can be used to automate listing DNPs for a board:

query(eval, '(@.type == SUBCIRCUIT && @.a.DNP == "true") thus @.a.refdes')

(Original idea by Matt Jenkins)