get & set the element anchors

Hi does anyone know if it is possible to get and set the anchor points of an element in code.
Many thanks
Caroline

You can use the solutionModel for that, for example:

	var _jsForm = solutionModel.getForm("yourFormName");
	var _element = _jsForm.getComponent("yourElementName");
	_element.anchors = SM_ANCHOR.NORTH|SM_ANCHOR.WEST;
	
	controller.yourFormName.recreatUI(); //to apply the changes

New feature ? :)

Joas:

controller.yourFormName.recreatUI(); //to apply the changes

I think that should be controller.recreateUI() or ```
forms.yourFormName.controller.recreateUI()

ROCLASI:
New feature ? :)

I stand corrected.
Thanks Roclasi :)

Many thanks Robert & Joas I’ll give that a go.

A follow on question if I may Joas.
I’ve been playing with the basics of what you gave me but I’m coming up with a problem in that I can’t seem to be able to determine if 2 of the anchors have been set. I’m sure I’m doing something wrong but what I’m trying to do is see if both North and South are set or if East and West are set. However the second two if statements always return true :? .

If someone can see what I’ve done wrong I would appreciate it.

var NorthSouth = SM_ANCHOR.NORTH|SM_ANCHOR.SOUTH;
var EastWest = SM_ANCHOR.EAST|SM_ANCHOR.WEST;
for (var i = 0; i < elements.length; i++) {
	var component = form.getComponent(elements[i].getName());
	var anchors = component.anchors;
	var msg = "Neither";
	if (anchors == SM_ANCHOR.ALL){
		msg = "All";
	}
	if (anchors&EastWest == EastWest){
		msg = "Horizontal";
	}
	if (anchors&NorthSouth == NorthSouth){
		msg = "Vertical";
	}
application.output(elements[i].getName() + ": " + anchors+" - "+msg);
}