Skip to main content
Multifarious
Inspiring
June 14, 2021
Answered

Extending ..extendscript

  • June 14, 2021
  • 1 reply
  • 1230 views

Is there a way to extend certain build in elements. Like you can add functinoality to arrays by :

 

Array.prototype.sum

 

I'd like to add functionality to the ScriptUI elemtns like groups/panels or text-elements.

 

Consider the following code:

 

function thedialog(){
    dlg = new Window ('dialog', "Zum Tezts");

    //this is the simple way
        dlg.grpTools = dlg.add( 'group' );
        //using function and sending the element
        colorizeOne( dlg.grpTools, panelColors.red );

        dlg.grpTools.add( 'statictext', [4,2,150,25], "this should be top" );
        dlg.grpTools.ButtonDo      = dlg.grpTools.add ('button', undefined, "Do me!");

  
    //this is (imo) a better way
        (dlg.grpHelp = dlg.add( 'group')).colorize = colorizeTwo;
        //having this as part of the element itself
        dlg.grpHelp.colorize( panelColors.blue );

        dlg.grpHelp.add( 'statictext', [4,2,150,25], "this should be bottom" );
        dlg.grpHelp.ButtonDo      = dlg.grpHelp.add ('button', undefined, "No, do me!");
        
        
        
        dlg.grpTools.ButtonDo.onClick = function(  ){
            dlg.grpHelp.colorize( panelColors.green );
            colorizeOne (dlg.grpTools, panelColors.grey);
        }        
        
        dlg.grpHelp.ButtonDo.onClick = function(  ){
            this.parent.colorize( panelColors.red );
            colorizeOne (dlg.grpTools, panelColors.blue);
        }
        
        
        dlg.buttonCancel = dlg.add ('button', undefined, "Cancel");
        dlg.show();            
 }

    function colorizeOne( element, color ){
        //alert(color);
        element.graphics.backgroundColor = element.graphics.newBrush (element.graphics.BrushType.SOLID_COLOR,color);
    }

    function colorizeTwo( color ){
        //alert(color);
        this.graphics.backgroundColor = this.graphics.newBrush (this.graphics.BrushType.SOLID_COLOR,color);
    }


    var panelColors = {
            grey :  [0.5,0.5,0.5],  //grey
            blue :  [0.5,0.5,0.7],  //lila
            green : [0.5,0.7,0.5],  //green
            red :   [0.7,0.5,0.5],  //red
    }

//do it!
thedialog();

 

 

As you can see, I added the functionality to change color to the second group. Which is fine for our example, but what I REALLY want is for all groups and panels to adopt that behavior. Because having to add [element.colorize=colorize] every time makes the whole endavour a bit useless. 

 

So, what I'm really looking for is something like:

ScriptUI.Group.prototype.setColor = colorize;

Which is obviously not the right code.. 

Anyone know? Is there an easyer way I'm not seeing? Would LOVE prototype access to the core objects.. 

This topic has been closed for replies.
Correct answer Jef Bracke

The only thing I could find during my coffee break is this...

‘Sprite’ Buttons in ScriptUI [UPDATE]

 

Looks promising, though still not prototype prototype. 😉

1 reply

Inspiring
June 15, 2021

Here's something perhaps even cooler than prototype access...

How I understand it, this is going to be the replacement of ExtendScript at some point.

UXP for Adobe Photoshop documentation

 

It uses html+css+javascript so it's very configurable.

(css = the language used to describe styles and colors of websites)

Meet Spectrum CSS that you can easily adapt to your needs.

It's very easy to make something that will blend in naturally with Photoshop and can be modified to have your own style if so desired.

 

Sorry it's not the direct answer to your question, but I hope it helps you along somehow.

Multifarious
Inspiring
June 15, 2021

Yeah, I saw that. One of life's little wobbles, as I am actually a webdeveloper. This is what happens when you're "out of the loop" I guess. As I am way ahead in the current project, and it is a tool I want to use with what I was REALLY going to do (:P), I decided to skip all that and stick with what I have now. A later version might well be done with UXP and be made public.

It stumps me tho' - been looking for days now and have found so much information but NOTHING about the prototypes. No one's asking, no one is even hinting at it. But I refuse to think it's just me who thought about it, considering how long extendscript has been around. It's in the name fps.. weird.. 😛

Jef BrackeCorrect answer
Inspiring
June 15, 2021

The only thing I could find during my coffee break is this...

‘Sprite’ Buttons in ScriptUI [UPDATE]

 

Looks promising, though still not prototype prototype. 😉