diff --git a/tests/test_line.py b/tests/test_line.py index 081293ae2..288945d3c 100644 --- a/tests/test_line.py +++ b/tests/test_line.py @@ -1092,4 +1092,14 @@ def test_insert_repeated_names(): line.insert_element("m2",xt.Marker(),at="d") assert line.element_names[0]=="m2" +def test_line_table_unique_names(): + line = xt.Line( + elements = {"obm": xt.Bend(length=0.5)}, + element_names= ["obm","obm"] + ) + table = line.get_table() + assert np.all(np.unique_counts(table.name).counts == 1), "Not all elements are unique" + for name, env_name in zip(table.name, table.env_name): + if name == '_end_point': continue + assert line[name] == line[env_name] diff --git a/xtrack/line.py b/xtrack/line.py index 786cc118e..12df7b68a 100644 --- a/xtrack/line.py +++ b/xtrack/line.py @@ -4057,6 +4057,8 @@ def __getitem__(self, key): return self.vv[key] elif hasattr(self, 'lines') and key in self.lines: # Want to reuse the method for the env return self.lines[key] + elif "::" in key and (env_name := key.split("::")[0]) in self.element_dict: + return self[env_name] else: raise KeyError(f'Name {key} not found')