Template Canvas Set Property Value In Template Through Scripts

Hopefully an easy answer to this question. I am trying to set different property values in templates that are in a Canvas. So far I can do this using the following:

print 'FIRST BLOCK OF CODE'
canvas = event.source.parent.getComponent('Template Canvas')
templateName = '007-008-01'
templates = canvas.getAllTemplates()
for template in templates:
	if template.getInstanceName() == templateName:
		print template.bgColor
		template.bgColor = 'red'
		print template.bgColor

I would rather do something like the below so I don’t have to iterate through every template each time:

print 'SECOND BLOCK OF CODE'
canvas = event.source.parent.getComponent('Template Canvas')
template = canvas.getTemplate('007-008-01')

for prop in template.getProperties():
	if str(prop.getName()) == 'bgColor':
		print prop.getValue()
#		prop.setValue('blue')
		prop.value = 'blue'
		print str(prop.value)

The issue is that the template doesn’t update. The first block of code it does update the color but the 2nd block of code it will return the “blue” color in the print statement but the template never actually shows the new color. So the color on the screen just stays red the entire time. If I manually change the color to like yellow then run the first block of code then it does change…just not for the 2nd block of code.

What am I missing in the 2nd block of code? Some sort of “refresh”? Or is this not possible since the .getTemplate() returns a different object than .getAllTemplates()?

:slight_smile: hopefully this isn’t a face palm moment…lol

image

I know other parts of the code could be optimized/changed, I clean up after it’s working. (i.e. - I can probably reference the property I want directly instead of looping through each property).

Well…figured out the background color setting. Using

color = system.gui.color('blue')
template.setBackground(color)

That works so now just have to figure out how to set a value that is a templates custom property (external) using something like

value = 'test'
template.setPropertyValue('messageText') = value

where messageText is the templates custom property. I’m sure I don’t have that written correctly.

OK got it.

template.setPropertyValue('messageText','test')
1 Like

You can’t imagine how much I appreciate users who keep plugging away after posting, and solve their own problem. (:

2 Likes

Thanks! Never give up! Never Surrender!

2 Likes

And i even appreciate more if they post the solution instead of “oh i solved this” and never say anything.

2 Likes