Python: TypeError: 'DataObject' object does not support indexing

Category:
Scripting
Summary

For some Scripts that are working perfectly in \pf 15.2 and 15.1 I am always getting an Error message when I try to run them in \pf 2016 :

TypeError: 'DataObject' object does not support indexing

 

Answer

In \pf 15.2 and \pf 15.1 an old approach has been used for some methods like for example GetContents(), GetPage(),... This methods were returning a list as the result ([result,input1,input2) for example:

 

test=project.GetContents('02- FiveCycles Classical Model.Intcase',1)

test=[[<powerfactory.DataObject Study Cases2- FiveCycles Classical Model.IntCase>], '02- FiveCycles Classical Model.Intcase', 1]

 

In \pf 2016 this has been changed so that now this test variable contains only the result of the method.

test=[<powerfactory.DataObject Study Cases2- FiveCycles Classical Model.IntCase>]

If you have written a lot of scripts in 15.2 and you do not want to change them you can still use the old code. For this just change Interface Version of the ComPython Object to 1. This option is located under Script page in ComPython object. Have a look in attached png file. 

Back