I’m having a little issue with these if statements and where the system.tag.browesTags searches. Before these IF statements, notes + system.tag.browseTags() was working fine. But, I have to declare notes as an array first if I want to add this searchable criteria. Where am I going wrong here?
This script works:
notes = system.tag.browseTags("[default]Orifice Meters")
notes = notes + system.tag.browseTags('[default]Compressor Stations')
notes = notes + system.tag.browseTags('[default]COMMS')
This does not:
notes = []
if self.parent.getChild("toggleFlex_container").getChild("meterToggle").props.selected == True:
notes = notes + system.tag.browseTags("[default]Orifice Meters")
if self.parent.getChild("toggleFlex_container").getChild("compressorToggle").props.selected == True:
notes = notes + system.tag.browseTags('[default]Compressor Stations')
if self.parent.getChild("toggleFlex_container").getChild("commToggle").props.selected == True:
notes = notes + system.tag.browseTags('[default]COMMS')
If I don’t decalre notes as an array it will be undefined.
Also, when I use return(type(notes)) I see it is a PyArray.
Thanks for the help.
Java, unlike Python, has distinct types for arrays vs lists - so Jython has to inherit the same distinction, since it runs on the Java Virtual Machine.
Instead of literal concatenation, which delegates to the classes’ ability to understand their arguments, use explicit Python list methods. I’d be willing to bet the latter example would work if you change the calls to the following:
notes.extend(system.tag.browseTags("[default]Orifice Meters"))
See list.extend()
in the Python docs: https://docs.python.org/2.7/tutorial/datastructures.html#more-on-lists
1 Like
I’m still getting the same error:
notes = []
if self.parent.getChild("toggleFlex_container").getChild("meterToggle").props.selected == True:
notes.extend(system.tag.browseTags("[default]Orifice Meters"))
if self.parent.getChild("toggleFlex_container").getChild("compressorToggle").props.selected == True:
notes.extend(system.tag.browseTags('[default]Compressor Stations'))
if self.parent.getChild("toggleFlex_container").getChild("commToggle").props.selected == True:
notes.extend(system.tag.browseTags('[default]COMMS'))
Strange, this morning, the scripting is now working excellent. Maybe I must have copied in something incorrectly. Thanks for the help! Btw, I was trying to figure out, would there be a way to declare my list the appropriate data structure? What syntax would work? Like rather than notes = [], how do I declare notes to be the appropriate data structure (without using the extend function)
Thanks.
Well, basically the problem’s actually on our end. system.tag.browseTags()
should return a proper list of results, because lists are a fundamental Python data structure. Also, it’s worth noting, the ‘modern’ replacement method system.tag.browse
does return a list.
Arrays are just a fundamentally Java-ey concept - they’re baked into the language in a way that they’re not in Python, so Jython has to attempt to convert between the two, and it can get a little awkward. Using list.extend() is probably the best way to deal with them, honestly - then you get a ‘real’ Python list out of it, and can use all the extension methods available.