Bug in methods for getting results
This bug is present in the following methods:
- getSParameters
- getPower
- getResultTreeItem
The former methods check if the runID received as input parameter is present in the project results by doing the following verification:
# Check that the desired runID exist in the project
if runID > len(runIDlist) - 1:
# It is necessary to subtract 1 since runIDlist begins with 3D:RunID:0
raise RuntimeError("ERROR: The specified runID is not present in the project results.")
This approach assumes that runIDlist begins with "3D:RunID:0". Nevertheless, when this resultID is not present in the list, this assumption can lead to unnecessarily raising an exception. This is specially evident when runIDlist = ["3D:RunID:1"]. Since len(runIDlist) - 1 would be 0, the exception will be raised for any value of runID (even for runID = 1, which should be a valid value).
An alternative and more correct way of solving this would be to parse the last element of runIDlist using a regular expression, to retrieve the value of its runID. Since CST is normally returning the runIDs in ascending order, this should allow to obtain the greatest available runID.
Additionally, when calling the GetResultFromTreeItem method of the COM interface, a resultID is passed by idexing resultIDlist like:
resultIDlist[runID]
Here it is also being assumed that the first element of resulIDlist it "3D:RunID:0". It is necessary to retrieve the runID of the first element in this list, and compensate the value of the input parameter runID when indexing resultIDlist.