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?
Context:
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.
Edit:
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.
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.
windowList = system.gui.getWindowNames()
for i in windowList:
serializer = context.createSerializer()
serializer.addObject(system.nav.openWindow(i))
outputStream = FileOutputStream(outputDirectory+i+'.txt')
serializer.serializeXML(outputStream, 'utf-8')
outputStream.close()
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.
@zacht
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.
As pturmel noted,
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.