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

172
Views
Indesign 2020 ScriptUI agregar marco de texto

Tengo un problema con un script para Indesign 2020.
No soy programador y no sé javascript (acabo de crear un script simple).
Quiero crear un panel simple con un botón que agregue un marco de texto, pero parece que no funciona.
aquí está el código

 var document = app.activeDocument; document.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS; document.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS; app.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN; app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN; app.activeDocument.zeroPoint = [0,0]; var Labelpanel = new Window("dialog"); Labelpanel.text = "Printer"; Labelpanel.orientation = "column"; Labelpanel.alignChildren = ["center","top"]; Labelpanel.spacing = 10; Labelpanel.margins = 16; var Button1 = Labelpanel.add("button", undefined, undefined, {name: "Button 1"}); Button1.text = "Magenta 1"; Button1.onClick = function() { var Label = document.pages[0].textFrames.add(); Label.properties = { geometricBounds : [ 25,284.5,15,226.5 ], contents : "1234_Mag1" } Label.paragraphs[0].appliedFont = app.fonts.item("Arial"); Label.paragraphs[0].pointSize = "30"; Label.paragraphs[0].justification = Justification.RIGHT_ALIGN; Labelpanel.close(); } Labelpanel.show();

El código del botón normalmente funciona, pero en ScriptUI no hace nada.
¿Alguien puede decirme qué estoy haciendo mal?

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

0

En su caso, el script funcionará (aunque no estoy seguro de su objetivo) si agrega esta línea:

 #targetengine session

al comienzo del código.

Y cambie "diálogo" con "paleta" aquí:

 var Labelpanel = new Window("palette");

El problema es que una ventana de diálogo no puede cambiar un documento hasta que se cierre el diálogo.

No como una paleta que siempre tiene acceso a los documentos.

Su secuencia de comandos se puede reescribir para usar una ventana de diálogo en lugar de una paleta. Pero tendrá que cambiar más de dos líneas.

Actualizar

Aquí está el ejemplo de cómo se puede hacer con una ventana de diálogo:

 // set the dialog window var labelDialog = new Window("dialog"); labelDialog.text = "Printer"; labelDialog.orientation = "column"; labelDialog.alignChildren = ["center","top"]; labelDialog.spacing = 10; labelDialog.margins = 16; // set a variable that we will convey to the main function var contents = ''; // a couple buttons var button1 = labelDialog.add("button", undefined, undefined, {name: "Button 1"}); button1.text = "Magenta 1"; var button2 = labelDialog.add("button", undefined, undefined, {name: "Button 2"}); button2.text = "Magenta 2"; // if click --> change the variable an close the dialog button1.onClick = function() {contents = '1234_Mag1'; labelDialog.close()}; button2.onClick = function() {contents = '5678_Mag2'; labelDialog.close()}; labelDialog.show(); // show the dialog // if the variable is not empty --> run the main function if (contents != '') main(contents); // the main function, get the variable and does the work function main(contents) { app.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN; app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN; app.activeDocument.zeroPoint = [0,0]; var document = app.activeDocument; document.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS; document.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS; var label = document.pages[0].textFrames.add(); label.properties = { geometricBounds: [ 25,284.5,15,226.5 ], contents: contents // <-- our variable goes here } label.paragraphs[0].appliedFont = app.fonts.item("Arial"); label.paragraphs[0].pointSize = "30"; label.paragraphs[0].justification = Justification.RIGHT_ALIGN; }

He hecho dos botones. Sospecho que sería su próxima pregunta: "¿Cómo agregar más botones?"

El punto principal: se debe cerrar una ventana de diálogo antes de intentar cambiar un documento. Una paleta no debería. Esta 'diferencia sutil' cambia significativamente el algoritmo.

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!