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)
| 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 | """ |
no test coverage detected