MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / find_all

Method find_all

dm_control/mjcf/element.py:455–498  ·  view source on GitHub ↗

Finds all elements of a particular kind. The `namespace` argument specifies the kind of element to find. In most cases, this corresponds to the element's XML tag name. However, if an element has multiple specialized tags, then the namespace corresponds to the tag name of the most ge

(self, namespace,
               immediate_children_only=False, exclude_attachments=False)

Source from the content-addressed store, hash-verified

453 return found_element
454
455 def find_all(self, namespace,
456 immediate_children_only=False, exclude_attachments=False):
457 """Finds all elements of a particular kind.
458
459 The `namespace` argument specifies the kind of element to
460 find. In most cases, this corresponds to the element's XML tag name.
461 However, if an element has multiple specialized tags, then the namespace
462 corresponds to the tag name of the most general element of that kind.
463 For example, `namespace='joint'` would search for `<joint>` and
464 `<freejoint>`, while `namespace='actuator'` would search for `<general>`,
465 `<motor>`, `<position>`, `<velocity>`, and `<cylinder>`.
466
467 Args:
468 namespace: A string specifying the namespace being searched. See the
469 docstring above for explanation.
470 immediate_children_only: (optional) A boolean, if `True` then only
471 the immediate children of this element are returned.
472 exclude_attachments: (optional) A boolean, if `True` then elements
473 belonging to attached models are excluded.
474
475 Returns:
476 A list of `mjcf.Element`.
477
478 Raises:
479 ValueError: if `namespace` is not a valid namespace.
480 """
481 if namespace not in schema.FINDABLE_NAMESPACES:
482 raise ValueError('{!r} is not a valid namespace. Available: {}'.format(
483 namespace, schema.FINDABLE_NAMESPACES))
484 out = []
485 children = self._children if exclude_attachments else self.all_children()
486 for child in children:
487 if (namespace == child.spec.namespace or
488 # Direct children of attachment frames have custom namespaces of the
489 # form "joint@attachment_frame_<id>".
490 child.spec.namespace and child.spec.namespace.startswith(
491 namespace + constants.NAMESPACE_SEPARATOR) or
492 # Attachment frames are considered part of the "body" namespace.
493 namespace == constants.BODY and isinstance(child, _AttachmentFrame)):
494 out.append(child)
495 if not immediate_children_only:
496 out.extend(child.find_all(namespace,
497 exclude_attachments=exclude_attachments))
498 return out
499
500 def enter_scope(self, scope_identifier):
501 """Finds the root element of the given scope and returns it.

Callers 1

_default_identifierMethod · 0.45

Calls 1

all_childrenMethod · 0.95

Tested by

no test coverage detected