# Calling Custom Method via runScript on a Template

**URL:** <https://forum.inductiveautomation.com/t/calling-custom-method-via-runscript-on-a-template/42906>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [February 2, 2021, 6:56pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-via-runscript-on-a-template/42906 "2021-02-02T18:56:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdc5067](https://avatars.discourse-cdn.com/v4/letter/p/c6cbf5/32.png) [@pdc5067](https://forum.inductiveautomation.com/u/pdc5067)\
**Post date:** [February 2, 2021, 6:56pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-via-runscript-on-a-template/42906/1 "2021-02-02T18:56:00Z")

</div>

So I have a template component (‘Temp\_Comp’) that has some text overlayed on it. I have a Template Parameter called FontSize.  
I have an Internal Property called Run\_CustomMethod with an expression binding:  
`runScript("self.ChangeFont",0,{Temp_Comp.FontSize})`

My Custom Method changes the font size over the template when the developer enters a FontSize on each template instance.

```auto
def ChangeFont(self, paramFontSize)
	from java.awt import Font
	# Get component object and global font
	text_component = self.getComponent("text")
	# paramFontSize = self.FontSize
	text_component.font = Font('Dialog',0,paramFontSize)

```

I did this all so that I can change the font size of each component I place on the screen without putting the designer in run mode. This seems to work fine when I am testing in the designer with the template…

MY PROBLEM:  
When I drop instances of this template onto a screen and try to adjust the Template Property for “FontSize” the text no longer scales as it did when I had the tested this on the Template Master.

Any help would be appreciated! Thanks!!

---

<div class="post-metadata">

**Author:** ![bmusson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmusson/32/87530_2.png) [@bmusson](https://forum.inductiveautomation.com/u/bmusson)\
**Post date:** [February 2, 2021, 7:47pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-via-runscript-on-a-template/42906/2 "2021-02-02T19:47:06Z")

</div>

Under “Layout” on your text component, if you’re using relative layout, try unchecking “Scale Font”.

---

<div class="post-metadata">

**Author:** ![pdc5067](https://avatars.discourse-cdn.com/v4/letter/p/c6cbf5/32.png) [@pdc5067](https://forum.inductiveautomation.com/u/pdc5067)\
**Post date:** [February 2, 2021, 7:50pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-via-runscript-on-a-template/42906/3 "2021-02-02T19:50:25Z")

</div>

I just tried that, but it didnt work.

---

<div class="post-metadata">

**Author:** ![pdc5067](https://avatars.discourse-cdn.com/v4/letter/p/c6cbf5/32.png) [@pdc5067](https://forum.inductiveautomation.com/u/pdc5067)\
**Post date:** [February 2, 2021, 7:50pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-via-runscript-on-a-template/42906/4 "2021-02-02T19:50:38Z")

</div>

> [@Binding to Custom Component Methods](http://forum.inductiveautomation.com/t/binding-to-custom-component-methods/19245/2):
>
> Yes, it is possible to use runScript with custom functions (in certain circumstances). Mirroring what was described in your first link, I added a text field that accepts \*args, and just returns them as a string: Then, I added a runScript binding using self: runScript("self.printArgs", 0, {Root Container.Text Field.text}, {Root Container.Text Field 1.text}, {Root Container.Text Field 2.text})

This Forum Thread makes mention of the runScript() expression function creating unexpected behavior in templates. Im not sure if that's what is going on here or if there is a work around..

---

<div class="post-metadata">

**Author:** ![pdc5067](https://avatars.discourse-cdn.com/v4/letter/p/c6cbf5/32.png) [@pdc5067](https://forum.inductiveautomation.com/u/pdc5067)\
**Post date:** [February 2, 2021, 7:54pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-via-runscript-on-a-template/42906/5 "2021-02-02T19:54:18Z")

</div>

Sorry, I originally unchecked “Scale Font” from the Template Instance. Once I unchecked it from the Template master, it worked on the Window! Thank you!

---

<div class="post-metadata">

**Author:** ![bmusson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmusson/32/87530_2.png) [@bmusson](https://forum.inductiveautomation.com/u/bmusson)\
**Post date:** [February 2, 2021, 9:44pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-via-runscript-on-a-template/42906/6 "2021-02-02T21:44:00Z")

</div>

> [@pdc5067](#):
>
> This Forum Thread makes mention of the runScript() expression function creating unexpected behavior in templates.

For what it’s worth, we’ve recently been doing the majority of our template theming by using runScripts and have had no issues. Basically we use runScript to call a custom method on the template which then delegates to a script module (passing along the “self” reference from the custom method) that configures/updates the styling.

Combined with some global colors/fonts it makes it very easy to maintain a consistent look and feel across templates.
