landscape_canvas_utils.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. import azlmbr.bus as bus
  7. import azlmbr.editor as editor
  8. import azlmbr.landscapecanvas as landscapecanvas
  9. import editor_python_test_tools.hydra_editor_utils as hydra
  10. def find_nodes_matching_entity_component(component_name, entity_id):
  11. """
  12. Finds all matching nodes given a component name and entity to search on.
  13. :param component_name: String of component name to search for
  14. :param entity_id: The entity ID to search for the given component node on
  15. :return List of matching nodes
  16. """
  17. component_type_id = hydra.get_component_type_id(component_name)
  18. component = editor.EditorComponentAPIBus(bus.Broadcast, 'GetComponentOfType', entity_id,
  19. component_type_id)
  20. if component.IsSuccess():
  21. component_id = component.GetValue()
  22. component_node = landscapecanvas.LandscapeCanvasRequestBus(bus.Broadcast, 'GetAllNodesMatchingEntityComponent',
  23. component_id)
  24. if component_node:
  25. print(f"{component_name} node found on entity {entity_id.ToString()}")
  26. else:
  27. print(f"Failed to find {component_name} node on entity {entity_id.ToString()}")
  28. return component_node