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()?
hopefully this isn’t a face palm moment…lol
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).