What I am trying to do is create a DataLab script that will create an asset tree regardless of whether it is a new tree or an existing tree in the workbook. Ideally I would just like to overwrite whatever tree is already there so that every time I run the script I end up with the same asset tree.
The problem I have is that apparently every time spy.assets.Tree is used, it tries to create a new tree. This contradicts the SPy documentation for Asset Trees 1 - Introduction, which says:
"Say you have an existing asset tree in Seeq, perhaps from an external datasource like OSIsoft PI AF, and you wish to clean up the tree or add calculations to it for further analysis. You can define a tree in SPy using this existing tree as a starting point by referring to it by name in the spy.assets.Tree input."
If I try to create a reference to my existing tree PM_SIM_AssetTree using PM_SIM_AssetTree = spy.assets.Tree('PM_SIM_AssetTree', workbook=scopedtoid), I get an error saying that there is an invalid item. The path suggests that it is trying to insert a new tree instead of creating a reference to the existing tree:
It doesn't matter whether I use workbook=scopedtoid or workbook=workbook_name, I get the same result. I know that the scopeid reference to my workbook is correct.
What is required to do either of these?
- detect the existence of a tree and remove it so that I can create the new one
- create the tree everytime with overwrite if it already exists