from ghpythonlib.componentbase import executingcomponent as component
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Warning


class FindBeamByRhinoGuid(component):
    def RunScript(self, Beams, Guid):
        if not (Beams and Guid):
            return

        if not isinstance(Guid, list):
            Guid = [Guid]
        Guid = [str(g) for g in Guid]
        FoundBeam = []
        for beam in Beams:
            if beam.attributes.get("rhino_guid", None) in Guid:
                FoundBeam.append(beam)

        if not FoundBeam:
            self.AddRuntimeMessage(Warning, "No beams found!")

        return FoundBeam
