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

Need scriptUI-expert's advice on proper implementation of Photoshop scriptUI dialog

Explorer ,
Jun 25, 2014 Jun 25, 2014

I'm in the middle of porting my deprecated flash based panel to an HTML5 version. Als part of my panel I wrote a script to create a new photoshop document including parameters for the video timeline. From the panel a separate script file was called which then generated a dialog window for user input. After the script was completed the dialog and all reference to it was automatically deleted.

Because now I'm using one single hostscript.jsx file for my functions I'm running into issues regarding the (re-) opening of the dialog after the first time.

The behaviour is best replicated when running the script directly in the ExtendScript Toolkit (targeted to itself).

I'm looking for someone who can give me some pointers on how to implement this so the dialog can be called a second time without issues.

Thanks in advance.

Here is my script:

// Presets Array

var vidSizes = [["HD 720p", 1280, 720], ["HD 1080p", 1920, 1080], ["Cineon Half", 1828, 1332], ["Cineon Full", 3656, 2664], ["Film (2K)", 2048, 1556], ["Film (4K)", 4096, 3112]];

// placeholder for AnimationProject sequence

var tempLayer = "";

// window reference

var w ;

// START OF FUNCTION ------------------------

function makePanelWindow(){

     // width value for dropdown and text input

     var charWidth = 15;

    w = Window.find('dialog','new project');

    //alert(w);

  

        if(w==null){

            //push names in dropdown list

            var vidFormats = [];

            for (var a in vidSizes){

                    vidFormats.push(vidSizes[0])

           }

    // scriptingUI Animation Project Settings window

        w = new Window ("dialog {text: 'Animation Project Settings'}","new project");

        var grName = w.add("group");

        var _labelName = grName.add ("statictext");

        var _docName = grName.add ("edittext", undefined,"");

        _docName.characters = 40;

// kader holder

        var grKader = w.add("group");

// kader 1 ~ settings

        var size_group = grKader.add ("panel", undefined, "Settings");

        size_group.alignChildren = "right";

        size_group.preferredSize = [" ", 160];

//dropdown

        var grDropdown = size_group.add("group");

        grDropdown.margins.top = 12;

        var _labelSize = grDropdown.add ("statictext");

        var _size = grDropdown.add ("dropdownlist", undefined,vidFormats);

        _size.selection = 0;

        _size.preferredSize = [164,22];

//input field Width

        var grHWidth = size_group.add("group");

        var _labelWidth = grHWidth.add ("statictext");

        var _width = grHWidth.add ("edittext", undefined, 1280);

         _width.characters = charWidth;

        var _labelUnit1 = grHWidth.add ("statictext");

        _labelUnit1.characters = 3;

//input field Height

        var grHeight = size_group.add("group");

        var _labelHeight = grHeight.add ("statictext");

        var _height = grHeight.add ("edittext", undefined, 720);

        _height.characters = charWidth;

        var _labelUnit2 = grHeight.add ("statictext");

        _labelUnit2.characters = 3;

//input field Framerate

        var grLabel = size_group.add("group");

        var _labelFramerate = grLabel.add ("statictext");

        var _frameRate = grLabel.add ("edittext", undefined, 24);

        var _labelUnit3 = grLabel.add ("statictext");

        _labelUnit3.characters = 3;

// kader 2 ~ Generate

        var opt_group = grKader .add ("panel", undefined, "Generate");

        opt_group.preferredSize = [" ", 160];

// Check boxes

        var grCheck = opt_group.add("group {orientation:'column', alignChildren: 'left'}");

        grCheck.margins.top = 12;

        var wantND = grCheck.add ("checkbox", undefined, "New Document");

        wantND.value = true;

        var wantVL = grCheck.add ("checkbox", undefined, "Video Layer");

        //var wantVLG = grCheck.add ("checkbox", undefined, "Video Layer Group");

// cancel and ok

        var buttons = w.add ("group");

        buttons.alignment = ["right", 'bottom'];

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

        var applyButton = buttons.add ("button", undefined, "OK", {name: "ok"});

        buttons.alignment = 'right';

// Label and name values

        _labelName.text = "Name:";

        _docName.text = "New Animation Project";

        _labelSize.text = "Size:";

        _labelWidth.text = "Width:";

        _labelUnit1.text = "px";

        _labelHeight.text = "Height:";

        _labelUnit2.text = "px";

        _labelFramerate.text = "Frame rate:";

        _labelUnit3.text = "Fps";

// Panel Functions ----------------------------------------------------

//List behaviour

        _size.onChange = function (){

            var sel = Number(_size.selection);

            _height.text = vidSizes[sel][2];

            _width.text = vidSizes[sel][1];        

}

//OK and Cancel buttons

        applyButton.onClick = function() {

            //makeDoc();

            return w.close();

    }

        cancelButton.onClick = function() {

            return w.close();

    }

}

w.show();

}

// END OF FUNCTION ------------------------

makePanelWindow();

TOPICS
Actions and scripting
2.4K
Translate
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

correct answers 1 Correct answer

Advisor , Jun 25, 2014 Jun 25, 2014

Patrick, try this:

Replace

return w.close();

with

w.close ();

w = null;

delete w;

$.gc ();

in your button functions.

Hope that helps.

--

tomaxxi.com

Translate
Adobe
Advocate ,
Jun 25, 2014 Jun 25, 2014

Hi Patrick,

could you please elaborate the issue? I've seen that when you run the above code on ESTK the first time everything's OK, the second time it appears an empty, small dialog - if you can't see it in ESTK, just add w.center() the line before w.show().

This is fixed if you Debug > Reset (on ESTK)

Yet in Photoshop I have not experienced this problem with your code since PS doesn't support persistent sessions, and multiple calls just work as expected.

Is there a why for the window.find() - do you need to call the same dialog? What's wrong with re-creating it the next run?

Regards

Davide Barranca

---

www.davidebarranca.com

www.cs-extensions.com

Translate
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 ,
Jun 25, 2014 Jun 25, 2014

Hello Davide,

Thank you for your reply.

When I wrote this script I was building a panel/toolbar in infigurator and executed separate script-files from the buttons in the flash-based toolbar. In the original script the scriptUI was not part of a function. When the script was called it would start with the dialog and the 'real' functions were executed by the scriptUI button events.

I'm recreating the toolbar in HTML5 in Brackets which does a javascript/evalScript call to the hostscript.jsx containing all my jsx photoshop functions.

$("#stNew").click(function () { csInterface.evalScript('makePanelWindow()'); });

In the scope of the hostscript.jsx the scriptUI wont be conveniently deleted at the end of the script.

The window.find() is a remainder of something I tried. Since the window object didn't get deleted I figured it would be best to reuse it.

Later it became a check to check what would happen if w was null(ed).

Patrick

Translate
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
Advisor ,
Jun 25, 2014 Jun 25, 2014

Patrick, try this:

Replace

return w.close();

with

w.close ();

w = null;

delete w;

$.gc ();

in your button functions.

Hope that helps.

--

tomaxxi.com

Translate
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 ,
Jun 25, 2014 Jun 25, 2014

Hi Marijan,

Thank you for your reply.

At first glance it fixed the problem of not being able to see the dialog on the second try.

I'm having a serious look at it tomorrow.

I understand what going on except for $.gc (); 

Could you tell me what does it stand for?

Regards,

Patrick

Translate
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 ,
Jun 26, 2014 Jun 26, 2014

This was the final and crucial step I needed to move on and start debugging my script.

Thank you for the help.

Translate
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
Advisor ,
Jul 17, 2014 Jul 17, 2014

You're welcome Patrick!

$.gc (); is calling garbage collector. It's undocumented command.

--

tomaxxi.com

Translate
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 ,
Jul 18, 2014 Jul 18, 2014

$.gc ()

Core JavaScript Classes

Initiates garbage collection in the ExtendScript engine.

It is documented it shows in both the OMV & the ID base classes iChm

Translate
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
LEGEND ,
Jul 22, 2018 Jul 22, 2018
LATEST

Like Muppet Mark says it's documented. I found it in JavaScript Reference Guide for CS2, then starting with CS3 Adobe moved it to separate Javascript Tools Guide. Unfortunately they frogot to move $.summary() as well to that other documentation, so last note about it left in old CS2 reference. That's regarding other topic: Script UI blank

Translate
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