# Resize factor of used template

**URL:** <https://forum.inductiveautomation.com/t/resize-factor-of-used-template/84177>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [January 12, 2024, 10:34am UTC](https://forum.inductiveautomation.com/t/resize-factor-of-used-template/84177 "2024-01-12T10:34:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piotr\_Piotr](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@Piotr\_Piotr](https://forum.inductiveautomation.com/u/Piotr_Piotr)\
**Post date:** [January 12, 2024, 10:34am UTC](https://forum.inductiveautomation.com/t/resize-factor-of-used-template/84177/1 "2024-01-12T10:34:02Z")

</div>

Hi,

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

Piotr

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 12, 2024, 12:31pm UTC](https://forum.inductiveautomation.com/t/resize-factor-of-used-template/84177/2 "2024-01-12T12:31:23Z")

</div>

Yes. I worked it out in this post:

> [@How to transform a component inside of a vision template](https://forum.inductiveautomation.com/t/how-to-transform-a-component-inside-of-a-vision-template/80122/6):
>
> Nope. While groups definitely exhibit the same scaling behaviors as templates when you squish them or expand them, a simple transform still works as expected on a group's individual components because the components' bounds are still relative to their location within the window editor in the designer. That said, I've finally got my head around what I was observing. The bounds of the template are always relative to the template editor in the designer. Therefore, my erroneous expectation was for…

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

---

<div class="post-metadata">

**Author:** ![Piotr\_Piotr](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@Piotr\_Piotr](https://forum.inductiveautomation.com/u/Piotr_Piotr)\
**Post date:** [January 12, 2024, 12:47pm UTC](https://forum.inductiveautomation.com/t/resize-factor-of-used-template/84177/3 "2024-01-12T12:47:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 12, 2024, 12:54pm UTC](https://forum.inductiveautomation.com/t/resize-factor-of-used-template/84177/4 "2024-01-12T12:54:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Piotr\_Piotr](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@Piotr\_Piotr](https://forum.inductiveautomation.com/u/Piotr_Piotr)\
**Post date:** [January 12, 2024, 7:24pm UTC](https://forum.inductiveautomation.com/t/resize-factor-of-used-template/84177/5 "2024-01-12T19:24:04Z")

</div>

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

```auto
<?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

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 13, 2024, 4:35am UTC](https://forum.inductiveautomation.com/t/resize-factor-of-used-template/84177/6 "2024-01-13T04:35:43Z")

</div>

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:

```auto
# 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

```

---

<div class="post-metadata">

**Author:** ![Piotr\_Piotr](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@Piotr\_Piotr](https://forum.inductiveautomation.com/u/Piotr_Piotr)\
**Post date:** [January 14, 2024, 11:11am UTC](https://forum.inductiveautomation.com/t/resize-factor-of-used-template/84177/7 "2024-01-14T11:11:24Z")

</div>

Works! Thank you very much for your help
