Read/Write Vision Template Definition Scripturally

From my designer-scoped custom module, I'm able to get a reference to the FPMIWindow instance of my vision windows (see method below from my ResourceEditor class). From there I can do all sorts of mutations.

Is there a similar way to mutate vision template definitions? Trying to avoid parsing the saved XML and mutating that, 'cause it's a huge headache.

private void test_debug2(){
var script_manager = context.getScriptManager();
PyStringMap locals = script_manager.createLocalsMap();
String code = """
system.vision.openWindow("%s")
w = system.vision.getWindow("%s")
""".formatted("test_3", "test_3");
try {
script_manager.runCode(code, locals, "<test_debug2>");
} catch (JythonExecException e) {
throw new RuntimeException(e);
}

PyObject py_win = locals.__finditem__("w");
if (py_win == null) {System.out.println("Fetching w from code locals returned null"); return;}

Object win = py_win.__tojava__(FPMIWindow.class);
System.out.println("Check it: " + win.getClass());
}

I think you want something like this, to get a VisionTemplate instance.

          final VisionClientContext visionContext = root.getAdapterContext();

          VisionTemplate template =
              visionContext.getTemplateManager().getTemplateInstance(templateId.getFolderPath());

Where root is the FPMIApp instance.

Probably not, as changes to an isolated instance won't be captured by a designer save op, I would expect.

A mimic of the designer's "open template" operation (for editing), returning the instance, would be needed, I think.

Probably WindowWorkspace#openTemplate(com.inductiveautomation.ignition.common.resourcecollection.ResourcePath) then.

context.getWorkspaceManager() can get you a WindowWorkspace (the key is com.inductiveautomation.factorypmi.designer.workspace.WindowWorkspace#WINDOW_WORKSPACE_KEY / "windows". There's no O(1) lookup of a workspace.

Someone owes you an adult beverage at ICC this year....