Get template instance size before runtime scaling

Within a template, we can get template original size via Rectangle.relWidth on a rectangle the same size as the template with layout anchored to top, bottom, and sides.

We can get template runtime size into internal template properties via the following expression bindings:

runscript('self.height', 50)
runscript('self.width', 50)

What we’d like to get is template instance size in Designer. In other words, if original template was 200x200 and we stretch it to 300x150 in Designer, we want to get the 300 and 150 numbers into bindings/scripting to manipulate some things in the template. Where could we find those values?

One way to accomplish this (assuming template runtime size is already bound to template internal properties heightRuntime and widthRuntime):

  1. Add template internal property isDesignerTesting with binding {[System]Client/System/SystemFlags} & 1 && {[System]Client/System/SystemFlags} & 2.

  2. Add template parameters (not internal properties) for widthInstance and heightInstance.

  3. Add this script to template:

if event.propertyName == 'isDesignerTesting' and event.newValue == True:
	event.source.heightInstance = event.source.heightRuntime
	event.source.widthInstance = event.source.widthRuntime

With all that done, flip Designer into test mode for a moment before saving to update the instance height and width parameters on all template instances open in Designer.

Is there a better or more direct way to do this?