Script Examples: Move Fields

Moving Fields Around on the Label

You can move a field on the label based on its center position or its top-left coordinates. When you rotate a field, it is always based on its center position, and the value you provide is the final rotation that you would like the field to be rotated, not the product of the intended rotation minus its current rotation.

The values passed to these methods are in 1/1000 of an inch, so a value of 3000 is 3 inches.

Barcode Rotation Considerations

All fields with the exception of barcodes have a single object associated with them. Barcodes can have either just a barcode or a barcode and human readable pair.

There are some special calls that are available for rotating barcodes as a group. These calls have the word Group in them.

  • moveGroupFromCenter
  • rotateGroup
  • moveGroupFromTopLeft

Take care when using these calls where the human readable is not in close proximity to the barcode as the call may have unintended consequences.

The standard move and rotate commands shown in the first examples will only move and rotate the barcode itself.

Barcodes can only be rotated at 0, 90, 180, and 270 degrees. A barcode's human readable fields can be rotated all 360 degrees.

Move a Field by its Center Position

The following example moves a box from its current position to centered at 3 inch by 3 inch on the label.

var box = getField("/Body/Box0001");

box.moveFromCenter(3000,3000);

To move the box relative to its current position by some distance use the following:

var box = getField("/Body/Box0001");

box.moveFromCenter(box.centerX+500,box.centerY+250);

This moves the box .5 inch to the right and .25 inch lower on the label from its current position.

Move and Rotate a Field by its Center Position

The following example moves a box from its current position to centered at 3 inch by 3 inch on the label, and then rotates it to the 90 degree position. If it is already at 90 degrees then no rotation will be applied.

var box = getField("/Body/Box0001");

box.moveFromCenter(3000,3000,90);

Move a Field by its Top/Left Corner Position

The following example moves a box from its current position to a position where its top left coordinate will be at 3 inch by 3 inch on the label.

var box = getField("/Body/Box0001");

box.moveFromTopLeft(3000,3000);

If you want to move it relative to its current position by some delta then do the following:

var box = getField("/Body/Box0001");

box.moveFromTopLeft(box.rotatedTop+250,box.rotatedLeft+500);

This moves the box a half an inch to the right and a ¼ inch down the label from its current position.

Note: The top/left coordinates are based on the bounding rectangle of the field. This means that if the field is rotated at an "off-axis" position (not one of 0, 90, 180 or 270) then the top/left position will be a point that is not on the object, but a projection of the topmost and leftmost points of the object. For example, consider an object rotated at 30 degrees where the leftmost corner is the bottom/left corner and the topmost corner is the top/left corner.

Move and Rotate a Field by its Top/Left Corner Position

The following example moves a box from its current position to a position where its top left coordinate will be at 3" by 3" on the label before rotation, and then it is rotated 90 degrees. Unless the box is a square, the final top/left will not be at 3" by 3".

var bar1 = getField("/Body/Box0001");

bar1.moveFromTopLeft(3000,3000);

bar1.rotation=90;

To make the final top/left position of the box be 3” x 3”, apply the rotation first.

var bar1 = getField("/Body/Box0001");

bar1.rotation=90;

bar1.moveFromTopLeft(3000,3000);

Move a Barcode with a Human Readable as a Group by its Center Position

The following example will find the center of the smallest bounding rectangle that encompasses the barcode and human readable and move both together to where this center is at 3" x 3"

var bc = getField("/Body/Barcode0000");

bc.moveGroupFromCenter(3000,3000);

If you want to move it relative to its current position by some delta then do the following:

var bc = getField("/Body/Barcode0000");

bc.moveGroupFromCenter(bc.groupCenterX+250,bc.groupCenterY+500);

Move a Barcode with a Human Readable as a Group by its Top/Left Position

The following example will find the top/left of the smallest bounding rectangle that encompasses the barcode and human readable and move both together to where this top/left coordinate is at 3" x 3"

var bc = getField("/Body/Barcode0000");

bc.moveGroupFromTopLeft(3000,3000);

If you want to move it relative to its current position by some delta then do the following:

var bc = getField("/Body/Barcode0000");

bc.moveGroupFromTopLeft(bc.groupTop+250,bc.groupLeft+500);

Rotate a Barcode with a Human Readable as a Group

Rotating the barcode group can be done by either rotating it with the moveGroupFromCenter method or by rotating it with the rotateGroup method. The rotation is based on the rotation of the barcode only. The human readable rotation will be changed relative to this rotation. That is, if the initial barcode rotation is 0 and the human readable is 90, and the rotation is set to 90, then the final rotation will be 90 for the barcode and 180 for the human readable.

var bc = getField("/Body/Barcode0000");

bc.moveGroupFromCenter(3000,3000,90);

or

bc.rotateGroup(90);

Move and Rotate a Barcode Human Readable Only

To single out the barcode human readable for movement, rotation, or any other changes you must retrieve it from the field and make calls on it.

var bc = getField("/Body/Barcode0000");

var hr = bc.formatProxy;

hr.moveFromCenter(3000,3000);