Custom AddRuntimeMessage instead of "Input fails to collect data"

Hi all,

I’m encountering a problem I find no answer to in the API reference nor on the forum.
I’m trying to write a plugin communicating with an external software via its own interface (RFEM5 and RF-COM). I’ve created custom types and params to handle my data and pass it to GH components. In my parameter definition, I overwrote the Prompt_Plural, which calls the software built-in pick tool.
Data collection can fail in various ways: the user closes the selection tool without having selected anything, or simply no model is open. I would like runtime messages to reflect that so I tried to call AddRuntimeMessage in my code in various places to no avail. The error messages simply don’t show up when I provoke the error. Instead, I get the traditionnal warning “1. Input failed to collect data” which is much less informative in that particular case. Is it possible to display my custom runtime messages in that particular case? Am I doing it correctly? Here’s the code:

protected override GH_GetterResult Prompt_Plural(ref List<RFEMTypes.RFEMMemberType> values)
{
    IModel model = Initialize();

    if (model == null)
    {
        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No RFEM model seems to be open.");
        return GH_GetterResult.cancel;
    }

    // Gets model data
    IModelData data = model.GetModelData();
    data.EnableSelections(true);

    // picks objects with built-in RFEM pick tool that returns a string
    string strPick = "";
    model.GetActiveView().PickObjects(ToolType.SelectMembers, ref strPick); // picks the objects in RFEM and puts them in a str

    if (string.IsNullOrEmpty(strPick))
    {
        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No valid member was picked.");
        Unitialize(ref model);
        return GH_GetterResult.cancel;
    }
    else
    {
        values = new List<RFEMTypes.RFEMMemberType>();

        foreach (int val in ParseIndices(strPick))
        {
            RFEMTypes.RFEMMemberType mem = new RFEMTypes.RFEMMemberType(-1);
                    
            if (mem.CastFrom(val)) // return true if cast succeeded
                values.Add(mem);
            else
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "A member provided is invalid. Please check the output.");
        }

        Unitialize(ref model);
        return GH_GetterResult.success;
    }
}

I’m sensing that has something to do with the return value of the method but I’m not sure. In a more general sense, any guidance on how runtime messages work would be very much appreciated.

Many thanks,

1 Like

I’m facing the same problem and no luck with it so far
@aduffau, have you found the solution?

Prompt_Plural is a method that does not belong to an IGH_Component, but a GH_PersistentParam. I guess you would see your messages if the elements are set from a param, but not done from a component ? In other words error messages generated by the parameter don’t rise up to the component level.

I did this but inside SolveInstance, not inside Prompt_Plural.

You could try to set the inputs of the component as optional, so the Input parameter xxx failed to collect data never shows up.

Then after DA.GetData(), test for your various error messages.
It seems you can access the runtime messages from an input param : Params.Input[0].RuntimeMessages()

Untested solution there, maybe a step in the right direction.