Get the runtime message of a component using ghpython

Hi I have a question I’m hoping someone has an answer to. Using ghpython I’m trying to get a list of runtime messages of a component(the warnings and errors in the bubble the top right of component).
image

What I’m essentially trying to do is to collect all the runtime warnings within a cluster and display it on the cluster itself. I’ve tried using “.RuntimeMessages” method but this returns me the “<built-in method RuntimeMessages of XXX object at= XXX” and not the actual warning text. Does anyone know how I might be able to retrieve the information?

Any suggestions are greatly appreciated. Thank you in advance!

the code I have currently looks like below:

import Grasshopper
mainDoc = ghenv.Component.OnPingDocument()
for obj in mainDoc.Objects:
    if type(obj)== Grasshopper.Kernel.Special.GH_Cluster:
        messages = []
        levels = []
        for c_obj in obj.Document("").Objects:
            a= c_obj.NickName
            level =  c_obj.RuntimeMessageLevel
            levels.append(level)
            message = c_obj.RuntimeMessages
            messages.append(message)
            print message
        for i in range(len(messages)):
            obj.AddRuntimeMessage(levels[i],str(messages[i]))


Looks wrong… Each obj could contain more than a single Runtime message.

Do you know how I might be able to get each individual message? c_obj.RuntimeMessages just returns “<built-in method RuntimeMessages of XXX object at= XXX” not the message itself

This is a method and you store it in a list. So you collect the method reference, but you do not execute it

I can‘t test it now, but I would expect messages = obj.RuntimeMessages(GH_RuntimeMessageLevel.Error)
which returns a list of strings so you do need to iterate it and append it to your final list

That did the trick. Thank you!