Convert Param Object to PyDictionary

I'm trying to create a template that opens a popup with a dynamic parameter set. The issue I've run into is that the system.perspective.openPopup function only accepts a dictionary to define the parameters, but I want to use an object in my template params called 'PopupParams'.

Essentially I need to convert 'PopupParams' to a dictionary, right now I accomplish that by encoding then decoding the object as a json string, removing the object wrapper.

	PopupParams = self.view.params.PopupParams
	ParamString = system.util.jsonEncode(PopupParams)
	ParamDict = system.util.jsonDecode(ParamString)
	system.perspective.openPopup(self.view.params.PopupID, self.view.params.PopupPath, params = ParamDict)

It works fine, but it's very gross, is there a better solution?

Where and how is the object defined ? What's its exact type ?

dict(self.view.params.PopupParams) might work; if it's not a deep dictionary.

If you do need a deep copy, you could try the approaches mentioned here:

Or you could use Ignition Extensions' system.util.deepCopy.

1 Like

Thanks, I think creating my own recursive deep copy function is the way to go, better visibility to other developers in my team. Unfortunately, we're unable to use community extensions as a restriction by our clients.

Actually, if you're going that way I kinda prefer @justin.brzozoski's duck-typing approach:

1 Like

I remember seeing that last week although I couldn't quite wrap my head around it then, @pascal.fragnoud 's explanation in the other thread helped to clear up the confusion. Thanks mate.