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

269
Views
InDesign - Javascript - Copiar objeto, pegar en el lugar, agrupar nuevo objeto con selección original

EDITADO PARA CLARIDAD

Creé un script para InDesign para mejorar mi flujo de trabajo.

Selecciono una imagen, luego ejecuto el script, que funciona de la siguiente manera:

  1. Copia la imagen seleccionada (para usar en el paso 3).
  2. Aplica el efecto "multiplicar" a la imagen seleccionada .
  3. Pega en el lugar la imagen original (sin efecto de multiplicación).
  4. Busca un nombre de ruta de Photoshop específico (ya sea 'X', 'FCP' o 'x').
  5. Aplica la primera ruta que encuentra y alerta sobre cuál se seleccionó o alerta "no existe una ruta válida" si no hay ninguna disponible.
  6. Guión Termina con la imagen pegada seleccionada.

Todo funciona según lo previsto; sin embargo, me gustaría seleccionar AMBAS imágenes (la imagen con un trazado de recorte y la imagen con el efecto de multiplicación) y agruparlas. Me estoy poniendo al día sobre cómo seleccionar ambas imágenes.

Aquí está el código original ( tengo la intención de hacer las ediciones de Yuri a los comandos de copiar y pegar ):

 app.menuActions.item("$ID/Copy").invoke(); var myProperties = { blendMode : BlendMode.MULTIPLY, opacity : 100 }; for (i=0; i<app.selection.length; i++) { try { app.selection[i].images[0].transparencySettings.blendingSettings.properties = myProperties; }catch(e){} } app.menuActions.item("$ID/Paste in Place").invoke(); for (j=0; j<app.selection.length; j++) { try { var myPathName = app.selection[0].images[0].clippingPath.photoshopPathNames; var myPath = app.selection[0].images[0].clippingPath; function working() { for (var i = 0; i < myPathName.length; i++) { if (myPathName[i] === "X") { myPath.appliedPathName = myPathName[i]; alert ("X path activated"); return i; } else if (myPathName[i] === "FCP") { myPath.appliedPathName = myPathName[i]; alert ("FCP path activated"); return i; } else if (myPathName[i] === "x") { myPath.appliedPathName = myPathName[i]; alert ("x path activated"); return i; } } alert ("No valid path exists"); } working(); } catch (e) {} }

Disculpas si no es el código más limpio. Empecé a aprender javascript en mi tiempo libre y este es uno de los primeros scripts que escribí.

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

0

Con la guía de Yuri pude resolver mi problema. Tuve que reordenar un poco el proceso para dar cuenta de cómo estaba agregando a la selección (tal vez no lo hice, pero tenía sentido para mí y ¡FUNCIONA!). Aquí está el código final para cualquier persona interesada.

 //look for clipping path 'X', 'FCP', or 'x' and apply it for (j=0; j<app.selection.length; j++) { try { var myPathName = app.selection[0].images[0].clippingPath.photoshopPathNames; var myPath = app.selection[0].images[0].clippingPath; function working() { for (var i = 0; i < myPathName.length; i++) { if (myPathName[i] === "X") { myPath.appliedPathName = myPathName[i]; alert ("X path activated"); return i; } else if (myPathName[i] === "FCP") { myPath.appliedPathName = myPathName[i]; alert ("FCP path activated"); return i; } else if (myPathName[i] === "x") { myPath.appliedPathName = myPathName[i]; alert ("x path activated"); return i; } } alert ("No valid path exists"); } working(); } catch (e) {} } //copy image with clipping path app.copy(); //remove clipping path app.selection[0].images[0].clippingPath.clippingType = ClippingPathType.NONE; //apply Multiply blend mode var myProperties = { blendMode : BlendMode.MULTIPLY, opacity : 100 }; for (i=0; i<app.selection.length; i++) { try { app.selection[i].images[0].transparencySettings.blendingSettings.properties = myProperties; }catch(e){} } //paste in place and add to current selection var clippedImage = app.selection[0]; app.pasteInPlace(); clippedImage.select(SelectionOptions.ADD_TO) //group selected images app.menuActions.itemByName("$ID/Group").invoke();

¿Qué sucede y cómo funciona? El usuario selecciona una imagen y ejecuta el script

  1. Busca una ruta de recorte para que coincida con una cadena específica.
  2. El usuario recibe una alerta sobre qué ruta se ha aplicado o si no se encuentra ninguna coincidencia.
  3. La imagen se copia (para el paso 6).
  4. Se elimina la ruta.
  5. Se aplica el modo de fusión Multiplicar.
  6. La imagen copiada en el paso 3 se pega en su lugar (con trazado de recorte).
  7. La selección de imágenes pegadas se agrega a la selección actual (imagen con modo de fusión múltiple).
  8. La selección está agrupada.
about 4 years ago · Juan Pablo Isaza Report

0

Todavía no estoy seguro si entiendo bien el problema. Si necesita agregar algún elemento a la selección actual, puede hacerlo de esta manera:

 var item1 = app.selection[0]; // some selected item app.paste(); // paste item which is selected now item1.select(SelectionOptions.ADD_TO) // add the item1 to current selection app.menuActions.itemByName("$ID/Group").invoke(); // group selected items

editado para cambiar app.selected a app.selection porque la selected devolvió un error

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!