Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
Comprobar si la selección contiene gráficos

Estoy tratando de escribir un script en el que parte de él es averiguar si hay una imagen en los objetos seleccionados o si los objetos son formas vacías.

Necesito verificar si los archivos de la selección son todas imágenes, todas las formas o están mezclados.

He reunido este código con alertas (el código final no será con alertas, es para fines de comprensión):

 if (app.selection.length == 0) { alert ("Nothing selected"); } else { for (var i = 0; i < app.selection.length; i++) { if ((app.selection[i].graphics.length == 0) && (app.selection[i].graphics.length == 1)) { alert ("The files are mixed"); } else if (app.selection[i].graphics.length == 1) { alert ("The files are images"); } else if (app.selection[i].graphics.length == 0) { alert ("The files are shapes"); } } }

Obviamente, el código no funciona según lo previsto (funciona para las imágenes y las formas, aunque ya sé que la parte mixta no está escrita correctamente), ya que mis búsquedas no han sido concluyentes.

Lo que busco es: si no se selecciona nada (hacer algo), si los archivos son formas e imágenes (hacer algo solo con las formas), si solo hay imágenes (hacer algo), si solo hay formas (hacer algo).

Alguien me puede dar una idea de como hacerlo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Básicamente, el algo puede ser algo como esto:

 var sel = app.selection; if (sel.length == 0) alert('Nothing selected'); else { var images = sel.pop().graphics.length > 0; var mixed = false; while (sel.length) { if ((sel.pop().graphics.length > 0) != images) { mixed = true; break; } } if (mixed) alert('Mixed'); else { if (images) alert('Images'); else alert('Shapes'); } }

Pero no maneja grupos.

Actualizar

Si solo desea obtener formas (y omitir imágenes) de la selección, puede hacerlo de esta manera:

 var sel = app.selection; if (sel.length == 0) { alert('Nothing selected'); exit() } var shapes = []; for (var i=0; i<sel.length; i++) if (sel[i].graphics.length == 0) shapes.push(sel[i]); if (shapes.length > 0) do_something(shapes); // ---------------------------------------------------------------------- function do_something(shapes) { alert('Here we go...'); app.selection = shapes; // do stuff... }

O una variante corta (solo para anular la selección de imágenes):

 var sel = app.selection; for (var i=0; i<sel.length; i++) if (sel[i].graphics.length > 0) sel[i].select(SelectionOptions.REMOVE_FROM);

Actualización 2

Aquí está el código que hace lo siguiente:

  • si nada seleccionado> crea un rectángulo blanco,
  • si solo las imágenes seleccionadas> crea un rectángulo blanco,
  • si solo las formas seleccionadas> colorean las formas blancas,
  • si la selección es mixta > selecciona solo las formas y los colores blanco.
 var sel = app.selection; if (sel.length == 0) fn_nothing(); else { var images = sel.pop().graphics.length > 0; var mixed = false; while (sel.length) { if ((sel.pop().graphics.length > 0) != images) { mixed = true; break; } } if (mixed) fn_mixed(); else { if (images) fn_images(); else fn_shapes(); } } function fn_nothing() { alert('Nothing'); create_white_rectangle(); } function fn_images() { alert('Images'); create_white_rectangle(); } function fn_shapes() { alert('Shapes'); color_shapes_white(); } function fn_mixed() { alert('Mixed'); select_shapes(); color_shapes_white(); } function select_shapes() { var sel = app.selection; while (sel.length) { var item = sel.pop(); if (item.graphics.length > 0) item.select(SelectionOptions.REMOVE_FROM) } alert('Select shapes'); } function color_shapes_white() { alert('Color shapes white') } function create_white_rectangle() { alert('Create a white rectangle'); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!