Thursday, 14 July 2016

How to make something useful in Extendscript pt.2

So from Part 1. we already have our Window being created.

In this line we create a newWindow that is a “palette” and name it My Window
(“palette”,”My Window”,undefined)
Undefined refers to the position and size of the palette.

If we want to start controlling the design a little we can instead write
(“palette”,”My Window”,[100,100,300,300])
Inside those square brackets the values represent [xPos, yPos, width, height].

Next we want to start populating the palette with our Things.

This is the full code we have so far:
function createUI(thisObj) {
    var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "My Window", [100, 100, 300, 300]);
    myPanel.add("button", [10, 10, 100, 30], "Tool1");
return myPanel;
var myWindowPanel = createUI(this);

So, roughly, we have a function called createUI with a new Panel named myPanel being created. It is a palette object named My Window and we define the pos and size. Then to add a button:
myPanel.add("button", [10, 10, 100, 30], "Tool1");
We add a button type object to myPanel, define the pos and size and supply the button text as Tool1.

Great. At this point it works, we have one little button but it doesn't do much. In order to add an action to the button we need to place the addition of the button inside a variable, so we change
myPanel.add("button", [10, 10, 100, 30], "Tool1");
var myButton = myPanel.add("button", [10, 10, 100, 30], "Tool1");
and add this afterwards
myButton.onClick = function () {
At this point testing becomes tricky because we're creating a ScriptUI panel and these don't seem to display in Extendscript independently, not like a standard 'script'. It's a bit of a hack but drop your jsx file into the scriptUI folder, restart AE so it will see it there and keep the jsx file you're working on in another folder. Then when you update it just drag and drop to overwrite the one in the scriptUI folder and relaunch from the window menu in AE.

If you just wanted, say, 3 or 4 buttons in your panel this would be good enough. You can just step and repeat, changing the var names of the buttons and putting different actions inside the onClick functions.

For my purposes I want a list to hold about 10 items and the actions are handled slightly differently for those, so I'll get into that in Part 3.

No comments:

Post a Comment