Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
Photoshop scripting circular selection on new layer

I'm trying to dynamically add layers in a Photoshop script via JavaScript. The layers have a circular selection, not rectangular or triangular.

For example rectangular:

var RectangleSelection = Array(
   Array(x, y), // start position
   Array(x + width, y), // right top
   Array(x + width, y + height), // right bottom            
   Array(x, y + height), // left bottom
   Array(x, y) // left top
);

I want to do the same now with a circular selection, maybe with a function like this? I'm stuck how to define the function:

var circleSelection = makeCircleSelection(x,y,radius); 

And return it in a selection which I can then place on a new layer:

var layer = document.artLayers.add();
document.selection.select(circleSelection);
document.selection.copy();
document.paste();

The docs don't have an answer and this answer I find difficult for my use case.

Thank you very much!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can utilize the following custom makeCircleSelection function. As you can see its signature has three parameters, namely x, y and radius.

/**
 * Make a circular selection.
 * @param {Number} x The center of the circular selection on the x-axis.
 * @param {Number} y The center of the circular selection on the y-axis.
 * @param {Number} radius The radius of the circular selection.
 * @returns {Object} A reference to the newly created circular selection.
 */
function makeCircleSelection(x, y, radius) {
  var d1 = new ActionDescriptor();
  var d2 = new ActionDescriptor();
  var ref = new ActionReference();

  d1.putUnitDouble(charIDToTypeID('Top '), charIDToTypeID('#Pxl'), y - radius);
  d1.putUnitDouble(charIDToTypeID('Left'), charIDToTypeID('#Pxl'), x - radius);
  d1.putUnitDouble(charIDToTypeID('Btom'), charIDToTypeID('#Pxl'), y + radius);
  d1.putUnitDouble(charIDToTypeID('Rght'), charIDToTypeID('#Pxl'), x + radius);

  ref.putProperty(charIDToTypeID('Chnl'), charIDToTypeID('fsel'));

  d2.putReference(charIDToTypeID('null'), ref);
  d2.putObject(charIDToTypeID('T   '), charIDToTypeID('Elps'), d1);
  d2.putUnitDouble(charIDToTypeID('Fthr'), charIDToTypeID('#Pxl'), 0);
  d2.putBoolean(charIDToTypeID('AntA'), true);

  executeAction(charIDToTypeID('setd'), d2, DialogModes.NO);
  return document.selection;
}

Then you can do the following to meet your requirement:

// Example usage

var document = app.activeDocument;

var circleSelection = makeCircleSelection(200, 100, 100);
circleSelection.copy();

document.artLayers.add();
document.paste();

Note: You'll need to ensure that pixels exist within the circular selection on the active art layer that you copy from. The area cannot be transparent.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Thanks for answering my question! The solution works perfect.

If you want follow me on instagram.

I'll definitely use the code for my digital art project.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda