landscape_canvas_utils.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. """
  2. All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. its licensors.
  4. For complete copyright and license terms please see the LICENSE at the root of this
  5. distribution (the "License"). All use of this software is governed by the License,
  6. or, if provided, by the license below or the license accompanying this file. Do not
  7. remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. """
  10. import azlmbr.bus as bus
  11. import azlmbr.editor as editor
  12. import azlmbr.landscapecanvas as landscapecanvas
  13. from . import hydra_editor_utils as hydra
  14. def find_nodes_matching_entity_component(component_name, entity_id):
  15. """
  16. Finds all matching nodes given a component name and entity to search on.
  17. :param component_name: String of component name to search for
  18. :param entity_id: The entity ID to search for the given component node on
  19. :return List of matching nodes
  20. """
  21. component = editor.EditorComponentAPIBus(bus.Broadcast, 'GetComponentOfType', entity_id,
  22. hydra.get_component_type_id(component_name))
  23. if component.IsSuccess():
  24. component_id = component.GetValue()
  25. component_node = landscapecanvas.LandscapeCanvasRequestBus(bus.Broadcast, 'GetAllNodesMatchingEntityComponent',
  26. component_id)
  27. if component_node:
  28. print(f"{component_name} node found on entity {entity_id.ToString()}")
  29. return component_node