function createGrid(selectedLayers, opt) {
  // check rows count
  if (!opt.rowsCount || opt.rowsCount < 0) {
    Context().document.showMessage('Number of grid rows must be at least 1.')
    return
  }

  // check rows margin
  if (!opt.rowsMargin && opt.rowsMargin !== 0) {
    Context().document.showMessage('Grid row margin is invalid.')
    return
  }

  // check column count
  if (!opt.columnsCount || opt.columnsCount < 0) {
    Context().document.showMessage('Number of grid columns must be at least 1.')
    return
  }

  // check columns margin
  if (!opt.columnsMargin && opt.columnsMargin !== 0) {
    Context().document.showMessage('Grid column margin is invalid.')
    return
  }

  // get first layer (most top left)
  let layer = selectedLayers[0]
  let smallestX = selectedLayers[0].frame().x()
  let smallestY = selectedLayers[0].frame().y()
  for (let i = 0; i < selectedLayers.length; i++) {
    let tempLayer = selectedLayers[i]
    if (tempLayer.frame().x() < smallestX || tempLayer.frame().y() < smallestY) {
      smallestX = tempLayer.frame().x()
      smallestY = tempLayer.frame().y()
      layer = tempLayer
    }
  }

  // arrange copies of the first layer
  let layerWidth = layer.frame().width()
  let layerHeight = layer.frame().height()
  let layerParent = layer.parentGroup()
  if (!layerParent) layerParent = layer.parentArtboard()
  if (!layerParent) layerParent = layer.parentPage()

  // remove selected layers from parent
  selectedLayers.forEach(function (tempLayer) {
    tempLayer.removeFromParent()
  })

  // keep track of original position
  let startX = layer.frame().x()
  let startY = layer.frame().y()

  // store new selected layers
  let newSelectedLayers = []

  // create rows
  for (let i = 0; i < opt.rowsCount; i++) {
    // set row y
    let y = startY + i * (layerHeight + opt.rowsMargin)

    // create columns
    for (let j = 0; j < opt.columnsCount; j++) {
      // create layer copy
      let copy = Utils.copyLayer(layer)

      // add to parent layer
      layerParent.addLayers([copy])

      // add to selected layers
      newSelectedLayers.push(copy)

      // set column x
      let x = startX + j * (layerWidth + opt.columnsMargin)

      // position copy
      copy.frame().setX(x)
      copy.frame().setY(y)
    }
  }

  return newSelectedLayers
}
Creates a grid from layers.

@param selectedLayers
@param opt
@returns {Array}