Resize factor of used template

Hi,

Is there any way to get resize factor of template used in window? It would be great to do it using script.

Piotr

Yes. I worked it out in this post:

I've since used this approach successfully in multiple projects.

1 Like

I don't want to resize anything, i would like "read" parameter which will indicated what is the scaling factor, between original template size and template used (smaller one) . Maybe I don't see it in your post

It's there. In the code example at the bottom of the post, the layout.getPreferredBounds gives you the original length and width of the template as it was in the designer. To get the factor, simply create a ratio using the template's normal length and width properties.

Edit: Just get your template instance, and use its layout property to directly access the original sizes.

2 Likes

getBounds() shows resized values but getPreferredBounds() doesn't work.
Maybe a different angle will help. There is a representation of template in xml.

<?xml version="1.0" encoding="UTF-8"?>
<objects fpmi.archive.type="components" framework.version="8.1.36.2024010211" com.inductiveautomation.vision.version="11.1.36.0" timestamp="Fri Jan 12 20:21:53 CET 2024">
	<arraylist len="0"/>
	<c cls="com.inductiveautomation.factorypmi.application.components.template.TemplateHolder">
		<c-comm>
			<p2df>500.0;250.0</p2df>
			<r2dd>10.0;100.0;500.0;250.0</r2dd>
			<str>Sorter</str>
			<lc>10.0;100.0;16;0;0.024;0.048</lc>
		</c-comm>
		<c-c m="setTemplatePath" s="1;str"><str>Screens/Sorter</str></c-c>
	</c>
</objects>

The scalling ratio indirectly is located in <lc>10.0;100.0;16;0;0.024;0.048</lc>, 0.024 and 0.048, but still don't know how to access this values from designer script

I see the problem; I didn't explain what getting the template instance meant. Looking at your XML file, I can see that you are getting the template holder instead of the template itself.

If your template is in a template holder, you will need to use the loadedTemplate property to retrieve the template itself from the holder. However, if it is in a template repeater or canvas you will need to use loadedTemplates[index] or allTemplates[index] to get the specific template instance.

Here is an example that has been adapted specifically for your use case:

# Get the template holder
# Change this base path and template name to the appropriate relative path and template name
templateHolder = event.source.parent.getComponent('TemplateName')

# Get the template instance from inside the template holder
template = templateHolder.loadedTemplate

# Get the template's layout
layout = template.layout

# Get the original bounds of the template in the template designer
originalBounds = layout.getPreferredBounds(template)

# Get the bounds of the template as it exists in the window
actualBounds = layout.getBounds(template)

# Print the original bounds
print originalBounds.width, originalBounds.height

# Print the bounds as displayed in the window
print actualBounds.width, actualBounds.height
1 Like

Works! Thank you very much for your help

1 Like