Perspective properties store and retreive using Document Tag

Hello All,

We are starting to look into the power chart control in Perspective. We would like to provide a button on the screen that will save the chart config to a memory document tag. This can later be recalled by reading this tag and overwriting the chart properties with the value of the tag. Has anyone done this? If so did you it similiarly or is there a better way?

I have this script on a button.

from com.inductiveautomation.ignition.common import TypeUtilities
# Grab the property you want to save as a JSON object
jsonObj = TypeUtilities.pyToGson(self.getSibling(PowerChart).props)
system.tag.writeBlocking([[WhitewaterTags]ChartConfig],[jsonObj])

This correctly writes the props JSON object into the tag, how do i now read this tag and write it back to the powerchar props? TypeUtilities.gsonToPy? Doing this throws an error.

Thanks,

Frank

You may want to look into the Ad Hoc Trend component on the Exchange.

If you’re just trying to create some pre-made trends, I think it’s what you’re after. Admittedly I haven’t spent much time with it, but from the description it’s capable of saving trends on a global or per-user basis.

I thought about that. I was hoping to roll my own with some scripting as I’d like to save the trend config inside a pid loop udt for instance.

Thanks,

Frank

I suppose the next question is once i get the powerchart.props into a document tag,how do i then write the JSON back over top of the chart component props?

Thanks,

Frank

Document objects, such as you’d get from system.tag.read*("some/document/tag"), have a toDict() or something like that method on them, which recursively converts them into ‘plain’ Python dictionaries/lists/objects. You should be able to directly assign those objects to a Perspective property. It’d be nice if you didn’t have to do the intermediate step, but I believe it’s still necessary for now.

1 Like

Paul,

Thanks. After doing some more reading through other posts, I was unaware this function existed until now. So my current setup is a power chart and 2 buttons. One save trend config button with this script behind it.

from com.inductiveautomation.ignition.common import TypeUtilities


# Grab the property you want to save as a JSON object|
jsonObj = TypeUtilities.pyToGson(self.getSibling(PowerChart).props)

system.tag.writeBlocking([[WhitewaterTags]ChartConfig],[jsonObj])

The other button is a recall settings button with this script behind it.

chartProps = system.tag.readBlocking([[WhitewaterTags]ChartConfig])

savedProps = chartProps[0].value.toDict()
self.getSibling(PowerChart).props = savedProps

I have read in another thread this may not be working because of date format isues in the gsontoPy when loading the JSON back into the trend.props…

These scripts are not throwing any errors in the event log but the chart does not update to saved settings when click the recall button. Some of the methods in the Ad Hoc chart assign members of the props individually rather than wholesale in my approach. Is this the issue? Thanks for your help.

Frank

I broke out the save and restore into multiple JSON objects and have it working successfully. Thanks for the support.

Frank