Access Template Size

Is there a way to access a templates size and pull the values via scripting?

I looked through Nick Mudge’s drag and drop project and sort of got an idea of accessing the project templates, but can’t seem to find a way to pull the size out.

The template object has a size, width and height property that can be referenced. The following script could go in a button press and would print these properties:

print event.source.parent.getComponent('template').getSize() print event.source.parent.getComponent('template').getWidth() print event.source.parent.getComponent('template').getHeight()

Unfortunately that wont work for what I want to do.

I am trying to get the size of a template before loading it into a template canvas. As far as I know, you can’t use that method unless the template is already existent on the screen.

Essentially I have a dynamic set of data in the database that I need to pull out and display in a template canvas. I can hard code the size in and it works (obviously) but I was trying to think toward the future where if the size of the template changes, I don’t have to go in manually and update the scripting.

What Nick Mudge is doing in that demo (while very cool) is also not officially supported, and I would caution against building any kind of project that relies on its functionality; there’s no guarantee that it will continue to work in future versions.

That said, I was able to modify his drag and drop project to print the root template’s actual width/height - I’ll leave it to you to modify for your purposes if you so choose.

I added the following to lines 30 and 31 of the visionWindowOpened event handler script on the ‘Templates’ docked window:

template = XMLDeserializer.deserialize(context.createDeserializer(), obj.getSerializedBytes(), None) print template.getName(), template.getWidth(), template.getHeight()

Basically, Nick’s project is looking through the project’s resources from the backend, then deserializing them out of Ignition’s encoded format. The additional lines I added perform a second deserialization step to get the root template object directly from the project resources, before it’s actually created.

We pass the height and width of the template canvas to the stored procedure we use to load the templates, then we divide width and height based on columns and rows we want, and set the height and width of the templates based off of that.


Thank you! I will try adding that into the code and seeing if it is what I need (I’m sure it is).


Do you mean that you are passing the sizes of the templates from the database via stored procedure? I thought about putting the height and width in the database (since I already store names in it), but I didn’t want to have to go in and update the sizes manually if for some reason the sizes ever changed.

Thanks for the posts everyone

No, I pass the Template Canvas Width, Height, Number of Required Columns, Max Number of rows, to the stored procedure.
Then in the query inside the stored procedure I set the return value for width and height of each template to:

CanvasWidth/NumberOfColumnsIWant and CanvasHeight/MaxNumberOfRows

This then returns the height and width for each template record to the canvas on load.