rofunc.utils.robolab.formatter.mjcf_parser.namescope#

An object to manage the scoping of identifiers in MJCF models.

1.  Module Contents#

1.1.  Classes#

NameScope

A name scoping context for an MJCF model.

1.2.  API#

class rofunc.utils.robolab.formatter.mjcf_parser.namescope.NameScope(name, mjcf_model, model_dir='', assets=None)[source]#

A name scoping context for an MJCF model.

This object maintains the uniqueness of identifiers within each MJCF namespace. Examples of MJCF namespaces include ‘body’, ‘joint’, and ‘geom’. Each namescope also carries a name, and can have a parent namescope. When MJCF models are merged, all identifiers gain a hierarchical prefix separated by ‘/’, which is the concatenation of all scope names up to the root namescope.

Initialization

Initializes a scope with the given name.

Args:

name: The scope’s name mjcf_model: The RootElement of the MJCF model associated with this scope. model_dir: (optional) Path to the directory containing the model XML file.

This is used to prefix the paths of all asset files.

assets: (optional) A dictionary of pre-loaded assets, of the form

{filename: bytestring}. If present, PyMJCF will search for assets in this dictionary before attempting to load them from the filesystem.

property revision#
increment_revision()[source]#
property name#

This scope’s name.

property files#

A set containing the File attributes registered in this scope.

property assets#

A dictionary containing pre-loaded assets.

property model_dir#

Path to the directory containing the model XML file.

property mjcf_model#
property parent#

This parent NameScope, or None if this is a root scope.

property root#
full_prefix(prefix_root=None, as_list=False)[source]#

The prefix for identifiers belonging to this scope.

Args:
prefix_root: (optional) A NameScope object to be treated as root

for the purpose of calculating the prefix. If None then no prefix is produced.

as_list: (optional) A boolean, if True return the list of prefix

components. If False, return the full prefix string separated by mjcf.constants.PREFIX_SEPARATOR.

Returns:

The prefix string.

add(namespace, identifier, obj)[source]#

Add an identifier to this name scope.

Args:
namespace: A string specifying the namespace to which the

identifier belongs.

identifier: The identifier string. obj: The object referred to by the identifier.

Raises:

ValueError: If identifier not valid.

replace(namespace, identifier, obj)[source]#

Reassociates an identifier with a different object.

Args:
namespace: A string specifying the namespace to which the

identifier belongs.

identifier: The identifier string. obj: The object referred to by the identifier.

Raises:

ValueError: If identifier not valid.

remove(namespace, identifier)[source]#

Removes an identifier from this name scope.

Args:
namespace: A string specifying the namespace to which the

identifier belongs.

identifier: The identifier string.

Raises:

KeyError: If identifier does not exist in this scope.

rename(namespace, old_identifier, new_identifier)[source]#
get(namespace, identifier)[source]#
has_identifier(namespace, identifier)[source]#