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

What? ActionReference, charIDToTypeID, stringIDToTypeID

$
0
0

Hi,

 

I am newbie to photoshop scripting but I do have few years experience with Javascript. Looking for clarification as I can't figure out what is  going on here.

 

I was looking for solution how to get array of selected artLayers and layersSets. I found couple solutions on blogs and forums which works, but I can't figure out what that code actually does so may someone could explain it line by line or point me to normal documentation as I found http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/photoshop/pdfs/photoshop_scriptref_ js.pdf doesn't explain anything just gives list of available functions.

How ActionDescriptor, ActionReference works, how returned object by executeActionGet(ref) is structured and how Photoshop stores actions in memory.

 

var ref = new ActionReference();

var selectedLayers = [];

ref.putEnumerated( // Puts an enumeration type and ID into a reference along with the desired class for the reference.

     //why I do need use putEnumerated? what it gives?

     charIDToTypeID("Dcmn"), // document

     charIDToTypeID("Ordn"), // typeOrdinal - what is ordinal?

     charIDToTypeID("Trgt") //enumTarget - what?why?

)

 

var desc = executeActionGet(ref); // returns ActionDescriptor, how this object structure looks? how it was created?

desc = desc.getList( stringIDToTypeID( 'targetLayers' )); //returns ActionList, but what is targetLayers,who specified targetLayers? or it means it targets all layers?

 

for(var i=0;i<c;i++){

            try{              

               selectedLayers.push(  desc.getReference( i ).getIndex() );//gets action reference index in the ActionList

            }catch(e){

              // selectedLayers.push(  desc.getReference( i ).getIndex()+1 ); //I commented this out as I can't understand why it is used, if we failed for i, how I can be sure that we will not fail for i+1??

            }

}

 

If I understand correctly it gives me indexes of actions but not layers. Is that right? After this code I should somehow get artLayer+layersSets by using action indexes?

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

--------------------------My structure of layers and groups is

   Layer 4

Group4(1)

      Layer 3

   Group 3(1)

Group 2(1)

   Layer 2

Group 1(1)

Layer 5

Layer 1

 

and when I select all groups ant layers script above which should return array of selected layers/groups indexes returns me this - 1,2,4,5,8,9,10,12,13. As you can see it is missing some numbers so I assume this is not array of layers indexes.

 

 

Thank you!

 

Tomas


Select layer by name in other document

$
0
0

So i have 2 open documents.

They both have the same names in layers.
I wrote a script that should select a layer with the same name as the selected layer in the first document.
Here is the script. Currently the code that does not work is commented out.

 

 

 

var aDoc = app.activeDocument; 

var AllDocs = app.documents; 

var actLay = aDoc.activeLayer; 

 

if (AllDocs.length > 1) { 

var itemDoc = null; 

 

var win = new Window("dialog","select the same name in other document"); 

this.windowRef = win; 

win.Txt1 = win.add ("statictext", undefined, "Paste in which open document?"); 

win.NewList=win.add ("dropdownlist", undefined, AllDocs); 

 

win.NewList.selection = 0; 

itemDoc = win.NewList.selection.index; 

  

win.testBtn4 = win.add('button', [260,140,100,50], 'select the same name in other document', {name:'doding1'});

win.testBtn4.onClick = dothing;

 

//Get selected document from list

win.NewList.onChange= function () { 

    itemDoc = win.NewList.selection.index; 

    return itemDoc; 

    } 

 

 

//Show al items

win.show(); 

 

function dothing()

{

 

//Make the selected document the active document.

app.activeDocument = app.documents[itemDoc];

app.refresh();

 

 

//This outputs [Artlayer layername]

//alert (actLay);

 

//Find right layer and set active THIS DOES NOT WORK!!

//app.activeDocument.activeLayer = app.activeDocument.layers.itemByName(actLay);

 

win.close();

}

 

 

}

else

    alert ("No other documents open");

}

[CS6] Custom Panel hook for C++ API question

$
0
0

I have a plugin (.dll) written in C++ that I want to create a custom panel for, so a few questions:

Is this possible?

If so, could you point me in the direction of what I have to use, I understand that I can use ActiveXObject for web to call native dlls in Js. Would this work for Photoshop?

Would like to automate open stacks as layers + run action. Possible with script??

$
0
0

I would like to automate part of my workflow that involves opening stacked images as layers in Ps CS5 and running an PS action that composites the layers and processes the image. Something similar to 'Process Collection' in Bridge CS5 only with my own action instead of merge to HDR/Panorama.

 

Apparently this is possible with Mac 'Automator' - is there anything I can do in Windows? I don't have any experience with writing scripts, but have friends that can help. Can someone tell me if its possible and point me in the right direction please?

Help: need a script to merge all layers, even if there is only one layer

$
0
0

I am trying to build an action that includes "merge all layers" or "merge visible layers". However when I record that throught the actions tool (usung the layers panel flyout dialog), if a file being batched doesn't have more than two layers or has one layer that is flat, I get an error and the actions stops. I wanted to add a step in the action to run a script that can do one of the two layer merges, and if there is only one layer will just continue without erroroing out.

 

Could anyone suggest some code snippets or point me the obvious answer?

 

Thanks so much!

 

 

- Not even a script noob yet. Please be kind.

jsx showing levels window

$
0
0

Hi guys. I'm trying to create a panel that has the tools I need all stacked together. I've managed to get the tools to work but the Levels, Replace Color and such windows don't work. I'm very new to this. Any ideas?

 

//

//==================== Select Tool Open Levels ==============

//

function SelectToolOpenLevels(){

    var idmodalStateChanged = stringIDToTypeID( "modalStateChanged" );

    var desc364 = new ActionDescriptor();

    var idLvl = charIDToTypeID( "Lvl " );

    desc364.putInteger( idLvl, 1 );

    var idStte = charIDToTypeID( "Stte" );

    var idStte = charIDToTypeID( "Stte" );

    var identer = stringIDToTypeID( "enter" );

    desc364.putEnumerated( idStte, idStte, identer );

    var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );

    desc364.putBoolean( idkcanDispatchWhileModal, true );

    executeAction( idmodalStateChanged, desc364, DialogModes.NO );

};

 

 

 

 

Below is the code for lasso and magic wand selection, if any has problems with those;

//

//==================== Select Tool MagicWand ==============

//

function SelectToolMagicwand(){

    var idslct = charIDToTypeID( "slct" );

    var desc344 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    var ref85 = new ActionReference();

    var idmagicWandTool = stringIDToTypeID( "magicWandTool" );

    ref85.putClass( idmagicWandTool );

    desc344.putReference( idnull, ref85 );

    var iddontRecord = stringIDToTypeID( "dontRecord" );

    desc344.putBoolean( iddontRecord, true );

    var idforceNotify = stringIDToTypeID( "forceNotify" );

    desc344.putBoolean( idforceNotify, true );

    executeAction( idslct, desc344, DialogModes.NO ); 

};

 

//

//==================== Select Tool Polygonal Lasso Select ==============

//

function SelectToolPolyLasso(){

    var idslct = charIDToTypeID( "slct" );

    var desc355 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    var ref90 = new ActionReference();

    var idpolySelTool = stringIDToTypeID( "polySelTool" );

    ref90.putClass( idpolySelTool );

    desc355.putReference( idnull, ref90 );

    var iddontRecord = stringIDToTypeID( "dontRecord" );

    desc355.putBoolean( iddontRecord, true );

    var idforceNotify = stringIDToTypeID( "forceNotify" );

    desc355.putBoolean( idforceNotify, true );

    executeAction( idslct, desc355, DialogModes.NO ); 

};

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)

Self Signing Panel - P12 generation failed

$
0
0

Has anyone encountered this "Error - certificate request could not be generated. P12 generation failed" when trying to self-sign a panel? I'm on Mac High Sierra. Thanks all!


How to save all actions at once with a script?

$
0
0

I have lots of actions organized in lots of folders and constantly work with them. Now I am saving all edited actions each day by saving their folders. But this is very inconvenient because sometimes I do not remember folders where I edit actions.

 

Hence, the question is - Is there a way to save all my actions at once with a script?
Would be very grateful for any answer!

How to remove xmp metadata?

$
0
0

I need to remove the "XMP metadata" information in the tiff(photoshop) files via scripting. Is it possible? Kindly advice me. Please provide examples.

 

Thanks for looking into this..

 

Regards,

Maria Prabudass

Move files

$
0
0

Hi friends! I need help getting a working script to create and move the open document to a sub folder called "Processed Image" I have this script but the current document has not been moved to the sub folder. Where is the error? Thank you

#target photoshop
app.bringToFront();
var docRef = app.activeDocument;
var sourceFolder = app.activeDocument.path ;

var File1 = docRef;
var tempFile = File1;
tempFile = tempFile.File1;
var outputFolder = new Folder(File1.path + "/Processed Image"); // defines the name of the subfolder
//Check if it exist, if not create it.
if(!outputFolder.exists) outputFolder.create(); //if subfolder not exist then create
if(tempFile != null){
var saveName = tempFile.name;
var res = tempFile.copy(new File(outputFolder+'/'+saveName));
if(res != true) throw('Unable to move file to '+decodeURI(backupFolder));
res = tempFile.copy(new File(outputFolder+'/'+saveName));
if(res != true){
throw('Unabe to move file to '+decodeURI(outputFolder));
}else{
// if we get here then the file has been backuped and moved to new folder so delete
tempFile.remove();
app.open(new File(outputFolder+'/'+saveName));// open moved file to work on
}
}

File information for smart objects

$
0
0

I need to get some information for the smart objects in PSD file using PS scripting.

1. I need to get the file path for the smart objects in a PSD. I found that for linked smart objects, the file path is accessible by opening it up as a document. But it would be nice if I could get the path without opening it up. Is there a way to achieve this using script? Also, for embedded smart objects is it possible to get the file path?

2. Is there a way to distinguish between linked smart objects and embedded smart object using script?

 

Thanks much in advance for any help.

Watch Folder

$
0
0

Hello,

 

Is there a way to have Photoshop watch a folder for new images and run some actions on the newly added files - after which removing the original from that folder.

 

I need to automate the follwoing:

Image is added to watch folder

Photoshop

  1. Detects new image
  2. Opens image
  3. Runs actions
  4. Saves to a new directory

File is deleted from watch folder.

 

I am on Mac 10.7 and have Automator at my disposal. I'm also familiar with scripting but not specifically for Photoshop so I prefer scripting would be the last resort.

 

Any help or guidance is greatly appreciated.

 

Thank you!

 

V

Automatically run scripts on files in a specific folder

$
0
0

Hello all!

 

I have a series of very effective scripts that I am running against a series of photoshop files. Now the big quiestion!

 

Is there a program to

1) "watch" a folder, so when a file is saved in that folder.

 

2) It runs my script(s) on that file?

 

If you look at it simply-- I would like to replace the "drag and drop" method used for droplets, with the "drop in the folder" method.

No doubt this would require a separate program, to consistently check the folder for new files.

 

This is something that I would prefer to tackle with python, but maybe you all in the community could provide me with a more "industry accepted" solution?

 

Oh and Ideally I would run this on both mac and PC.... though I understand if windows makes more  sense for an operation like this.

 

Best,

Thomas Murphy

Image Processor Pro not available in Bridge CC 2018

$
0
0

After updating to Photoshop CC 2018 and Bridge CC 2018 the Image Processor Pro (IPP) does not display under the Bridge > Tools > Photoshop menu.

The IPP dependencies were copied from the Photoshop 2017 to Photoshop 2018. The IPP can be accessed from Photoshop CC 2018 > File > Automate > Image processor Pro.. but not from Bridge CC 2018.

 

Currently, Photoshop CC 2017 and Bridge CC 2917 are installed locally and the IPP does display under the Bridge > Tools > Photoshop > Image Processor Pro...

Which IPP version have Mac users been able to successfully install in Bridge CC 2018 in OSX High Sierra?

 

Environment:

OSX High Sierra

MacBook Pro 2015


Changing color of text found with regex

$
0
0

Hi,

I have multiple text layers in the document. I would like to filter through the contents of each text layer with regex and change the color of the found result.

In the example below I would like to find all the hastags in the text layer and change the color to blue.

 

Example:

This is a really long piece of text copy and #hashtag more copy here #anotherhastag#hashtagNo3

 

I've written a few scripts for indesign that involve GREP(regex) and it's fairly simple to change the color of the found results. I can't seem to find a solution for this in photoshop.

 

Thanks

Problem with listboxes

$
0
0

// run this script

 

var dlg = new Window("dialog", "");

 

 

// HERE IS EXAMPLE CODE FROM "JAVASCRIPT TOOLS GUIDE.pdf" FOR CREATIVE CLOUD

 

// create list box with two titled columns

var list = dlg.add ('ListBox', [0, 0, 150, 75], 'asd',

{numberOfColumns: 2, showHeaders: true,

columnTitles: ['First Name', 'Last Name']});

// add an item for the first row, with the label value for the first column

var item1 = list.add ('item', 'John');

// add the label value for the second column in that row.

item1.subItems[0].text = 'Doe';

 

// END OF EXAMPLE

 

dlg.show();

 

// line

// item1.subItems[0].text = 'Doe';

// cause an error on PS CC2015.5 and CC2018

// WTF ?

Change the Blending Options of a layer?

$
0
0

Something I do often is to change the Blending Options of folders (groups), and I wondered if it would be possible to run a script to do it instead of having to do it manually every time.

 

What I do after opening the Blending Options on the selected folder is to hold down the Option (Alt) key and drag half of the white slider on the right over to the left (changing  it on the right hand side from 255 to 0 / 255).

 

Is there a way to run a script to do this? Any help would really be appreciated

 

 

Here are some screenshots of what I do

 

zispcv+

 

d0DOQy+

 

pkKaA6+

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

Photoshop text size bug???

$
0
0

I think there is a bug in the Photoshop scripting DOM with the text size.   The wrong text size is being reported if an image is resized after the text layers were already created.  It reports the original text size instead of the new text size.

 

app.activeDocument.activeLayer.textItem.size will always report the text size as the original text size after the image has been resized (and text is auto resized with the image resizing).  Say for instance, you create a text layer at 20 points and then resize the image to 50%.  In this case the text auto sizes down to 10 points.  In the Photoshop user interface it shows the text correctly at 10 points.  However, app.activeDocument.activeLayer.textItem.size still has the font size stored as 20 points instead of 10 points.

 

Taking it step further, when replacing the text using app.activeDocument.activeLayer.textItem.contents="New Text"..........

For CS6 it will resize the text back to the original point value (text size before the image was resized).

For CC, the text replacement does not resize the text.  It will stay at the current size.  However, CC will still report the old text size and not the current text size

 

Has anyone encountered this?  If so, would you know of a work around?

Viewing all 12244 articles
Browse latest View live


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