Jump to content

Import multiple signals to multiple parents in an asset tree


Go to solution Solved by John Brezovec,

Recommended Posts

Posted

I'm building an asset tree in SDL and I'm trying to import an ordered list of signals into multiple parents, one signal per parent.  

I've tried a couple variations on tree.insert and it doesn't seem to do what I want.

tree = spy.assets.Tree('My Tree')
tree.insert(children=['Area D','Area E','Area F'])
search_results = spy.search(query = {'Name': '/Area [D,E,F]_Compressor Power/'},
                            order_by = 'Name')
tree.insert(children= search_results,
                 friendly_name = 'Power',
                  parent = 'Area ?')
tree.visualize()
My Tree
|-- Area D
|   |-- Power   (is actually Area D_Compressor Power)
|-- Area E
|   |-- Power   (is actually Area D_Compressor Power)
|-- Area F
    |-- Power   (is actually Area D_Compressor Power)

This appears to do what I want, but each "Power" is actually the same tag.  I tried removing the friendly_name parameter next.

tree2 = spy.assets.Tree('My Tree')
tree2.insert(children=['Area D','Area E','Area F'])
search_results2 = spy.search(query = {'Name': '/Area [D,E,F]_Compressor Power/'},
                            order_by = 'Name')
tree2.insert(children= search_results2,
                 
                  parent = 'Area ?')
tree2.visualize()
My Tree
|-- Area D
|   |-- Area D_Compressor Power
|   |-- Area E_Compressor Power
|   |-- Area F_Compressor Power
|-- Area E
|   |-- Area D_Compressor Power
|   |-- Area E_Compressor Power
|   |-- Area F_Compressor Power
|-- Area F
    |-- Area D_Compressor Power
    |-- Area E_Compressor Power
    |-- Area F_Compressor Power

Now that's too many signals.  If I have an ordered list of signals that I pull from spy.search, how can I insert one per parent?

My goal is a tree that looks like the one below.  I'm hoping there's a method other than manual insertion or CSV import

 

My Tree
|-- Area D
|   |-- Area D_Compressor Power
|-- Area E
|   |-- Area E_Compressor Power
|-- Area F
    |-- Area F_Compressor Power

 

Thanks!

 

 

  • Seeq Team
  • Solution
Posted

Check out inserting with references, which will do what you're looking for:

search_results = spy.search({'Name': '/Area [D,E,F]_Compressor Power/',
                             'Datasource Name': 'Example Data'}, order_by='Name')

tree = spy.assets.Tree('My Tree')
tree.insert(children=['Area D', 'Area E', 'Area F'])
tree.insert(
    children=search_results,
    friendly_name='{{Name}}',
    parent='{{Name}(Area ?)_*}'
)

Results in a tree that looks like:

My Tree
|-- Area D
|   |-- Area D_Compressor Power
|-- Area E
|   |-- Area E_Compressor Power
|-- Area F
    |-- Area F_Compressor Power

In most cases though you're going to want the leaf node to have a 'generic' name (i.e. Compressor Power), and use the context of the tree to tell you what area it belongs to. You can also accomplish this using references:

search_results = spy.search({'Name': '/Area [D,E,F]_Compressor Power/',
                             'Datasource Name': 'Example Data'}, order_by='Name')

tree = spy.assets.Tree('My Tree')
tree.insert(children=['Area D', 'Area E', 'Area F'])
tree.insert(
    children=search_results,
    friendly_name='{{Name}Area ?_(*)}', # note the new inclusion of the capture group
    parent='{{Name}(Area ?)_*}'
)
Posted

Thank you, John. Apologies for asking a question that's clearly covered in the help.  I was even on that page!  For some reason my eyes just kept scrolling past that part.

I've got it working now.  Looking forward to scaling up my tree.

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...