MCPcopy
hub / github.com/CadQuery/cadquery / _query

Method _query

cadquery/assembly.py:317–355  ·  view source on GitHub ↗

Execute a selector query on the assembly. The query is expected to be in the following format: name[?tag][@kind@args] valid example include: obj_name @ faces @ >Z obj_name?tag1@faces@>Z obj_name ? tag obj_name

(self, q: str)

Source from the content-addressed store, hash-verified

315 return self
316
317 def _query(self, q: str) -> Tuple[str, Optional[Shape]]:
318 """
319 Execute a selector query on the assembly.
320 The query is expected to be in the following format:
321
322 name[?tag][@kind@args]
323
324 valid example include:
325
326 obj_name @ faces @ >Z
327 obj_name?tag1@faces@>Z
328 obj_name ? tag
329 obj_name
330
331 """
332
333 tmp: Workplane
334 res: Workplane
335
336 query = _grammar.parse_string(q, True)
337 name: str = query.name
338
339 obj = self.objects[name].obj
340
341 if isinstance(obj, Workplane) and query.tag:
342 tmp = obj._getTagged(query.tag)
343 elif isinstance(obj, (Workplane, Shape)):
344 tmp = Workplane().add(obj)
345 else:
346 raise ValueError("Workplane or Shape required to define a constraint")
347
348 if query.selector:
349 res = getattr(tmp, query.selector_kind)(query.selector)
350 else:
351 res = tmp
352
353 val = res.val()
354
355 return name, val if isinstance(val, Shape) else None
356
357 def _subloc(self, name: str) -> Tuple[Location, str]:
358 """

Callers 1

constrainMethod · 0.95

Calls 4

WorkplaneClass · 0.85
_getTaggedMethod · 0.80
addMethod · 0.45
valMethod · 0.45

Tested by

no test coverage detected