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

233
Vistas
Script de InDesign para cambiar el estilo de la primera letra de una línea

Estoy tratando de escribir un guión para InDesign para encontrar el primer carácter de cada línea de cada párrafo y cambiarlo a otro color si es una vocal. Dado que es mi primer esfuerzo en secuencias de comandos de InDesign, descargué la Guía de secuencias de comandos de Adobe y hasta ahora logré hacer lo siguiente:

 createCharacterStyle(); main(); function main() { // I don't check if a document is open for now var myDocument = app.documents.item(0); var myStory = myDocument.stories.item(0); var noOfParas = myStory.paragraphs.length; for ( var theParaCounter = 0 ; theParaCounter < noOfParas ; theParaCounter++) { var currentParaLinesCount = myStory.paragraphs.item(theParaCounter).lines.length; for (var theLineCounter = 0 ; theLineCounter < currentParaLinesCount - 1 ; theLineCounter++ ) { var theCurrentLine = myStory.paragraphs.item(theParaCounter).lines.item(theLineCounter).contents; var theFirstChar = theCurrentLine.charAt(0); if ( theFirstChar == 'a' || theFirstChar == 'e' || theFirstChar == 'i' || theFirstChar == 'o' || theFirstChar == 'u') { theFirstChar.appliedCharacterStyle = 'Highlighted'; } } } } function createCharacterStyle() { var myDocument = app.documents.item(0); // Create the highlight color try { myColor = myDocument.colors.item('Red'); myName = myColor.name; } catch ( myError ) { myColor = myDocument.colors.add({name:'Red', model:ColorModel.process, colorValue:[0,100,100,0]}); } // Create a new Character Style try { myCharStyle = myDocument.characterStyles.item('Highlighted'); myName = myCharStyle.name; } catch ( myError ) { myCharStyle = myDocument.characterStyles.add({name:'Highlighted'}); } myCharStyle.fillColor = myColor; myCharStyle.underline = true; }

Primero creo el estilo del carácter (subrayado rojo) y luego recorro las líneas. El bucle funciona y encuentra el primer carácter. El problema es que nunca se aplica el estilo. Cualquier ayuda será apreciada. ¡Gracias!

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

0

Como una solución rápida, puede reemplazar la línea:

 theFirstChar.appliedCharacterStyle = 'Highlighted';

con:

 myStory.paragraphs[theParaCounter].lines[theLineCounter].characters[0].appliedCharacterStyle = 'Highlighted';

El problema es que theFirstChar en su código es solo una cadena, un texto. No tiene la propiedad appliedCharacterStyle . Debe obtener el character del objeto de la historia/párrafo/línea: stories[0].paragraphs[counter].lines[counter].character[0] si desea aplicarle un estilo de carácter.

Nota: paragraphs.item(theParaCounter) es lo mismo que paragraphs[theParaCounter] , lines.item(theLineCounter) es lo mismo que lines[theLineCounter] .


Además, la condición se puede acortar:

 if ('aeiou'.indexOf(theFirstChar.toLowerCase()) > -1) {

en vez de:

 if ( theFirstChar == 'a' || theFirstChar == 'e' || theFirstChar == 'i' || theFirstChar == 'o' || theFirstChar == 'u') {

.toLowerCase() hace que la condición no distinga entre mayúsculas y minúsculas. Si lo necesitas.


La función main() se puede reducir a esto:

 function main() { var doc = app.activeDocument; var story = doc.stories[0]; var paragraphs = story.paragraphs.everyItem().getElements(); while (paragraphs.length) { var lines = paragraphs.shift().lines.everyItem().getElements(); while (lines.length) { var character = lines.shift().characters[0]; if ('aeiou'.indexOf(character.contents.toLowerCase()) < 0) continue; character.appliedCharacterStyle = 'Highlighted'; } } }
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