Setting component layout runtime

Hi,

I’m adding component dynamically through TemplateHolder. And I wanna set component layout to Anchored by script. Is there any layout method or property?

Thanks

Hi Vita,

Here is code for dynamically setting the layout of a component to anchored on all sides.

from com.inductiveautomation.factorypmi.application.components.util import FPMILayout
layout = component.getClientProperty(FPMILayout.LAYOUT_CONSTRAINTS)
layout.setFlags(FPMILayout.ANCHOR_N | FPMILayout.ANCHOR_E | FPMILayout.ANCHOR_W | FPMILayout.ANCHOR_S)

Have you considered using the Template Canvas to dynamically create template instances? Here’s a link to a tutorial: nickmudge.info/post/ignitions-te … at-runtime

Best,

1 Like

Thanks a lot.

I wanna create an instance of object according to the cursor position. So using the script is a way for me.

So I tested it and for dynamically created component I made small modification:

from com.inductiveautomation.factorypmi.application.components.util import FPMILayout
from com.inductiveautomation.factorypmi.application.components.util import FPMI_LC
from com.inductiveautomation.factorypmi.application.components.template import TemplateHolder

newobj = TemplateHolder()
...
layout = FPMI_LC()
layout.setFlags(FPMILayout.ANCHOR_N | FPMILayout.ANCHOR_W)	
newobj.putClientProperty(FPMILayout.LAYOUT_CONSTRAINTS,layout)	

Once again Nick, thank you