• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
3

How to make editable variables dynamic so they change with user input?

Explorer ,
Jul 13, 2023 Jul 13, 2023

Copy link to clipboard

Copied

Thanks to other replies here, I'm moving forward with a simple script that will let me draw guides at proportions of my document.


But, the main editable variables I'm creating don't seem to change when I change the text, and I don't know why. I'm new to JavaScript, so if anyone could explain how to fix this, I'd appreciate it.

 

I've configured a dialog with editable text fields. These text fields are meant to control the proportions with which guides are drawn across the length of a document, such as 20% of the document's length, 40%, 60% and so on. The script works the first time I run it, but when I edit the text, nothing changes.

How do I get the variables to dynamically update with new user inputs?

 

var myWindow = new Window("dialog");

    var ProportionsGroup = myWindow.add("group");
    ProportionsGroup.orientation = "column";
    ProportionsGroup.alignment = "left";
    ProportionsGroup.add("statictext",undefined,"Proportions (enter values between 0 and 1)");
        var ProportionEntries = ProportionsGroup.add("group");
        ProportionEntries.alignment = "left";
        var ProportionA = ProportionEntries.add("edittext",undefined,"0.2");
            ProportionA.characters = 6;
            ProportionA.active = true;

var A = ProportionA.text;

var docWidth = Number(app.activeDocument.documentPreferences.pageWidth);
var docHeight = Number(app.activeDocument.documentPreferences.pageHeight);

// guide test
for (var i = 0; i<4;++i){
        app.activeWindow.activePage.guides.add({location: docWidth*i*Number(A), orientation: HorizontalOrVertical.VERTICAL});
}
myWindow.show();

 

 

TOPICS
Scripting

Views

62

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 13, 2023 Jul 13, 2023

Copy link to clipboard

Copied

Here's a piece of script I tried to get started, but again it does nothing and I don't know why

 

for (var i = 0; i<4;++i){
        app.activeWindow.activePage.guides.add({location: docWidth*i*Number(A), orientation: HorizontalOrVertical.VERTICAL});
        if(A != 0.2){app.activeWindow.activePage.guides[i].remove()}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 13, 2023 Jul 13, 2023

Copy link to clipboard

Copied

As an additional piece of information, there MIGHT maybe possibly be an "onChange" event handler for adobe's scripting, though I don't know how I would implement this here for text fields. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 13, 2023 Jul 13, 2023

Copy link to clipboard

Copied

LATEST

Here is again an attempt, which does not return an error, but which STILL does nothing while utilizing the onChange event handler. I'm intending it to delete all previously created guides and then redraw new ones, but it doesn't. 

 

var myWindow = new Window("dialog");

    var ProportionsGroup = myWindow.add("group");
    ProportionsGroup.orientation = "column";
    ProportionsGroup.alignment = "left";
    ProportionsGroup.add("statictext",undefined,"Proportions (enter values between 0 and 1)");
        var ProportionEntries = ProportionsGroup.add("group");
        ProportionEntries.alignment = "left";
        var ProportionA = ProportionEntries.add("edittext",undefined,"0.2");
            ProportionA.characters = 6;
            ProportionA.active = true;

var A = ProportionA.text;

var docWidth = Number(app.activeDocument.documentPreferences.pageWidth);
var docHeight = Number(app.activeDocument.documentPreferences.pageHeight);

// guide test
for (var i = 0; i<4;++i){
        app.activeWindow.activePage.guides.add({location: docWidth*i*Number(A), orientation: HorizontalOrVertical.VERTICAL});
}
A.onChange = function(){
    for (var i = 0; i<4;++i){
    app.activeWindow.activePage.guides[i].remove();
    }
    for (var i = 0; i<4;++i){
        app.activeWindow.activePage.guides.add({location: docWidth*i*Number(A), orientation: HorizontalOrVertical.VERTICAL});
}
}
myWindow.show();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines