# Imposition AI Scripting

Imposition AI provides the option to run scripts when layout results are applied, providing some powerful tools to evaluate layouts, modify them, and access items within the layouts.

# Example Imposition AI Script

Below you'll find an example script to help you understand how scripting works, as well as help with some common scripting needs. More examples will be added over time, so check back later for more examples. Keep in mind that Tilia Labs does offer solution services for building custom marks, so reach out to your salesperson to inquire about scripting today!

# Find the layout template, and save it as a product property

This script looks through each layout and finds the template used in the layout. Then it adds the layout name as a custom product property to the first product. The use case for this one is that the user needed to add a custom barcode mark to each layout with the template name. This wasn't easily possible in version 7 so this script solved the problem: After Imposition AI was run, a barcode mark was applied to the layout using the keyword <layout.product.1.LayoutTemplate>. This script is delivered as is to help share scripting concepts and is not designed to be used in production.

/*
 * Tilia Labs Inc.
 * Copyright (c) 2012-*, All Rights Reserved
 * Script author: david@tilialabs.com
 */

var PROPERTY_NAME = "LayoutTemplate";

function run(context) {
  // Get the job we are currently operating on
  var job = context.job;

  // Get the jobs api for performing actions on jobs
  var jobs = context.jobs;
  // Loop over each layout in the job
  var layoutIndex;
  for (layoutIndex = 0; layoutIndex < job.layouts.size(); layoutIndex++) {
    var layout = job.layouts.get(layoutIndex);
    var template = layout.templates.get(0).name

    // Get the list of products placed on this layout
    var products = context.layoutProducts(layout.index);
    if (products != undefined && products != null) {
      // Loop over each layout placed in the layout
      var productIndex;
      var product = products.get(0);
      jobs.setProductProperty(
        job.id,
        product,
        PROPERTY_NAME,
        //SET NEW PRODUCT PROPERTY VALUE BELOW, 
        template
      );
    }
  }
}
Last Updated: 2/16/2022, 11:54:03 PM