Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all 12244 articles
Browse latest View live

Using mouse wheel to zoom and pan

$
0
0
I was wondering if there would be a way to make a javascript that would load at Photoshop's startup that would allow the user to zoom in and out using the mouse wheel (instead of using it for scrolling), and to use that same mouse wheel as a third button (when you push on the mouse wheel) or any third button on a three button mouse to pan in your image. I'm a 3ds max user and I love the way the navigation work in that software so it'd be great to be able to do that for Photoshop and Illustrator and get rid of those useless key shortcuts that we need to use to zoom and pan.

For the pan fonction, I guess if there was a way to simply say "when the third mouse button is pressed, press the space button, until the mouse button is released" it could work. But then it would force the panning to stop when the mouse goes offscreen, unlike in 3ds max where you can pan for whatever distance you want, even if you have the loop throught the screen ten times.

For the zoom function, if scolling up could simply "push" the keyboard shortcuts to zoom in/ zoom out it could work, but I don't know if that's possible. And then we'd have to disable the scrolling up and down in the document.

Anyways, if anyone has any ideas about that let me know! I've been looking for that for such a long time!

Add subpath to existing path

$
0
0

I need to add a subpath to an existing path. The SubPathItems object doesn't provide the add method, so to add the subpath I create a new path that includes old subpaths and the new one, and then delete the old path. This causes flickering and doesn't look like the best solution.

 

Is there a better way to add a subpath to an existing path?

BUG: Server exception when saving for web (COM scripting)

$
0
0

Hello,

 

I'm scripting Photoshop through COM, using Python. The COM api is exactly the same as for Visual Basic, so the code example below should be equally trivial to follow.

 

I've stripped down the problem I'm having with the attached Jpeg image to bare bones:

1) open the file

2) save a PNG 24 for web

-> I get COM error -2147417851 (The server threw an exception).

 

If instead I (for example) resample the image in between 1) and 2), then Photoshop is happy.

 

Notice that if I do exactly the same operations by hand (using the UI and my mouse) there is no problem whatsoever.

This particular image is one I stumbled upon, but for many others this very same code works with no problems.

 

What is going on?

Is it an internal bug, or am I missing something?

Apparently this image triggers some unexpected behaviour.

 

This is the Python code: http://rafb.net/p/buw3dk18.html (also cut & paste below)

 

You can try to comment the middle section to see the problem.

 

Thanks,

Stefano Masini

Pragma 2000

www.pragma2000.com

 

------------------------------------------------------------------------------

 

import os
import win32com.client

 

psDisplayAllDialogs   = 0x1
psDisplayErrorDialogs = 0x2
psDisplayNoDialogs    = 0x3

 


srcFile = r'C:\buggy-jpeg.jpg'
dstFile = r'C:\buggy-jpeg-web.png'
if os.path.exists(dstFile):
    os.remove(dstFile)
   
comApp = win32com.client.Dispatch('Photoshop.Application')
comApp.DisplayDialogs = psDisplayNoDialogs
comDoc = comApp.Open(srcFile)

 


# ----------------------------------------------------------------
#  Slightly change the image resolution, with Bicubic resampling
# ----------------------------------------------------------------

 

resolutionDpi = comDoc.Resolution

 

desc = win32com.client.Dispatch("Photoshop.ActionDescriptor")
desc.PutUnitDouble(comApp.CharIDToTypeID("Rslt"),
                   comApp.CharIDToTypeID("#Rsl"),
                   resolutionDpi+1)
desc.PutBoolean(comApp.StringIDToTypeID("scaleStyles"), True) # Scale Styles
desc.PutBoolean(comApp.CharIDToTypeID("CnsP"), True) # Constrain Proportions
desc.PutEnumerated(comApp.CharIDToTypeID("Intr"),
                   comApp.CharIDToTypeID("Intp"),
                   comApp.CharIDToTypeID("Bcbc")) # Bicubic
comApp.ExecuteAction(comApp.CharIDToTypeID("ImgS"), desc, psDisplayNoDialogs)

 


# ----------------------------------------------------------------
#  Save for Web, PNG24
# ----------------------------------------------------------------

 

desc2 = win32com.client.Dispatch("Photoshop.ActionDescriptor")
actionDesc = win32com.client.Dispatch("Photoshop.ActionDescriptor")
actionDesc.PutEnumerated(comApp.CharIDToTypeID("Op  "),
                         comApp.CharIDToTypeID("SWOp"),
                         comApp.CharIDToTypeID("OpSa"))
actionDesc.PutEnumerated(comApp.CharIDToTypeID("Fmt "),
                         comApp.CharIDToTypeID("IRFm"),
                         comApp.CharIDToTypeID("PN24"))
actionDesc.PutBoolean(comApp.CharIDToTypeID("Intr"), False)
actionDesc.PutBoolean(comApp.CharIDToTypeID("Trns"), True)
actionDesc.PutBoolean(comApp.CharIDToTypeID("Mtt "), False)
actionDesc.PutInteger(comApp.CharIDToTypeID("MttR"), 255)
actionDesc.PutInteger(comApp.CharIDToTypeID("MttG"), 255)
actionDesc.PutInteger(comApp.CharIDToTypeID("MttB"), 255)
actionDesc.PutBoolean(comApp.CharIDToTypeID("SHTM"), False)
actionDesc.PutBoolean(comApp.CharIDToTypeID("SImg"), True)
actionDesc.PutBoolean(comApp.CharIDToTypeID("SSSO"), False)
actionDesc.PutList(comApp.CharIDToTypeID("SSLt"),
                   win32com.client.Dispatch("Photoshop.ActionList"))
actionDesc.PutBoolean(comApp.CharIDToTypeID("DIDr"), False)
actionDesc.PutPath(comApp.CharIDToTypeID("In  "), dstFile)

 

desc2.PutObject(comApp.CharIDToTypeID("Usng"),
                comApp.StringIDToTypeID("SaveForWeb"),
                actionDesc)
comApp.ExecuteAction(comApp.CharIDToTypeID("Expr"), desc2,
                     psDisplayNoDialogs)

onClick = function () {a (i);}; I want to repeat processing with variables

$
0
0

Hello, I usually do animation etc in python.

Please kindly advise. OS windows 7 software PhotoshopCC

It is not English - speaking countries.

 

I am using photoshop at work, but I've recently started making photoshop script, trying to make a simple script that opens a template that I always use. I can create a scriptUI that opens with an arbitrary button, but I want to organize the increasing number of buttons by iterating. However, it does not work.

 

 

button0.onClick = function(){openfile (0);};  // ← I want to repeat this by iteration

button1.onClick = function(){openfile (1);};

button2.onClick = function(){openfile (2);};

:

:

 

 

Below is the actual script. Buttons will appear, but nothing will happen when pressed.

 

filePath = [
"C:\\Users\\staff\\Desktop\\templateA.psd",
"C:\\Users\\staff\\Desktop\\templateB.psd",
"C:\\Users\\staff\\Desktop\\templateC.psd",
"C:\\Users\\staff\\Desktop\\templateD.psd"]; // File path

win = new Window("dialog", "title"); // Wind, button creation
btn0 = win.add("button", {width: 80, height: 25, x: 40, y: 25}, "templateA");
btn1 = win.add("button", {width: 80, height: 25, x: 40, y: 25}, "templateB");
btn2 = win.add("button", {width: 80, height: 25, x: 40, y: 25}, "templateC");
btn3 = win.add("button", {width: 80, height: 25, x: 40, y: 25}, "templateD");

for (var i = 0; i <filePath.length; i ++){    bNo = "btn" + i.toString();    bNo.onClick = function(){opnFile(i);};
}

win.show(); // button window appearance

 function opnFile(btNo){
    filename = new File(filePath [btNo]);    open(filename); // Open the file    win.close();
};

 

It works fine if it is below

 

filePath = [
"C:\\Users\\staff\\Desktop\\templateA.psd",,
"C:\\Users\\staff\\Desktop\\templateB.psd",,
"C:\\Users\\staff\\Desktop\\templateC.psd",
"C:\\Users\\staff\\Desktop\\templateD.psd"]; // File path

win = new Window ("dialog", "title"); // Wind, button creation
btn0 = win.add ("button", {width: 80, height: 25, x: 40, y: 25}, "templateA");
btn1 = win.add ("button", {width: 80, height: 25, x: 40, y: 25}, "templateB");
btn2 = win.add ("button", {width: 80, height: 25, x: 40, y: 25}, "templateC");
btn3 = win.add ("button", {width: 80, height: 25, x: 40, y: 25}, "templateD");

btn0.onClick = function(){ opnFile(0); };       //Button action definition
btn1.onClick = function(){ opnFile(1); };
btn2.onClick = function(){ opnFile(2); };
btn3.onClick = function(){ opnFile(3); };

win.show(); // button window appearance

 function opnFile(btNo){
    filename = new File(filePath [btNo]);    open(filename); // Open the file    win.close();
};

 

Is there any way to create editable table in a JSX dialog box?

$
0
0

I have created a table in JSX dialog box using multiple column list as follows.

var dlg = new Window("dialog", "Animation List");
dlg.frameLocation = [100,100]; // position
dlg.size = [750, 250];


//table initailize
var w0=150, w1=150 ;
   
 table = dlg.add ("listbox", {x:20, y:20, width:300, height:150}, undefined, { numberOfColumns:6, showHeaders:true,
 columnWidths: [w0,w1],
 columnTitles:["First Name", "Last Name"] });


table.add("item", "Namodaya");
table.items[0].subItems[0].text = "Balaarachchi";
 
 dlg.show();

 

Output table:

3.PNG

But I want to edit the cells in the table. Is there any way to achieve this?

Duplicate and fit

$
0
0

I have this need

 

I would duplicate the document in use

 

Resize to 1920px

 

Return the document to the original

And adapt it to the original document size

 

Without having too much loss of quality.

Playing an action from a certain step using Extendscript or Javascript

$
0
0

Hi,

 

I just wonder if it's possible to play an action via Extendscript, strating from a certain step, not from the begining. Is it possible?

Unzip a file

$
0
0

Hi Team,

 

Is there any possibility of unzipping a file from desktop and execute an action through PS.


About progress bar and Photoshop

$
0
0

I have been reading a lot about how to make a progress bar in photoshop (scripting) and my conclusion is that it is not worthy. The only way to make a progress bar is by using Palette window but Photoshop does not support it. If we use a dialog window, since it is modal, it will freeze whatever your script is doing so, you cannot use it (how to track the progress of a script if the script is paused while the dialog is being shown?). Although Photoshop does not support Palette, there are two workarounds that would make it work and they are using either app.refresh() or waitForRedraw() (and undocumented function that seems to me to do exactly the same thing that app.refresh() does). But as the manual says, app.refresh() will slow down considerably your code. According to my experimentation, each time you call app-refresh(), your script will waste about 1 second (no matter how powerful your computer is). That is a lot of time! In practical terms, you would use app.refresh() only a few times so your progress bar could be refreshed only a few times during the whole duration of your script, still one second lost for each time you use it. In other words, there is no good way of making a progress bar in photoshop scripting.

 

My question is: am I right? Is there a way to code a progress bar in PS that would not delay the code unreasonably?

Please Help "Copy to Clipboard" not recorded in Actions

$
0
0

Hi There

 

When I try to Copy values on Canvas Size (e.g. value on Height Copied to Width or reverso so as Height = Width) then I want to repeat this "Copy" task to all remaining Opened Files using Actions, these "Copy" task is not recorded but it just Copies The first Value I Copied in the first action

 

Example:

 

Picture 1 has the Canvas Size
Height : 27 Inches
Width : 18 Inches

 

 

Picture 2 has the Canvas Size
Height : 24 Inches
Width : 10 Inches

 

First, I use Actions and start to record
Then, I Copy value on Height and paste it to Width on Picture 1
Then, I click Stop

 

The problem arise when I repeat this "Copy" task on Picture 2, the Height won't be the same as Width and the Width is the value I Copy for the first time i.e. 27 Inches

 

So the result is

 

Picture 2 has the Canvas Size
Height : 24 Inches
Width : 27 inches  (not 24 Inches)

 

Hope you can help me with this

 

Thanks before

converting actions into script

$
0
0

Hello Guys,

 

Might be a quick answer for you or maybe not.

I have never scripted anything in my life (except a few macro files in excel) and I am green to this.

 

Simple question - I have a few "actions" in photoshop and I would like them to be converted into scripts as it might come handy for the future as I will be working with some scripters.

So how do I transform this ATN file into a script?

 

The reason behind it is that I am already having one action that has 2 scripts in it and in the future I want to add more, so I will need someone scripting to work on the script itself not actions.

 

Maybe it is also counter-productive so give me your opinion,

 

thanks.

 

Olaf

Create compatible window for different monitors/screens resolutions

$
0
0

I want to create a compatible window for run different monitor/screens. In below window, I have given hard-coded values for positions and buttons length.

 

var dlg = new Window("dialog", "Patient List"); 
dlg.frameLocation = [100,100]; // position 
dlg.size = [500, 250];   
//table initailize  
var w0=150, w1=150 ;      
 table = dlg.add ("listbox", {x:20, y:20, width:300, height:150}, undefined, { numberOfColumns:6, showHeaders:true,  
 columnWidths: [w0,w1],  
 columnTitles:["First Name", "Last Name"] });


dlg.btnRightGroup = dlg.add ("group", {x:350, y:20, width:130, height:200});
btnNew = dlg.btnRightGroup.add("button", {x:0, y:0, width:130, height:20}, "New");
btnEdit = dlg.btnRightGroup.add("button", {x:0, y:25, width:130, height:20}, "Edit");


dlg.editGroup = dlg.add ("group", {x:20, y:175, width:500, height:25})
editAnimationName = dlg.editGroup.add ("edittext", {x:0, y:0, width:150, height:20});
editStart = dlg.editGroup.add ("edittext", {x:151, y:0, width:150, height:20});
btnUpdate = dlg.editGroup.add("button", {x:325, y:0, width:130, height:20}, "Update");


dlg.btnBottomGroup = dlg.add ("group", {x:150, y:200, width:500, height:30})
btnOk = dlg.btnBottomGroup.add("button", {x:0, y:10, width:100, height:20}, "Ok");
btnCancel = dlg.btnBottomGroup.add("button", {x:150, y:10, width:100, height:20}, "Cancel");
  
table.add("item", "Namodaya");  
table.items[0].subItems[0].text = "Balaarachchi";    
 dlg.show();

Capture.PNG

I want to create compatible (Responsive) window. Please help me to find any reference to learn that one.

Batch Crop & Straighten

$
0
0

A while ago a good chap helped me out by creating a script that prompted the user for a folder, then ran the Crop and Straighten Photos command on all images contained in the folder and saved the newly created photos in a new folder.  The script is below.

 

The script saves cropped photos as PNGs, I'd like to save them as JPEG.  Could someone help me out by tweaking the script to save as JPEG?  I'd like them saved with the highest quality option.

 

#target Photoshop
app.bringToFront;
var inFolder = Folder.selectDialog("Please select folder to process");
if(inFolder != null){     var fileList = inFolder.getFiles(/\.(jpg|tif|png|)$/i);     var outfolder = new Folder(decodeURI(inFolder) + "/Edited");     if (outfolder.exists == false) outfolder.create();     for(var a = 0 ;a < fileList.length; a++){          if(fileList[a] instanceof File){               var doc= open(fileList[a]);               doc.flatten();               var docname = fileList[a].name.slice(0,-4);               CropStraighten();               doc.close(SaveOptions.DONOTSAVECHANGES);               var count = 1;               while(app.documents.length){                    var saveFile = new File(decodeURI(outfolder) + "/" + docname +"#"+ zeroPad(count,3) + ".png");                    SavePNG(saveFile);                    activeDocument.close(SaveOptions.DONOTSAVECHANGES) ;                    count++;               }          }     }
};

function CropStraighten() {
     function cTID(s) { return app.charIDToTypeID(s); };     function sTID(s) { return app.stringIDToTypeID(s); };     executeAction( sTID('CropPhotosAuto0001'), undefined, DialogModes.NO );
};

function SavePNG(saveFile){
    pngSaveOptions = new PNGSaveOptions();    pngSaveOptions.embedColorProfile = true;    pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;    pngSaveOptions.matte = MatteType.NONE;    pngSaveOptions.quality = 1;     pngSaveOptions.PNG8 = false; //24 bit PNG    pngSaveOptions.transparency = true;     activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}

function zeroPad(n, s) {
     n = n.toString();     while (n.length < s) n = '0' + n;     return n;
};

Script to open the Open Dialog Window

$
0
0

Hello everyone!

I'm new to scripting and this is probably an easy question but I'm trying to write a script that opens the Open Dialog Window. Basically I need to start the script in one active document, have the script open the Open Dialog (to let the user select another image) and then finish the script in the newly opened document. Every script I find is to open a specific file, but I need it to be User Selected through the Open Dialog of Photoshop.

 

I hope that makes sense! LOL. Any help would be greatly appreciated!

 

Thanks,

Bradi

Script to search layer names

$
0
0

Hi -

 

Does anyone know if there is a script that can search through layer names within a file for a specific text string and then select it as the active layer?

 

For instance, if a file has 4 layers, named My LayerX, LayerY, LayerZ, LayerA, I want to automatically search for a layer that has the text "rA" and make it the active layer.

 

Thanks.


Export selected groups as png files

$
0
0

Hello

 

I need a way to automaticly export png images from selected layers or groups.

The way I would like script to work is simple:

Before: Select layers/grous you want to export (selected groups\layers may be inside other grouops)

After: List of transparent png images (with exact size of layer/group content) named with source layer/group.

 

I have found a code to export groups to files, all I need is a little bit help modyfing script for my needs.

http://www.damienvanholten.com/blog/export-groups-to-files-photoshop/

A script for "Save for Web" as .jpg

$
0
0

I found a script that saves the current selected document in Photoshop as .png to the Desktop, and use it all the time.

 

function main() {

          // declare local variables

          var doc = app.activeDocument;

          var docName = app.activeDocument.name.slice(0,-4);

 

 

    var saveFile = new File("~/Desktop/" + docName + ".png");

    pngSaveOptions = new PNGSaveOptions();

    pngSaveOptions.interlaced = false;

    doc.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);

}

 

main();

 

 

Now I'd really like a similar script to do "Save for Web" as .jpg files, without a colour profile, to the Desktop. Preferably a version to save as 100% quality and one to save as 60% quality.

Any help would be greatly appreciated.

Photoshop CC 2015 changes to scripting

$
0
0

It's again the time of year that Adobe releases a new version with some new "features" so I was thinking we should share issues to minimize time on debugger

 

  • Greatly improved Javascript performance, I'd say at least 2-3x improvement in my scripts, Kudos Adobe
  • Dialogs are much more responsive and change updates immediatelly. However in my end loop (waiting for user to click OK) dialog became unresponsive and hanged Photoshop. Needed to add app.refresh() in the loop (but don't use in script as it has great performance impact).

 

So far looking looking good, but please share if you discover some changes

Abort the default Photoshop progress bar

$
0
0

Screenshot_2.jpg

Hello everyone! Is there any way to abort or hide this "standard progress bar" when exporting high-quality prints through scripts?

I added a custom progress bar to my script that took too long but I sometimes realize that the two palettes are shown at the same time? It would be possible?

 

That's the palette I'm using! If someone has another functional model I am very grateful

myPrs = new Window('palette', 'Batch Processing');     myPrs.orientation = 'column';     myPrs.alignment = 'right';     myPrs.ProcessHead  = myPrs.add('statictext',[40,0,260,25], "Batch Processing...");     myPrs.Process = myPrs.add("progressbar",[40,40,260,65]);     myPrs.Label = myPrs.add('statictext', [150,75,200,120], "0%");     myPrs.Process.value = 0;     var LENGTH = 4;     myPrs.show();     for(i=0;i<1;i++){         var PrCounter = 0;        ProgressBar(++PrCounter, i+1 , 1);         Function1();     }           function ProgressBar(v, x, y){         var value = (Number(v) / LENGTH) * 100;         myPrs.Label.text = Math.round(value) + " % ";         myPrs.ProcessHead.text = "Batch Processing... [" + x + "/"+ y + "]";         myPrs.Process.value = value;     }       function Function1(){      // my code     }

How to create table for working Photoshop CC 2014, 2015.1 and 2015.5?

$
0
0

I created a table using Listbox columns. But it only works for Photoshop CC 2014.

 

var dlg = new Window("dialog", "Animation List"); 
dlg.frameLocation = [100,100]; // position 
dlg.size = [750, 250];   
//table initailize  
var w0=150, w1=150 ;      
 table = dlg.add ("listbox", {x:20, y:20, width:300, height:150}, undefined, { numberOfColumns:6, showHeaders:true,  
 columnWidths: [w0,w1],  
 columnTitles:["First Name", "Last Name"] });   
table.add("item", "Namodaya");  
table.items[0].subItems[0].text = "Balaarachchi";    
 dlg.show();

 

Capture.PNG

 

Then I found listbox is not supported for Photoshop CC 2018, 2017 and 2015.

Can anyone help me to create a table as mentioned above for support every version in Photoshop?

Viewing all 12244 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>