If it’s public, what is the java class/method behind the ‘Copy XML to Clipboard’ option in the Shift + Right Click context menu on a vision window in the the Project Browser?
When our Ignition environment was first created (and for a few years after that), the tag structure was not well planned. Tags were pulled in from processors and never used. Multiple tags were created in different folders for a single OPC path on the same device; etc. In trying to go back and fix some of this, I’ve had good success manually copying XML to a text file and using python to find tag paths that are used in the window. I’d love to be able to automate the Copy XML step if I can.
What I’d really like to find is the class/method that returns the XML String so I can write to a file. I’m less interested in the String → Clipboard step.
I posted this in the afternoon/evening (across the US). Bump to see if there’s any interest in the morning.
Start by obtaining a DesignerContext. (:
From that, obtain a fully-configured serializer with .createSerializer().
Then add the window object to the serializer, and use .serializeXML() to yield your desired string. Or use one of the peer methods to serialize directly to a file or other stream.
You’ll note that there is also a
.createDeserializer() method. Please report back when you reach the bottom of this rabbit hole… (:
Working with contexts is totally unsupported, of course.
Note that this is based on an open window. I’m sure there’s a way to extract the serialized form from the window resource. No idea on that.
Naturally. It almost goes without saying.
Based on the number of (: in your reply I suspect the rabbit hole is probably pretty deep, but I’ll report as far as I get.
Noted. Thanks for pointing me in the right direction.
windowList = system.gui.getWindowNames()
for i in windowList:
serializer = context.createSerializer()
outputStream = FileOutputStream(outputDirectory+i+'.txt')
I imagine there is probably a more elegant way to do this, but this script accomplishes my goal. I haven’t looked into
createDeserializer() (yet). Alas, there’s only so long I can spend scripting my work before I have to do the work…
Thanks again @pturmel for the help and thanks to @nmudge in another thread for the code to get a gateway context.
Thanks for the above snippet, its almost exactly what I need. I cant get it to work though. I’ve added the following on the top
from com.inductiveautomation.ignition.designer.model import DesignerContext
context = DesignerContext
but I keep getting an error saying it expects atleast 1 arg, but not sure what to pass to it
That isn’t how I got the designer context. I used some code from this forum post.
so tread carefully and probably don’t use this in a production setting. I used it to partially automate some mass tag renaming I was very closely supervising. I wouldn’t trust it for much more than that, and I certainly wouldn’t trust it across Ignition versions.
In the forum thread I linked you will also see @Robert.McKenzie warn against relying on this sort of implementation, so consider this a double warning.