Trigger Navigation in Designer

Is there a way to automatically trigger navigation to a resource within the Designer Context?

Ideally something similar to when you Find/Replace and you select a found item and it navigates directly to the view.

Specifically, I want to be able to trigger opening a Perspective resource from within a module. However if it was a generic resource opening function, that would be nice too.

If you're on a new enough SDK (8.1.34/whenever the tag reference tracker was introduced), you can use the Location/Locatable classes as your entrypoint.

Construct a com.inductiveautomation.ignition.designer.location.Location, then pass it to the module you want to locate (use Locatable.forward to allow passing any random module ID):

        String perspectiveModuleId = "com.inductiveautomation.perspective";
        DesignerModuleHook perspective = context.getModule(perspectiveModuleId);
        ResourceType resourceType = new ResourceType(perspectiveModuleId, "views");
        ProjectResourceId resourceId = new ProjectResourceId(context.getProjectName(), resourceType, "path/to/view");
        Locatable.forward(perspective, new Location(resourceId, Map.of()));

Okay, this makes sense for something clearly defined in a module like that,

Is it possible for items that are included in the core installation as well? Like project scripts?

This hasn't been implemented for project scripts in particular, because there's no way for TRT to drill into a project script - it only captures the call, not the library depth.

You want to get a ScriptWorkspace so you can call openScript: ScriptWorkspace

But I'm not sure if there's any good way to do that...

Debatably "good" (at least doesn't rely on reflection):

MutableNavTreeNode scriptFolder = context.getProjectBrowserRoot().getScriptFolder();
for (int i = 0; i < scriptFolder.getChildCount(); i++) {
    var child = scriptFolder.getChildAt(i);
    if (child instanceof ScriptPackageNode scriptFolder) {
        scriptFolder.workspace.openScript(someScriptResourcePath);
    }
}

The library depth is noted in the jython frame code's co_filename and the current line number is in the jython frame itself. So the TRT should be able to capture that level of detail.

You're right - 'no way' was incorrect, and I argued the point at the time, but the decision was made to favor performance. May or may not get revisited at some point.

1 Like