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

Method _attach

dm_control/mjcf/element.py:883–916  ·  view source on GitHub ↗

Attaches another element of the same spec to this element. All children of `other` will be treated as children of this element. All XML attributes which are defined in `other` but not defined in this element will be copied over, and any conflicting XML attribute value causes an erro

(self, other, exclude_worldbody=False, dry_run=False)

Source from the content-addressed store, hash-verified

881 'The attachment must have the same spec as this element.')
882
883 def _attach(self, other, exclude_worldbody=False, dry_run=False):
884 """Attaches another element of the same spec to this element.
885
886 All children of `other` will be treated as children of this element.
887 All XML attributes which are defined in `other` but not defined in this
888 element will be copied over, and any conflicting XML attribute value causes
889 an error. After the attachment, any XML attribute modified in this element
890 will also affect `other` and vice versa.
891
892 Children of this element which are not a repeated elements will also be
893 attached by the corresponding children of `other`.
894
895 Args:
896 other: Another Element with the same spec.
897 exclude_worldbody: (optional) A boolean. If `True`, then don't do anything
898 if `other` is a worldbody.
899 dry_run: (optional) A boolean, if `True` only verify that the operation
900 is valid without actually committing any change.
901
902 Raises:
903 ValueError: If `other` has a different spec, or if there are conflicting
904 XML attribute values.
905 """
906 self._check_valid_attachment(other)
907 if exclude_worldbody and other.tag == constants.WORLDBODY:
908 return
909 if dry_run:
910 self._check_conflicting_attributes(other, copying=False)
911 else:
912 self._attachments[other.namescope] = other
913 self._sync_attributes(other, copying=False)
914 self._attach_children(other, exclude_worldbody, dry_run)
915 if other.tag != constants.WORLDBODY and not dry_run:
916 other._alias_attributes_dict(self._attributes) # pylint: disable=protected-access
917
918 def _detach(self, other_namescope):
919 """Detaches a model with the specified namescope."""

Callers

nothing calls this directly

Calls 5

_sync_attributesMethod · 0.95
_attach_childrenMethod · 0.95

Tested by

no test coverage detected