APSIMInitiative / ApsimX

ApsimX is the next generation of APSIM
http://www.apsim.info
Other
132 stars 161 forks source link

Reporting properties of items in a list #3653

Closed lie112 closed 5 years ago

lie112 commented 5 years ago

I am trying to report a property of a model item in a list in the Report. It doesn't seem that the variable string supports Model.Item[index].PropertyName I also tried creating a method Model.GetValue(int index) in the parent holding the list, but this function is not supported by the code getting the values either. Does anyone have a work around for this? Rather than use lists of models provided in the UI, I create a List in the background so that any code changes to these models does not influence the user setup for the next run. Now I need to report properties of some items in the list.

hol430 commented 5 years ago

This seems to be working ok for me. Here is my setup:

Manager:

public IModel[] Arr
{
    get
    {
        return Apsim.ChildrenRecursively(Apsim.Parent(this, typeof(Simulation))).ToArray();
    }
}

Report:

[Manager].Script.Arr[2].Name

Output:

Summary (name of the second model).

The array-indices in the report are 1-indexed (!), which is something to watch out for. Could you upload your .apsimx/.met files?

lie112 commented 5 years ago

What if Arr is a List? You can normally used List[index] to obtain items. Does this work in reports?

hol430 commented 5 years ago

Yep, that also seems to work for me. Is this not working for you?

lie112 commented 5 years ago

Thanks. I had missed making the List a property and then there was a wayward report with an erroneous line causing problems. Adam