QueryAPI¶
Interface QueryAPI
Hierarchy (View Summary)
- QueryAPI
Index
Methods
Methods
query
Executes a query for metadata of structure or aux nodes. For an explanation of the query format, see the QueryAPI.
Parameters
- query: string | Query
The query to execute. Can be either a query object or a JSON string.
OptionalnodeID: numberOptional node ID specifying a subtree to which the query should be scoped. If not provided, the query is scoped to the whole space.
Returns Promise<QueryResult>
A promise that resolves to an object containing the result data and any errors that have occurred during query execution. If one or more errors have occurred, the result data must be considered incomplete.
- query: string | Query
Search Nodes & Query Metadata: The QueryAPI
Overview
The QueryAPI allows you to filter nodes and query their metadata. Each query is scoped to either structure or aux nodes and consists of a set of conditions and a set of selectors. For each node that matches the conditions, the values specified by the selectors are returned. The result contains a data array with one entry for each matching node. Each entry is an array containing the selected values for the corresponding node in the same order as the selectors in the query. For example, if the selectors are
['nodeId', 'label'], then each entry in the result will be an array with the node ID as the first element and the label as the second element.The QueryAPI currently has several known issues. For details, see section "Known Issues" below.
Quick Start
Conditions
By convention, each query must contain one top-level
nodeTypecondition with the valueauxorstructure. The conditions have an implicit AND relation and can contain nested logical groups. For type information, see QueryCondition.Several of the supported conditions have the form
{metadata: <key>, <operator>: <value>}. For these, the following rules apply:equals,equalsAny,contains, and numeric comparison operators. Whileequalssupports strings, numbers, and subqueries,equalsAnyandcontainsonly support strings. For details, see QueryCondition.*can be used as a wildcard for any sequence of characters.caseSensitiveoption can be added to the condition. By default, string comparisons are case-insensitive.General Conditions
{nodeType: "aux" | "structure"}: Sets the node type.{nodeId: number}: The node with the specified ID.{metadata: "label", <operator>: string}: Nodes with a matching label. This condition operates on the node labels defined in the original CAD files. Any client-side changes to the node labels are ignored.Experimental
{property: <property name>, <operator>: <value>}: Nodes with a matching property value. The available property names are the string values of the Property enum. This condition does not support properties which are matrices or objects. This condition only operates on nodes which are loaded in the client. Note: this condition is experimental and may be changed in future releases. Mixing ofpropertyandmetadataconditions in logical condition groups is not yet supported.Aux Node Conditions
In addition to the general conditions, aux nodes support the following conditions. For an explanation of the aux node metadata namespacing, see the section "Aux Node Metadata Namespacing" below.
{metadata: "auxProperties.pmiType", <operator>: string}: Aux nodes with a matching PMI type.{metadata: "auxProperties.<key>", <operator>: <value>}: Aux nodes with a matching aux properties entry.{metadata: "auxAttributes.<key>", <operator>: <value>}: Aux nodes with a matching aux attributes entry.{pointsTo: number}: Aux nodes that point to the aux node with the specified ID.{faceHandle: TopologyHandle}: Aux nodes connected to the specified face. See TopologyAPI.{extFaceLink: string}: Aux nodes with the specified external face link.Structure Node Conditions
In addition to the general conditions, structure nodes support the following conditions:
{metadata: <key>, <operator>: <value>}: Structure nodes with a matching metadata entry.{ancestors: <condition array>}: Structure nodes that have an ancestor which matches all of the specified conditions.Logical Groups
{and: <condition array>}: Nodes that match all of the specified conditions.{or: <condition array>}: Nodes that match one or more of the specified conditions.{not: <condition array>}: Nodes that do not match any of the specified conditions.Selectors
The selectors specify which values are returned for each matching node. The available selectors depend on the node type and include the node ID, metadata entries, and topology handles.
General Selectors
nodeId: The ID of the node.label: The label of the node, as defined in the original CAD file. Any client-side changes to the node label are not reflected in this selector.Experimental
property.<property name>: The value of the specified property. The available property names are the string values of the Property enum. Note: this selector is experimental and may be changed in future releases.Aux Node Selectors
metadata.auxProperties.pmiType: The PMI type of the aux node.metadata.auxProperties.<key>: The value of the specified aux property, ornullif non-existent.metadata.auxProperties.*: All aux properties of the node aggregated into an object. Each metadata key will be prefixed withmetadata.auxProperties..metadata.auxAttributes.<key>: The value of the specified aux attribute, ornullif non-existent.metadata.auxAttributes.*: All aux attributes of the node aggregated into an object. Each metadata key will be prefixed withmetadata.auxAttributes..faceHandles: An array of TopologyHandles for the faces connected to the aux node, or an empty array if the aux node is not connected to any face.faceHandle: This is a legacy selector. New code should use thefaceHandlesselector instead. This selector returns TopologyHandles for the faces connected to the aux node and changes the result structure in the same way as theextFaceLinkselector described below.extFaceLinks: The external face links of the aux node, as strings. This selector changes the result structure in the following way: If an aux node has multiple external face links, there will be multiple result entries for that node, each with a different external face link and the same values for all other selectors. If an aux node has no external face links and there are no other selectors, then the result will not contain an entry for that node. If an aux node has no external face links but there are other selectors, then this selector will return the string"undefined"for that node.Structure Node Selectors
metadata.<key>: The value of the specified metadata entry, ornullif non-existent.metadata.*: All metadata entries of the node aggregated into an object. For backward compatibility, each metadata key will be prefixed withmetadata.structMetaData..ancestors.<selector>: An array with the value of the nested selector for each ancestor of the node. The ancestors are ordered from highest to lowest in the hierarchy. This selector can not contain anotherancestorsselector.Link Depth
The
linkDepthproperty of the query defines how many levels of linked 3D models are included in the query. The default value is1, which means that the scope root model and its directly linked models are included. The scope root model is defined by the optionalnodeIDparameter of the function QueryAPI.query. If the root model is not specified and the link depth is1, then all top-level models of the space are considered.Error Handling
Error codes for any errors that occur during query execution are returned in the
errorsproperty of the query result. If one or more errors have occurred, the result data must be considered incomplete.Known Issues
Mixing of
metadataandpropertyconditions in logical condition groups is not yet supported.Inconsistent "all nodes" semantics: If a query does not contain any conditions except for
nodeType, it matches all nodes of the specified type. Similarly, anotcondition matches all nodes except for some specific ones. Before the introduction ofpropertyconditions and selectors, the QueryAPI only operated on added 3D models and ignored any additional nodes created via the webvis API. With the introduction ofpropertyconditions and selectors, we aim to extend the query scope to all nodes in the 3D space. However, not all condition and selector types have been updated to this extended scope yet. In particular, if a query does not contain anypropertyconditions or selectors, then the behavior will currently be the same as before.Inconsistent ancestor paths: Before the introduction of
propertyconditions and selectors,ancestorsconditions and selectors only operated on the ancestor path of a node within its 3D resource. Now, whenancestorsconditions or selectors are used together withpropertyconditions or selectors, the complete ancestor path in the webvis node tree is considered. However, usingancestorsconditions or selectors together withmetadataconditions or selectors will still only consider the ancestor path within the node's 3D resource.Multiple result entries for certain nodes: When a node in a 3D model links to another 3D model, then the linking node and the root node of the linked model are merged in the webvis node tree. Currently, the query evaluation logic does not take this merging into account for most conditions and selectors. As a result, the corresponding nodes may not be filtered as expected and may have multiple entries in the query result.
Aux Node Metadata Namespacing
Aux node metadata entries are grouped into the two namespaces
auxAttributesandauxProperties. The first,auxAttributes, contains all key-value pairs that are associated with a given aux node. Here, all values are stored as strings. The second namespace,auxProperties, contains only a subset of the key-value pairs, but supports both strings and numbers as values. For aux node metadata conditions, numerical comparison operators can only be used with numerical values from theauxPropertiesnamespace.To discover the available
auxAttributesorauxPropertieskeys for a given node, you can use the selectorsmetadata.auxAttributes.*andmetadata.auxProperties.*, which return all entries of the respective namespace aggregated into an object:Examples
Querying a specific metadata value of a structure node:
Querying the labels of all ancestors for each node that has a specific metadata entry:
Query with complex nested conditions:
Query with subquery as condition value. The subquery must return exactly one value:
See