Jump to content

Overwrite asset tree?


Recommended Posts

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


Link to comment
Share on other sites

Hi Pat,

Errors like this can sometimes occur if there are items in your pre-existing tree that are unexpectedly archived. I would use spy.search to look for any such items, particular items related to PM_SIM_AssetTree >> LAB >> PM_SIM_AssetTree >> REEL.

search_results = spy.search({'Path': 'PM_SIM_AssetTree'}, workbook=scopedtoid, include_archived=True)
search_results[search_results['Archived'] == True]

Another possibility is that you have an item in your tree with the same name as its parent asset. SPy Trees unfortunately does not support the handling of such items. If this is the case for you, then you can still proceed by using the spy.assets module, by reconstructing your tree from scratch using spy.assets.Tree, or by manually renaming any such items using the API reference page in Seeq.

If neither of these leads prove fruitful, I can assist further with the help of some more information about your current asset tree. Run the following code

search_results = spy.search({'Path': 'PM_SIM_AssetTree'}, workbook=scopedtoid, include_archived=True, all_properties=True)

and share the resulting search_results.csv file in your next post, and I can take a deeper look.



Link to comment
Share on other sites

I had an archived asset tree 'PM_SIM_AssetTree' with items in it that were not archived.  This was because of a prior error on my part.  To fix it, I used an API call to delete it.  Afterwards, the script runs each time and overwrites the existing tree

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...