Hi,
I’m trying to develop a simple module with ignition 8, but this is my first attempt as I never did any module dev on 7. There is a section in the sdk documentation on project resources, however this seems to have very little if any relevance to ignition 8 (eg concrete classes that are now abstract, there is no lock manager anymore, the ProjectResource builder doesn’t expose the setters to replace all constructor parameters in the sdk documentation’s way of instantiating resource objects etc etc). Obviously there have been significant changes around this in 8. As a result I can’t even get started with a simple resource. My plan is to create a resource which will be a special script-like object that I can access in the project browser. I have been able to guess my way to getting a folder into the browser (this has also changed). But I can’t get any further. The question is are there any resources or examples for ignition 8 that I can use to understand the intended architecture of project resources, so that I can use them the way I have described?
Did you check the examples at https://github.com/inductiveautomation/ignition-sdk-examples ?
You will need to use the ProjectResourceBuilder to build the resources
http://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.1/com/inductiveautomation/ignition/common/project/resource/ProjectResourceBuilder.html
From the designer you can use the createOrModify method on the designableProject to add resources to the project (note this needs the project to be saved for the changes to persist)
http://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.1/com/inductiveautomation/ignition/designer/project/DesignableProject.html
From the gateway you can use the ProjectManager to push change operations to project resources
http://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.1/com/inductiveautomation/ignition/gateway/project/ProjectManagerBase.html
To create the change operations you use the static methods from ChangeOperation
http://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.1/com/inductiveautomation/ignition/common/project/ChangeOperation.html
An example of creating a resource in the designer
DesignableProject project = context.getProject();
ProjectResourceId resourceId = new ProjectResourceId(project.getName(), new ResourcePath(new ResourceType(<MODULE_ID>, <RESOURCE_TYPE>), <RESOURCE_PATH));
XMLSerializer serializer = context.createSerializer();
serializer.addObject(<YOUR_OBJECT>);
Map<String, byte[]> data = new HashMap<>();
data.put(ProjectResource.DEFAULT_DATA_KEY, serializer.serializeBinary(true));
ProjectResource resource = ProjectResource
.newBuilder()
.setResourceId(resourceId)
.setData(data)
.build();
project.createOrModify(resource);
or from the gateway create the resource the same way but
gatewayContext.getProjectManager().push(List.of(ChangeOperation.newCreateOp(projectResource)));
Good luck!
Do you know if we can search if a template exist from its path with the ressource manager in V8 ?
Yeah, I would probably use either the getResource or browse methods on the project depending on if you are looking for one or many templates.
example for designer
boolean templatePresent = context.getProject().getResource(new ResourcePath(new ResourceType("com.inductiveautomation.vision", "templates"), "Test Template")).isPresent();
or with browse
List<ProjectResource> templates = context.getProject().browse(new ResourcePath(new ResourceType("com.inductiveautomation.vision", "templates"), "")).orElseGet(Collections::emptyList);
Thanks, do you know if it is possible in client scope ?
The ClientContext also has a getProject so it should work exactly the same way, though I haven’t tested it.
Thanks, I will try asap !
Hi @KathyApplebaum,
I did scan through these projects but couldn’t find an example of working with project resources (unless i was not looking in the correct places for where resources are likely to be used). Do you know of a specific example, maybe i am not recognising it?
Thanks, @connor.elison, for the detailed response, I will try this and see how I go.