Skip to content

model_builder::find_body_by_name #21

Description

@Saadmaghani
# Returns deep copy of body in XML, using passed in name
def find_body_by_name(xml_root, target_name=None):
    if target_name is not None:
        for body in xml_root.findall(".//body"):
            if body.attrib.get("name") == target_name:
                return copy.deepcopy(body)
    worldbody = xml_root.find(".//worldbody")
    if worldbody is not None and len(worldbody) > 0:
        for body in worldbody.findall("body"):      
            return copy.deepcopy(body)
    return None

Hey guys, I had a question about this, specifically the following part:

for body in worldbody.findall("body"):      
            return copy.deepcopy(body)

why are you returning just the first element and not all of them?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions