In Perspective, is there a way to hide a component if a tag doesn't exist?

So i am building a view that i will use for pointing at different pump stations based what was selected by the operator. Each pump station has varying amounts of pumps on them. Some will have just one, and others up to 4.

I am building the main view to contain 4 pumps since it is the max but i cant figure out if there is a way to hide extra pumps if I am pointing to a station that lets say has only 2 pumps?

What is the best way to do this? Is it even possible in Perspective?

I would also like to use this method for things like alarming indicator labels when one station has a generator and another doesn't, I would like to hide the generator alarm component if there is no tags for it.

Hopefully this all makes sense.
But I really want to avoid building out separate screens for each individual station, as building just one and having it point to the correct station is a big plus for using perspective.

Try this, system.tag.exists | Ignition User Manual

Create a tag binding to the tag, then in an expression transform, you can add the following

(toInt(qualityOf({value}))&0x7fff)=519

A code of 519 means the tag does not exist in the tag structure, vs the tag having a different bad quality.

An expression will be be more performant than a script transform.

4 Likes

You can also dynamically generate content based on what tags are defined within a folder in your tag database. The general use case would be to structure a section of your tag database with folders and dynamically create instances of a template. In this example I did that using a flex repeater to create instances of a template and pass in the parameters required to indirect bind the template.

You just manually create an instance in your flex repeater and copy/paste that node to notepad to get the json structure. Then you make your script populate it dynamically in a transform.

2 Likes

Unfortunately what everyone recommended did not work for me..
I was able to figure it out through an expression on the Display Property of the object.
This is it for anyone who needs this feature in the future.

!isNull(tag("[default]Lift Stations/" + {view.params.stationName} + "/Pump3"))

Based on the tag existing it will make the value of Display true or false, hiding an object if no tag is found.

Let me know if this worked for you!

Note that you shouldn't need this extra indirection/bitwise trickery - we overload the equality operator for quality codes, so
qualityOf({value}) = "Bad_NotFound" or qualityOf({value}) = 519 should both work the same.

Don't use tag in an UI binding. Create an additional indirect tag binding on a custom property and then use an expression on display that brings in that custom property and does your isNull logic.

2 Likes

Thanks for the response, just so i can have a better understanding, what is the reason I shouldn't use a tag in UI binding?

Basically, the tag() function is slow, and will slow down the rest of your UI disproportionately if overused. There are rare circumstances where it's appropriate, but Perspective isn't one of them.

2 Likes

It's been discussed a few days ago. See,

1 Like

Okay i see! This will definitely be overused, would you mind giving an example or explaining a little more in detail of how to go about the way you mentioned with

"Create an additional indirect tag binding on a custom property and then use an expression on display that brings in that custom property and does your isNull logic."

Thanks in advance.

  1. Create a custom property on the same component you're already working with.
    Add an indirect tag binding to it; this will replace the tag() function - give it the "[default]Lift Stations/" + {view.params.stationName} + "/Pump3" part of your expression.
    Tag Bindings in Perspective | Ignition User Manual

  2. In the expression binding you already have on the display property, use the property selector to reference that custom property with the indirect tag binding on it, instead of the tag() function call. So it'll become something like:
    !isNull({path.to.custom.property})

2 Likes

This worked! thank you for taking the time to explain and give an example.