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

A "preview" checkbox with JavaScript

Advocate ,
Apr 26, 2013 Apr 26, 2013

Copy link to clipboard

Copied

Hi friends.

I´m writting a JavaScript that sends the active document in an appropriated way to print. Before calling the print command, I wanna display a dialog box asking the number of copies to print. So I thought I could also use this box to show some "auto" adjustments options (for example "auto levels"). If the user active "Apply auto-levels" then image refreshes to show the result (like a live preview). If user disables this box, then auto levels must be retired from image.

Well..hope you do not laught on my solution. The way I found to do it is..apply auto levels and refresh when user enables the field, and return in the history and refresh if the user disables this field. It get the expected result. BUT, if I have more checkboxes in the same dialog box, then this solution will not work so well (sure).

Do you have any other consistent solution to have previews of commands, but retire if the user disables the field?? Would like to learn a little about it.

Well..what I do (the solution I´ve mentioned above) is:

var doc = app.activeDocument;

var c = doc.activeLayer;

var dial = new Window ("dialog", "Print", undefined, {closeButton:false});

dial.orientation = "column";

dial.alignChildren = "fill";

dial.margins = 20;

var dPanel = dial.add ("panel", undefined, "Print options:");

dPanel.orientation = "column";

dPanel.alignChildren = "left";

dPanel.margins = 15;

var aLevels = dPanel.add ("checkbox", undefined, "Apply auto levels");

var dGroup = dial.add ("group", undefined);

dGroup.orientation = "row";

dGroup.alignChildren = "left";

var st = dGroup.add ("statictext", undefined, "Copies:");

var nField = dGroup.add ("edittext", undefined, "1");

nField.characters = 10;

var gButtons = dial.add ("group", undefined);

gButtons.orientation = "row";

gButtons.alignChildren = ["right", "right"];

var exe = gButtons.add ("button", undefined, "Execute", {name:"ok"});

var canc = gButtons.add ("button", undefined, "Cancel", {name:"cancel"});

aLevels.onClick = function (){

   

    if (aLevels.value){

        c.autoLevels();

        app.refresh();

    };

    else

    if (! aLevels.value){

        doc.activeHistoryState = doc.historyStates[doc.historyStates.length-2];

        app.refresh();

    };   

};

   

dial.show();

Any idea to forget all of this and make a real "preview" checkbox?

TOPICS
Actions and scripting

Views

3.6K

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
Adobe
Guru ,
Apr 26, 2013 Apr 26, 2013

Copy link to clipboard

Copied

I don't know of a good way to create an 'one the fly' preview with javascript that can be used in a dialog.

One thing that might work for you is if you used adjustment layers.Checking the control creates the layer. unchecking either deletes that layer or turns the visibility off.

Or when the script start it creates a snapshot. Then have all the controls that affect the document's state call one function that set the history to the snapshot and applies all the controls that are checked.

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
Advocate ,
Apr 27, 2013 Apr 27, 2013

Copy link to clipboard

Copied

Hi Michael

Grat idea. Using adjustment layers I can even work with buttons..so I leave the adjustment to the user do before printing. Very good.

I´m trying to create the adjustment layers in the document...but I´m getting an error. See it:

var c2 = doc.artLayers.add();

c2.kind = LayerKind.CURVES //error here

It returns an error telling I can set only "Normal" and "Text" to layer kind. So how to create a Curves Adjustment layer???

Thank you a lot

Best Regards

Gustavo.

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
Guru ,
Apr 27, 2013 Apr 27, 2013

Copy link to clipboard

Copied

The guide is wrong or at best mis-leading. You can only change the kind to text using the Object Model. And then only if the layer is a blank layer.

For the other layer kinds you need to use scriptlistener( Action Manager ).

I am not clear about what you want to do, but the user will not be able to change the adjustment layers while the dialog is open.

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
Advocate ,
Apr 29, 2013 Apr 29, 2013

Copy link to clipboard

Copied

Hi Michael

The guide is wrong or at best mis-leading. You can only change the kind to text using the Object Model. And then only if the layer is a blank layer.

At least changing I have sucess changing the kind to "text" or to "normal" by using directlly the "kind" property.

--

And yeah..I you are longer right. I wont be able to make editions in any adjustment layer while my dialog is opened. 😕

I´d like a way to enable user to adjust color balance or curves or levels (if he wants) before printing. This is why I thought on a dialog with buttons that gives acess to these commands.

Gustavo.

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
Advocate ,
Apr 30, 2013 Apr 30, 2013

Copy link to clipboard

Copied

Hi Michael

See what do you think...I used Script Listener to seek for each Photoshop command then included in the onClick event for buttons. In my tests the script looks working without problems. But..considering Photoshop supports only one dialog at a time (if I remember well), do you think it could cause any problem in any situation??

If you have a time try to run my script and tell what do you think. Download link is: https://dl.dropboxusercontent.com/u/39734475/Impressao.jsx

(note: the portion that checks if there´s an opened image is not written yet..and even not the process of printing). I´ve just written the buttons. The script is in my native language but this should not be a problem.

Best Regards

Gustavo.

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
Participant ,
Sep 14, 2013 Sep 14, 2013

Copy link to clipboard

Copied

Did you find a solution for that?

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
Advocate ,
Sep 16, 2013 Sep 16, 2013

Copy link to clipboard

Copied

None so direct Royi

I have made a recent script where I have a checkbox that acts like a "Preview" option. At true, when you enable, it really executes the needed function, and when you disable the checkbox, it executes another function that removes everyting (doing the inverse as the first function, like undoing that action).

Gustavo

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
Community Expert ,
Sep 16, 2013 Sep 16, 2013

Copy link to clipboard

Copied

I have a script that uses adjustment layers and sharpening.  You really have to do one process at a time.  You can have a dialog box that has check boxes for curves, sharpening, and whatever you want to add to the image before you print, then hit the preview or next button to do those functions, then have another dialog box come up asking if you like the changes.  Then have a button to print if all the changes are acceptable.  If you're adding sharpening also, you would want to make create a smart object so that you can go back and edit it.

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
Advocate ,
Sep 21, 2013 Sep 21, 2013

Copy link to clipboard

Copied

Hello Gustavo,

I've been using (or seen using) preview in a couple of ways:

1. Nesting when possible adj.layers into Groups and toggling their visibility and/or using smart filters on smart objects;

2. Adding, and switching from, history states. Which is handy because you don't toggle only between original and "filtered", but if the UI of your script permits it, between original, "filtered with settings #1", "filtered with settings #2", etc. giving to users the extra feature of comparison.

An option similar to #2 (that I've adopted when the processing is particularly elaborate) is to duplicate the original doc, work on it and paste back the result as a new layer. You can use the same strategy of multiple settings previews there too, but without the need to resort to snapshots.

I've been working for a while on an embedded preview (in the ScriptUI window) but never found a robust workflow for it.

Cheers

Davide Barranca

www.davidebarranca.com

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
Advocate ,
Sep 21, 2013 Sep 21, 2013

Copy link to clipboard

Copied

LATEST

Hey Davide

Thank you for the comments. These ways of working can be very useful (I like the adjustment layers way, I have a script that tries to do similiar thing) haha

Best Regards

Gustavo.

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