📜 ⬆️ ⬇️

My first programming experience for Photoshop

Good As promised here - I will write about my experience in creating a script for the program Adobe Photoshop. This experience does not pretend to be a 100% sure guide to action - I just did it, and everything works.

There will be no illustrative programming, but rather some bumps, because of which it was created a day, and not 10 minutes :)

First, the links.

http://www.adobe.com/devnet/photoshop/scripting/ - Edobi about his brainchild, manuals
http://blogs.adobe.com/crawlspace/2006/04/cs_ui_builder_2.html - ui builder for your script (very, very unfinished, but better than handles)
http://bigmag.net/copyright/ - my script
')
Well, you can open copyrightPlacerRU.jsx in any code editor and follow the narration.
I think you shouldn’t disassemble each line (I myself did something just on a whim, more on that below)

The first thing I encountered was the construction of the interface. Breaking the guides from the edobi site I did not find anything intelligible, I started looking further - and here is the wonderful program CSUIB_2. It creates a string, thanks to which we create an instance of the Window class by passing it to the parameters:

win = new Window (ui);

The lion’s share of time left to build the interface, since the script was written on a laptop that couldn’t run exe files, and had to run from computer to computer, plus CSUIB, roughly speaking, not quite stable :) But this is the lyrics, go ahead.

I think you have already paid attention to the terrible structure of the code - so stop paying attention to it :)
After building the interface, another stop occurred - for some reason, button handlers were not called. Apparently due to time and fatigue, I did not immediately realize that if you put an event handler after the window appears, then it will not be called until the window is closed.

By the way, I still don’t know by what principle the “submit” button is selected on the form - apparently in the text (“OK”, “Cancel”). I did not have time to figure it out - if you tell me the solution, I will be grateful.

The other lion part of the time was spent on ... a blank form check. Just after clicking on the OK button, the window was not going to appear anymore, and I had to override its instance. But this erased the values ​​that the user still managed to enter. Having quickly saved the TextEdit values ​​into temporary variables, I was confused with how to save the DropDownList value. Again, in the guides of Edobi silence, the decision that worked makes me cry every time I see it.

for (var i=0,len=stringList.length-1;i<len;i++)
{
if (String(win.pnl.alignDDL.items[i])==tmpDDL)
{
win.pnl.alignDDL.selection=win.pnl.alignDDL.items[i];
}
}


Again, redefinition of the window dropped all event handlers (which is quite natural), and for convenience I included their definition in the function, although, of course, it would be worthwhile to render and then simply pass their pointer.

In general, now, in the morning, I see how and what to do beautifully and correctly, I hope I will take the time and redo everything.

In the comments I would like to hear questions and their own bumps, not suggestions for the code :)
Thanks for attention.

PS: dzhuff pluses, on the basis of its code mine (:

Source: https://habr.com/ru/post/74584/


All Articles