SEARCH(nged)

find and list objects in a BRL-CAD database

๐Ÿ“… published 7.44.0, from nixpkgs unstable

okay bestie, this is the SEARCH(nged) page from BRL-CAD User Commands โ€” itโ€™s basically find(1) energy but for objects in your MGED database instead of files on disk. ๐Ÿ’…

๐Ÿ’– NAME ๐Ÿ’–

search โ€” find and list objects in a BRL-CAD database.

โœจ SYNOPSIS โœจ

search [-a] [-v] [-Q] [-h] [path] [expressions...]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

search works in a fashion similar to Unix-style find commands (internally it is based on OpenBSD's and NetBSD's find code) but searches objects in the current open database in MGED rather than files in a file system. One or more search paths are specified for searching, and a search plan specifies filters through which objects in the search paths are tested. The names of objects satisfying all of the filters are returned as the command output. ๐Ÿซถ

Search Inputs are specified using PATHS and matching of objects is done according to a search plan built using boolean expressions constructed using the PRIMITIVES and OPERATORS described below. Note that OPTIONS are not used to form search plans โ€” unlike the search plan they are specified before the paths and are used to control settings that apply globally to search's behavior and reporting during the execution of the search. no cap, options are their own little vibe check.

The results of the search command will be sorted according to David Koelle's "alphanum" algorithm, which is basically a human-intuitive ordering for strings with letters and numbers. For example, a result returning d1.r, d10.r and d2.r will be sorted as:

d1.r
d2.r
d10.r

instead of the default ASCII character ordering, which would look like:

d1.r
d10.r
d2.r

๐Ÿ’… OPTIONS ๐Ÿ’…

  • -h โ€” Print help and exit.
  • -a โ€” Include hidden objects when assembling implicit, top-level, or flat input lists and when walking search hierarchies.
  • -Q โ€” Exit quietly without printing error messages if the search plan contains errors. Primarily used in situations where programs automatically generate search invocations.
  • -v[v..] โ€” Prints extra (verbose) information in results. Can be stacked up to 3 times for increasingly verbose printing. (See Example 22 for in-depth usage)

๐ŸŒธ PATHS: ๐ŸŒธ

By default, only the "top level" objects in any search are used as starting points in the search. The default mode if no path is explicitly specified returns a list of all objects found matching the criteria using the top level objects as inputs. Specifying paths is done as follows:

Table 1. Path Specifiers

  • / โ€” Search using top level objects in database as starting points, return list of matching full paths.
  • . โ€” Search using top level objects in database as starting points, return list of all matching objects (default).
  • | โ€” Iterate over all objects in the database without doing a tree walk, return list of all matching objects.
  • |/ โ€” flat version of /: uses every object in the database as a starting point for a full tree walk, then returns matching full paths.
  • |. โ€” flat version of .: uses every object in the database as a starting point for a full tree walk, then returns all matching objects.
  • objname โ€” Use object objname as the starting point, return list of matching full paths.
  • /objname โ€” Use object objname as the starting point, return list of all matching objects.
  • |objname โ€” Use every object below objname as starting points, return list of all matching objects.

One search command may use multiple paths, each of which can specify its own mode โ€” such a "mixed mode" search will return a list of full paths and objects in the order paths were supplied to search. ๐ŸŽ€

The "flat" searches that are specified by using | as a modifier to other paths will use every object in the database as starting points for full tree walks and consequently will be significantly more expensive for complex tree hierarchies. The "truly flat" iterative search triggered by the the stand-alone | path specifier will be faster, but because it does not walk the tree hierarchy depth-related options (-above, -below, -depth, etc.) will not function. iykyk, flat is fast until depth options ghost you.

๐Ÿ”ฅ PRIMITIVES: ๐Ÿ”ฅ

๐ŸŒŸ -attr attrib[>/</=val] ๐ŸŒŸ

Returns TRUE if the object has attribute attrib. If a specific value is also supplied for the attribute with an equal condition, TRUE is returned if the object both has the attribute and the attribute is set to value val. In the case of >, <, >=, and <= there are two possibilities โ€” if val is numerical a numerical comparison is performed, otherwise a string comparison is performed. Both attrib and val are treated as patterns under shell pattern matching rules when a string comparison is performed, but in numerical mode only the attribute name is pattern matched.

๐ŸŒŸ -bool u/+/โˆ’ ๐ŸŒŸ

True if the object in question is being combined into the local hierarchy with the specified boolean operation. Recognized types are Union (u), Intersection (+), and Subtraction (-).

Note that by convention, top level objects are implicitly "unioned" into the database. To see only objects that have been unioned into a comb tree without returning the top level comb object as well, use the -mindepth option to filter for returns deeper in the tree.

๐ŸŒŸ -depth [>/</=]depth ๐ŸŒŸ

True if the depth of the object in the tree is within the range specified.

๐ŸŒŸ -exec expression arg1 arg2 ... ";" ๐ŸŒŸ

Pass expression and its arguments to the host application's search execution handler. The filter is true if the handler reports success and false if it reports an error; a textual command result is not interpreted as a boolean. The commands available to -exec depend on the host application. Any pair of curly braces ({}) in an argument is replaced by the name or full path of the object. The semicolon terminates the argument list and must not be omitted. Remember to quote the parameters properly. The semicolon must stand on its own and must be quoted. ๐Ÿ˜ญ

bestie, do not forget that semicolon. it is not decorative. it is the whole assignment. ๐Ÿ’€

When using multiple -exec filters, keep in mind that filters are evaluated lazily, so if you have two -execs and the first one returns false for one node, the second one will not run at all.

๐ŸŒŸ -iname pattern ๐ŸŒŸ

Like name except the match is case insensitive.

๐ŸŒŸ -iregex pattern ๐ŸŒŸ

Like regex except the match is case insensitive.

  • -matrix IDN|{#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#} โ€” true when the object in question is being combined into the local hierarchy with the specified matrix โœจ. This one is so good when you pair it with the ! operator for finding objects in a hierarchy with matrices over them โ€” iykyk. And IDN is a shorthand that lets you specify an identity matrix more succinctly, which, thank you, because typing all those numbers is a โœจchoiceโœจ.
  • -maxdepth n โ€” true if the depth of the object in the tree is less than or equal to n.
  • -mindepth n โ€” true if the depth of the object in the tree is greater than or equal to n.
  • -name pattern โ€” true if the object name matches pattern โ€” and bestie, that's the name only, not the full path, just the name ๐Ÿ’…. The evaluation is done according to shell pattern matching rules.
  • -nnodes n โ€” true if the object is a combination and has n nodes. This one also supports supplying <, >, <=, and >= in front of the number, so you can get true for objects with node counts less than, greater than, less than or equal to, and greater than or equal to n. Slay, comparison operators.
  • -param param[>/</=val] โ€” returns TRUE if the object has parameter param. And here's the tea: unlike -attr, which looks only at general attributes stored as metadata on objects, the -param filters based only on the internal geometric object's characteristics ๐Ÿซถ. If a specific value is also supplied for the parameter with an equal condition, TRUE is returned if the object both has the parameter and the parameter is set to value val. In the case of >, <, >=, and <= there are two possibilities โ€” if val is numerical a numerical comparison is performed, otherwise a string comparison is performed. Both attrib and val are treated as patterns under shell pattern matching rules when a string comparison is performed, but in numerical mode only the parameter name is pattern matched. No cap.

The following table outlines what parameters are visible to the -param option ๐Ÿ‘‘. Because BRL-CAD uses the same internal containers for some types, some parameters will be present even when they do not make sense for the specific subtype โ€” examples include using arb8's container for arb4 and tgc for rcc ๐Ÿ™ˆ. Note: there are also a number of primitives whose parameters are not exposed in a way that that -param can access them: arbn, ars, brep, bspline, dsp, metaball, nmg, pipe, pnts, and poly. So if your fave is on that list, that's literally why the vibe check failed.

๐ŸŽ€ Table 2. Primitive Parameters ๐ŸŽ€

  • arb8 (arb4, arb5, arb6, arb7) โ€” V1, V2, V3, V4, V5, V6, V7, V8
  • bot โ€” mode[surf,volume,plate,plate_nocos], orient[no,lh,rh], V, F, T
  • cline โ€” V, H, R, T
  • ebm โ€” F, W, N, H, M
  • ehy โ€” V, H, A, r_1, r_2, c
  • ell (sph) โ€” V, A, B, C
  • epa โ€” V, H, A, r_1, r_2
  • eto โ€” V, N, C, r, r_d
  • extrude โ€” V, H, A, B, S, K
  • grip โ€” V, N, L
  • half โ€” N, d
  • hf โ€” cfile, dfile, fmt, w, n, shorts, file2mm, v, x, y, xlen, ylen, zscale
  • hyp โ€” V, H, A, b, bnr
  • part โ€” V, H, r_v, r_h
  • revolve โ€” V, axis, R, ang, sk_name
  • rhc โ€” V, H, B, r, c
  • rpc โ€” V, H, B, r
  • sketch โ€” V, A, B, VL, SL
  • submodel โ€” file, treetop, meth
  • tgc (rcc, rec, tec, trc) โ€” V, H, A, B, C, D
  • tor โ€” V, H, r_a, r_h
  • vol โ€” file, w, n, d, lo, hi, size, mat
  • -path pattern โ€” true if the object path matches pattern. The evaluation is done according to shell pattern matching rules.
  • -print โ€” evaluates to TRUE ๐Ÿ’– โ€” used to print out the path and name of the object.
  • -regex pattern โ€” true if the object's path matches pattern. The matching here is done with Regular Expression matching, so go off with your regex self ๐Ÿ’…
  • -size [>/</=]size โ€” true if the object's size lands inside the range you specified. Big note though bestie: for combs, extrudes, and other composite objects, this filter only looks at the object definition itself, not its related elements. So don't come for it expecting it to count the whole squad ๐Ÿ™ˆ
  • -stdattr โ€” returns TRUE if an object has ONLY standard attributes attached to it. In BRL-CAD, the standard attributes are literally these:
    • GIFTmater โ€” value type #
    • inherit โ€” value type 0 or 1
    • material_id โ€” value type #
    • oshader โ€” value type shader string
    • region_id โ€” value type #
    • rgb โ€” value type #/#/#
  • -type pattern โ€” returns TRUE if the object's type matches pattern. This one uses shell pattern matching for the evaluation, so it's giving glob energy โœจ Types it recognizes include:
    • arb4, arb5, arb6, arb7, arb8, arbn
    • annot, ars, binunif, bot, brep, bspline
    • cline, constrnt, datum, dsp, ebm, ehy
    • ell, epa, eto, extrude, grip, half
    • hf, hrt, hyp, joint, metaball, nmg
    • part, pipe, pnts, poly, rec, rhc
    • rpc, script, sketch, sph, submodel, superell
    • tgc, tor, vol

And for the combinations, these are the types and the abbreviations it recognizes:

  • combination โ€” c, comb, combination
  • region โ€” r, reg, region

Also, as a little convenience treat ๐ŸŽ€ the -type option will also recognize the pattern shape, which matches any object that is not a combination, region, annotation, constraint, grip or joint. Not me giving you a catch-all, but she did that ๐Ÿ’…

And okay so if you're trying to identify shapes that are defined as implicit solids using the "plate mode" methodology โ€” the pattern plate is your girl. It matches any object whose internal definition indicates it's of that type. Currently that's possible with bot and brep objects. ๐Ÿ”ฅ

The pattern volume is basically the mirror of plate: it reports objects that clearly define a non-implicit solid volume. But heads up, its determination is local โ€” like, combs aren't matched because a comb may be made up of non-volumetric objects. In particular, plate mode objects won't match because their volume is implicit, and (for example) surface mode BoTs won't match because they don't define a volume. It's giving "read the room, the room is the local definition" ๐Ÿ˜ญ


๐Ÿ’ฅ OPERATORS ๐Ÿ’ฅ

  • ( expression ) โ€” evaluates to true when the expression inside the parentheses is true. Itโ€™s the โ€œbestie, please respect my order of operationsโ€ move ๐Ÿ’….
  • -below[>/</=val] expression โ€” true if an ancestor of the current path satisfies expression. The current object itself is not tested by expression. For example, -below -name start_comb.c is true for both /component/region.r/start_comb.c/prim1.s and any deeper descendants of start_comb.c, but itโ€™s false for start_comb.c itself. No cap.

An optional comparison constrains the number of hierarchy edges between the current object and the ancestor being tested. The immediate parent is at relative depth 1, its parent is at relative depth 2, and so on. So -below=1 -type region selects objects whose immediate parent is a region, while -below>1 -type region requires a matching region at least two levels above the current object. The unqualified form tests all ancestors. Slay.

Nested forms such as -below -below -name X are valid. They test whether the current object has an ancestor which is itself below an ancestor matching X. See Hierarchy Operator Performance before using constrained or action-bearing forms on large hierarchies. Fr fr, check the performance tea first โ˜•.

  • expression -and expression (a.k.a. -a) โ€” the and operator operates like the logical AND operator: TRUE only if both expressions are true. AND is the default operator assumed if two expressions are present with no operator explicitly defined. Itโ€™s giving โ€œif both of you are coming, then itโ€™s a partyโ€ ๐ŸŽ€.
  • -above[>/</=val] expression โ€” true if a descendant of the current path satisfies expression. The current object itself is not tested by expression. For example, -above -name prim1.s is true for /component, /component/region.r, and /component/region.r/start_comb.c when prim1.s is below them, but itโ€™s false for prim1.s itself.

An optional comparison constrains the number of hierarchy edges between the current object and the descendant being tested. An immediate child is at relative depth 1. Thus, -above=1 -name prim1.s matches only direct parents of prim1.s; the unqualified form tests descendants at every depth.

Using -above as the expression within another -above (for example, -above -above -name X) is valid, but may be dramatically slower than an ordinary -above. See Hierarchy Operator Performance. Basically: valid, but it can be a lil dramatic ๐Ÿ˜ญ.

  • -not expression (a.k.a. !) โ€” the logical NOT operator. Returns the opposite of the evaluation result of expression. Itโ€™s the โ€œflip the vibe checkโ€ button.
  • expression -or expression (a.k.a. -o) โ€” the logical OR operator. True if either expression is true. One of them showing up is enough, iconic behavior โœจ.

๐Ÿ”ฅ Hierarchy Operator Performance ๐Ÿ”ฅ

Ordinary, unconstrained, side-effect-free -above and -below expressions use cached propagation and are intended for large searches. Pure boolean composition with -and, -or, parentheses, or ! does not by itself disable these hierarchy caches. The following cases automatically require exhaustive evaluation instead:

  • Any -exec anywhere in a plan containing -above or -below disables all hierarchy-result caching for that plan. This is necessary because the callback may change the database, and later filters must observe those changes even when -exec is in a different -and or -or branch. Like, the database said โ€œIโ€™m different now,โ€ and the filters have to respect that ๐Ÿ’….
  • A -below with a relative-depth comparison, or whose expression contains an explicit action such as -exec or -print, may inspect the ancestor chain separately for every candidate. Its cost is proportional to the number of paths times their depth and can become quadratic on a deep chain. Unconstrained nested -below expressions remain cached when they contain no actions; in the unusual case of more than 64 cached -below operators, additional operators use exhaustive evaluation. Sixty-four is the vibes limit, apparently ๐Ÿ‘‘.
  • A depth-constrained -above, an -above whose expression contains an explicit action, or an -above directly nested inside another -above may compare candidates against the collected path set repeatedly. These forms can be quadratic in the number of paths. Oof.
  • Nesting hierarchy operators that require these exhaustive forms can compound the cost beyond quadratic. Itโ€™s giving โ€œthis could get real expensive real fastโ€ ๐Ÿ’€.

The implicit final -print added by search does not disable caching. Only an explicit -print inside the hierarchy expression does so. Important distinction, bestie ๐Ÿซถ.

Traversal pruning by -maxdepth is also conservative. An -or permits pruning only when every branch has a -maxdepth bound; for example, -maxdepth 2 -or -name *.s cannot prune, while -maxdepth 2 -or -maxdepth 4 can prune below depth 4. A -maxdepth under !, -above, or -below does not bound the outer traversal. Actions are evaluated from left to right, so -exec ... ";" -and -maxdepth 2 cannot prune before running the action, whereas placing -maxdepth 2 first permits pruning and prevents the later action from running below that depth.

โš ๏ธ Warning โ€” on large, deep, or heavily shared models, the number of full paths can be much larger than the number of database objects. The exhaustive forms above can therefore take an untenably long time and may appear to have hung. Not the cute kind of suspense ๐Ÿ˜ญ.

When possible, start from the narrowest applicable path, put inexpensive selective filters such as -name, -type, or -depth before a costly hierarchy operator, and avoid relative-depth constraints or nested hierarchy operators when an equivalent simpler plan is available. Test unavoidable exhaustive plans on a representative subtree before applying them to the complete database. Be smart, be safe, protect your runtime ๐ŸŒธ.

๐Ÿ’ฌ A NOTE ON EXPRESSIONS ๐Ÿ’ฌ

All primaries and operands must be expressed as separate arguments to search. In practice, this means that there must be a space between each element in a search expression. E.g. !(-name [a-z] -or -name [0-9]) must be written as:

! ( -name [a-z] -or -name [0-9] )

While this may seem like a rather verbose way of writing the expression, it greatly simplifies the parsing of the expression and is standard for virtually all find type commands. Because [a-z] and [0-9] are atomic arguments as far as search is concerned, they should NOT be expanded in a similar fashion. The parser said โ€œgive me spaces,โ€ and honestly? We respect it ๐Ÿ‘‘.

๐Ÿ”ฎ A NOTE ON SPECIAL CHARACTERS ๐Ÿ”ฎ

Depending upon your environment, special characters such as wildcards or brackets may require an escape character (\). Double quotes can also be used to surround the expression negating the need for multiple escape characters. The following three examples show a search for names containing the string "tire" using two wildcards.

search -name *tire*

search -name \*tire\*

search -name "tire"

If an escape character is required but not used, an "unknown option passed to find_create" error will be displayed. So if you see that, itโ€™s not a mystery, itโ€™s the shell/parser saying โ€œbestie, you forgot the escapeโ€ ๐Ÿ™ˆ.

๐Ÿ’– Example 1 โ€” Shell Globbing Based Pattern Match of Object Name ๐Ÿ’–

search -name *.s

Finds literally every object in the database whose name ends in ".s". Slay.

๐ŸŒธ Example 2 โ€” Full Path Instance Reporting of Search Results ๐ŸŒธ

search / -name *.s

Finds every instance of objects in the database with names ending in ".s". Yes bestie, there's a difference โ€” we'll get to it.

๐Ÿฆ‹ Example 3 โ€” Name Pattern Matching at Depth >= 3 ๐Ÿฆ‹

search / -name *.s -mindepth 3

Finds all the instances of objects whose names end in ".s" that are 3 or more levels deep in their tree. Deep cuts only.

๐ŸŽ€ Example 4 โ€” Finding all Objects in a Subtree ๐ŸŽ€

search group1 -name *.r

Finds all objects within group1 in the database that have names ending in ".r". Heads up though: this returns a list of objects, not the full path info associated with each instance of the matched objects. Just the objects themselves, no lore.

โœจ Example 5 โ€” Finding all Instances of Objects in a Subtree โœจ

search /group1 -name *.r

Finds all instances of objects within group1 whose names end in ".r". And unlike the previous example, this one does hand you the full path information associated with each instance of the objects matched. That leading / is doing so much work, iykyk.

๐Ÿงš Example 6 โ€” Finding all Instances of a Sub-Path ๐Ÿงš

search / -path \*r245

Finds all paths that end with the object r245. Note bestie: all paths generated by objects below r245 will not match this pattern. If you want to find all paths with r245 in them, use this pattern instead:

search / -path \*r245\*

And if you need to match an object path that's potentially ambiguous (say, r1 when there are lots of regions matching the r1* globbing rule), add the trailing slash to the expression:

search / -path \*r1\/\*

๐Ÿ”ฅ Example 7 โ€” Searching by Type ๐Ÿ”ฅ

search . -type eto

Finds all objects in the database that are elliptical tori. And note that a path of "." produces the same search behavior as the default behavior for an unspecified path. Same vibe, different spelling.

๐Ÿซถ Example 8 โ€” Finding all Instances of Nested Regions ๐Ÿซถ

search / -type region -below -type region

Finds all instances of objects of type region that are nested within another region. So it's searching for regions being used within the subtrees of other regions โ€” which is, and I cannot stress this enough, considered bad practice in BRL-CAD. Not the moment.

๐Ÿ‘‘ Example 9 โ€” Finding all Assemblies ๐Ÿ‘‘

search / -type comb ! -below -type region ! -type region

Finds all instances of objects of type combination that are not below regions and are not themselves regions. These are regarded as "assemblies" in BRL-CAD. Main character objects, honestly.

๐Ÿ’… Example 10 โ€” Finding all Combinations below Regions ๐Ÿ’…

search / -type comb -below -type region ! -type region

Finds all instances of combinations that are not regions and are located within a region (below a region in the hierarchy). Combs living inside regions, we see you.

๐Ÿ“ Example 11 โ€” Finding all Empty Combinations ๐Ÿ“

search -nnodes 0

Finds all combinations containing zero nodes. Empty combs, no thoughts, head empty.

๐ŸŒˆ Example 12 โ€” Finding all Combinations With 10 or More Nodes ๐ŸŒˆ

search -nnodes >=10

Finds all combinations with 10 or more nodes. Busy combs, thriving.

โญ Example 13 โ€” Finding all Intersected Objects โญ

search -bool +

Finds all objects that are combined into one or more trees using the Intersect boolean operation somewhere in the .g file. Important caveat: this approach only identifies which objects are intersected somewhere in the tree โ€” it does not tell you where specifically they're intersected.

๐ŸŒธ Example 14 โ€” Finding all Instances of Object Intersection ๐ŸŒธ

search / -bool +

Finds all boolean operations that use the Intersect boolean operation and reports the full paths to those objects. So this reports all the individual cases where an object has been combined into a hierarchy by intersection, not just which objects have been included with the intersection operator. Receipts AND locations ๐Ÿ’–

๐Ÿฆ‹ Example 15 โ€” Finding all Unions Within a Comb's Tree ๐Ÿฆ‹

search /all.g -mindepth 1 -bool u

Finds all unions within the all.g tree hierarchy, excluding all.g itself. -mindepth 1 said "not you, queen."

๐Ÿ’œ Example 16 โ€” Finding all Non-Subtracted Regions below Regions ๐Ÿ’œ

search / -type region -below -type region ! -bool -

A more nuanced variation on finding nested regions, which adds a check to make sure the regions aren't being subtracted. So real talk โ€” while this isn't ideal, using a subtraction does avoid the modeling error of two volumes claiming the same three dimensional space, and it's arguably acceptable. The -below command is the one that finds nested region instances that are considered errors.

โœจ Example 17 โ€” Finding all Non-Identity Matrix Instances โœจ

search / ! -matrix IDN

Reports all comb instances included in their parent comb with a non-identity positioning matrix. We love a transformed king.

๐ŸŽ€ Example 18 โ€” Finding all Regions with RGB color 180 180 180 ๐ŸŽ€

search -type region ( -attr color=180/180/180 -or -attr
rgb=180/180/180 )

Prints all regions with their color attribute set to 180/180/180. Some files may use rgb instead of color, so to be comprehensive an -or option is used to check both possibilities. Covering all bases, periodt.

๐Ÿงš Example 19 โ€” Find All Combs Containing At Least One of Two Objects (dbfind) ๐Ÿงš

search |. ( -depth 0 -above=1 -name obj1 ) -or ( -depth 0 -above=1
-name obj2 )

Prints all combs immediately above either obj1 or obj2. This more or less mimics the results of the dbfind command โ€” although it'll be somewhat slower (noticeably so on large databases). Worth it though.

๐Ÿ”ฅ Example 20 โ€” Finding all regions containing an intersection of obj2 ๐Ÿ”ฅ

search |/ -maxdepth 0 -type region -above ( -name obj2 -bool + )

Prints all regions immediately above obj2 where obj2 is included using an intersection operation.

๐Ÿ‘‘ Example 21 โ€” Finding all Plate-Mode BoT Objects ๐Ÿ‘‘

search -type bot -param mode=plate

Prints all BoT primitives using "plate" mode, instead of the closed-mesh-requiring "volume" mode. Plate mode girlies rise.

๐Ÿซถ Example 22 โ€” Returning all Combinations That Have Given Object As a Member ๐Ÿซถ

search -above=1 -name example.s

Prints all combinations that have example.s as a member. This behavior is identical to the deprecated command dbfind.

๐Ÿ’… Example 23 โ€” Returning the Full Path(s) of a Given Object ๐Ÿ’…

search / -name example.s

Prints all paths to example.s. This behavior is identical to the deprecated command dbfindtree.

๐ŸŒˆ Example 24 โ€” Verbose Reporting of Search Information ๐ŸŒˆ

search allows for multiple levels of verbose reporting, and each one is giving more:

  1. The first level reports the total number of items found.
  2. The second level reports the boolean operator used at each step along the path.
  3. The next, and final, level reports the primitive type of each object along the path.

You can supply increased verbosity two different ways: as a single flag with each 'v' indicating an elevated level (search -vv..), as well as stacked -v flags (search -v -v ..). Both work, pick your fighter.

mged>search -v /all.g ! -type comb

    /all.g/box.r/box.s
    /all.g/cone.r/cone.s
    /all.g/ellipse.r/ellipse.s
    /all.g/light.r/LIGHT
    /all.g/platform.r/platform.s
    /all.g/tor.r/tor
    [6] items found in search

First level of verbosity prints the total number of items found in the search. This is especially useful when coupled with the '-exec' flag, which may or may not print the number of items effected by the exec.

mged> search -vv /all.g ! -type comb
    OR
mged> search -v -v /all.g ! -type comb

    /u all.g/u box.r/u box.s
    /u all.g/u cone.r/u cone.s
    /u all.g/u ellipse.r/u ellipse.s
    /u all.g/u light.r/u LIGHT
    /u all.g/u platform.r/u platform.s
    /u all.g/u tor.r/u tor
    [6] items found in search

Second level of verbosity prints the total number of items found in the search as well as the boolean operators at each step along the path.

mged> search -vvv /all.g ! -type comb
    OR
mged> search -v -v -v /all.g ! -type comb

    /u all.g(c)/u platform.r(r)/u platform.s(arb8)
    /u all.g(c)/u box.r(r)/u box.s(arb8)
    /u all.g(c)/u cone.r(r)/u cone.s(tgc)
    /u all.g(c)/u ellipse.r(r)/u ellipse.s(ell)
    /u all.g(c)/u tor.r(r)/u tor(tor)
    /u all.g(c)/u light.r(r)/u LIGHT(ell)
    [6] items found in search

At max verbosity, it prints the total number of items found in the search, the boolean operators, and finally the primitive type of each object along the path. That's the full tea โ˜•

๐Ÿ“ Example 25 โ€” Operating on Sets of search Results ๐Ÿ“

There are two available methods for working with sets of search results. Okay so:

Method one: the exec option, used in the following example to search for all regions below subtractions or intersections in the m35.g example model in BRL-CAD and draw the objects' wireframes in the display manager:

mged> search all.g -type region -and ( -below -bool - -or -below -bool + ) -exec draw "{}" ";"
mged> autoview

Method two: another possibility โ€” especially useful for doing multiple sequential operations which would be awkward to write out in a single search line โ€” is to assign the results of a search command to a Tcl variable.

To illustrate, let's randomize the colors of all regions in the "cab" assembly of the m35.g example model and then assign a glass shader with transparency as a follow-on step.

First, we collect the set of search results into a Tcl variable:

mged>  set glob_compat_mode 0
mged>  set search_results [search cab -type region]

Next we randomize the colors using Tcl's functionality (here we use random numbers and avoid any value less than 30 to keep objects more visible):

mged>  foreach i $search_results {attr set $i color [expr {int(rand()*225)+30}]/[expr {int(rand()*225)+30}]/[expr {int(rand()*225)+30}]}

Finally, we add transparency to the same regions:

mged>  foreach i $search_results {attr set $i shader {glass {tr 0.7 ri 1}}}
โš ๏ธ Note โš ๏ธ Remember, when you're setting region colors, to check for the presence of a regionid_colortable attribute on the _GLOBAL object. If such a table is present (the m35.g sample model has one, for example) you need to remove that table (and for MGED wireframes, re-open the database) before the colors on the individual regions will "take": mged> attr rm _GLOBAL regionid_colortable

๐Ÿ’€ DIAGNOSTICS ๐Ÿ’€

Errors will be returned if parsing of the arguments fails, or if one of the primaries' evaluation functions returns an error. So like, if the words don't make sense, or the thing you asked for breaks โ€” you'll get an error. No cap.

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Clifford Yapp

okay so the legal bit, but make it cute: this software is Copyright (c) 2008-2026 United States Government as represented by the U.S. Army Research Laboratory. Portions Copyright 1990, 1993, 1994 The Regents of the University of California, per copyright and license information from OpenBSD and NetBSD. For more details see the copyright statements in search.c and search.h. ๐Ÿซถโœจ

๐Ÿ› BUGS ๐Ÿ›

bugs resulting from incorrect parsing of shell pattern expressions are the result of libbu's fnmatch โ€” literally thatโ€™s the source, no cap. ๐Ÿ’€

๐Ÿ“ฌ BUG REPORTS ๐Ÿ“ฌ

got a bug or a problem? reports of bugs or problems should be submitted via electronic mail to devs@brlcad.org. ๐Ÿ’Œ


and thatโ€™s the whole page, bestie! footer sign-off: source/version BRL-CAD, page SEARCH(nged), and the date isnโ€™t shown on the footer line as given โ€” no invented dates here, periodt. the trailing MANPAGE word is acknowledged too. ๐ŸŽ€โœจ๐Ÿ’…

๐Ÿ“ฆ where this page comes from