Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Stuck at Path Items

Guide ,
Apr 24, 2009 Apr 24, 2009

OK, I started to put this together last night and Im now stuck. What Im wanting to do is check for a condition document has clipping path or document has work path etc. In AppleScript I can use "whose" to act as a filter like this:

delete (every channel whose kind is not component channel)

Is there such a method in JavaScript or do I need to create a while loop and test each?

Here is where I have got to at the moment with my test file. A few of my commented needs I have now found over at www.ps-scripts.com The if else stuff needs moving about but I will attempt that L8R. Thanks

// Record user application preferences

var userRulerUnits = app.preferences.rulerUnits;

var userTypeUnits = app.preferences.typeUnits;

var userBeepWhenDone = app.preferences.beepWhenDone;

var userMacOSThumbnail = app.preferences.macOSThumbnail;

var userWindowsThumbnail = app.preferences.windowsThumbnail;

var userNotifiersEnabled = app.preferences.notifiersEnabled;

var userBackgroundColor = app.backgroundColor;

var userForegroundColor = app.foregroundColor;

var userColorSettings = app.colorSettings;

var userDisplayDialogs = app.displayDialogs;

// Set application preferences

app.preferences.rulerUnits = Units.PIXELS;

app.preferences.typeUnits = TypeUnits.POINTS;

app.preferences.beepWhenDone = false;

app.preferences.macOSThumbnail = true;

app.preferences.windowsThumbnail = true;

app.preferences.notifiersEnabled = false;

// Create a solid colour array for White

var whiteRef = new SolidColor()

whiteRef.cmyk.cyan = 0

whiteRef.cmyk.magenta = 0

whiteRef.cmyk.yellow = 0

whiteRef.cmyk.black = 0

// Create a solid colour array for Black

var blackRef = new SolidColor()

blackRef.cmyk.cyan = 0

blackRef.cmyk.magenta = 0

blackRef.cmyk.yellow = 0

blackRef.cmyk.black = 100

app.backgroundColor = whiteRef

app.foregroundColor = blackRef

// app.colorSettings = I will come back to this!!

app.displayDialogs = DialogModes.NO;

// This will become loop L8R

// Do my stuff with File here!!!

var fileRef = new File ("~/Desktop" + "/TestFile.psd")

var docRef = app.open (fileRef)

var docHeight = docRef.height;

var docWidth = docRef.width;

var docColorProfileName = docRef.colorProfileName;

var docMode = docRef.mode;

  if (docMode = "RGB") {

     alert("File is RGB");

       if (docColorProfileName != "Adobe RGB (1998)") {

     alert("File is wrong Colour Profile?");

     // Here I need to change the Profile to "Adobe RGB (1998)"

     docRef.colorProfileName = "Adobe RGB (1998)";

  }

     // Here I need to change the mode to CMYK

    docRef.changeMode(ChangeMode.CMYK);

  }

var docBitsPerChannel = docRef.bitsPerChannel;

  if (docBitsPerChannel = 16) {

     alert("File is I6 Bit");

     // Here I need to change the bit depth to 8

     docRef.bitsPerChannel = BitsPerChannelType.EIGHT;

  }

var docResolution = docRef.resolution

  if (docResolution != 300) {

     alert("File is not 300dpi");

     // Here I need to change the resolution to 300

     docRef.resizeImage(undefined, undefined, 300, ResampleMethod.NONE);

  }

var docPathsItems = docRef.pathItems.length

  if (docPathsItems >= 1) {

     alert("File has one or more Path Items");

     // Here I need to do some other checks

     // First look for Clipping Path item

     // Second Look for Saved path item

     // Third Look for work path item

     }

     else

     {

     alert("File has NO Path Items");

     // Here I will do somthing else as you would expect!!!

     }

// docRef.close( SaveOptions.DONOTSAVECHANGES );

// End my stuff with File…

// End my loop…

// Re-Set user application preferences

app.preferences.rulerUnits = userRulerUnits;

app.preferences.typeUnits = userTypeUnits;

app.preferences.beepWhenDone = userBeepWhenDone;

app.preferences.macOSThumbnail = userMacOSThumbnail;

app.preferences.windowsThumbnail = userWindowsThumbnail;

app.preferences.notifiersEnabled = userNotifiersEnabled;

app.backgroundColor = userBackgroundColor;

app.foregroundColor = userForegroundColor;

app.colorSettings = userColorSettings;

app.displayDialogs = userDisplayDialogs;

// Below is borrowed code from Paul Riggott that I have edited will try this L8R

// Save file as TIFF function

function SaveFileasTIFF(saveFile){

tiffSaveOptions = new TiffSaveOptions();

tiffSaveOptions.alphaChannels = false;

tiffSaveOptions.byteOrder = ByteOrder.MACOS;

tiffSaveOptions.embedColorProfile = true;

tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;

tiffSaveOptions.layers = false;

tiffSaveOptions.spotColors = false;

tiffSaveOptions.transparency = false;

activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);

}

// Save file as EPS function

function SaveFileasEPS(saveFile){

epsSaveOptions = new EPSSaveOptions();

epsSaveOptions.embedColorProfile = true;

epsSaveOptions.encoding = SaveEncoding.BINARY;

epsSaveOptions.preview = Preview.EIGHTBITTIFF;

activeDocument.saveAs(saveFile,epsSaveOptions, true,Extension.LOWERCASE);

}

// Save file as JPEG function

function SaveFileasJPEG(saveFile){

jpgSaveOptions = new JPEGSaveOptions()

jpgSaveOptions.embedColorProfile = true

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE

jpgSaveOptions.matte = MatteType.NONE

jpgSaveOptions.quality = 12;

activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE)

}

// Save file as PSD function

function SaveFileasPSD(saveFile){

psdSaveOptions = new PhotoshopSaveOptions();

psdSaveOptions.alphaChannels = true;

psdSaveOptions.annotations = true;

psdSaveOptions.embedColorProfile = true;

psdSaveOptions.layers = true;

psdSaveOptions.spotColors = true;

activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);

}

TOPICS
Actions and scripting
4.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Apr 26, 2009 Apr 26, 2009

You can use the function clippingPathIndex to see the the doc has a clipping path.

I think you need to save a workpath before it can be used as clipping

if ( clippingPath = false && docRef.pathItems[0].kind != PathKind.WORKPATH) {// if already saved

  docRef.pathItems[0].makeClippingPath(0.5);

docRef.pathItems[0].makeSelection(0, true, SelectionType.REPLACE);

docRef.pathItems[0].deselect()

}else{// if not save then convert

    if(docRef.pathItems[0].kind == PathKind.WORKPATH){// check just to be

...
Translate
Adobe
Valorous Hero ,
Apr 24, 2009 Apr 24, 2009

Hi Mark, download the code for "Complex Batch" here http://www.ps-scripts.com/bb/viewtopic.php?t=2625

If you look through the code you will see how I have found the clipping mask.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 24, 2009 Apr 24, 2009

Paul, thanks I will look there. I have been looking through quite a bit of your code examples over there as well as others. I've downloaded some that I think will be relevant to me. Although I saw that it said CS4 only so I did not look. Im thinking I need a 3 way switch with a loop in each but I will go see what you did first. This part is going to be tricky for me I know.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 24, 2009 Apr 24, 2009

The CS4 only is because of the save for web part of the script, as it supports all the metadata options that previous versions don't. all the rest of the code will be fine for any other versions of Photoshop.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 24, 2009 Apr 24, 2009

As long as you are not concerned about paths of a vector mask you can just loop through the pathItems and check the kind property. Soemthing like this

var doc = activeDocument;
var paths = doc.pathItems;
for ( var p = 0; p < paths.length; p++ ) {
    if( paths

.kind == PathKind.CLIPPINGPATH ){
        // code to deal with the clipping path
    }
    if( paths

.kind == PathKind.NORMALPATH ){
        // code to deal with saved paths
    }
    if( paths

.kind == PathKind.WORKPATH ){
        // code to deal with the work path
    }
}

If you do want to deal with vector mask paths you have to do a nested loop with the outside loop for layers and the inside loop for paths.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 24, 2009 Apr 24, 2009

Mike, with the exception of your p's and my i's thats what I have but not sure now if its going to work the way I want it to. I will check though and come back. Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 24, 2009 Apr 24, 2009

Paul, not only does your code look like it may have a solution to my Path Items there is also other stuff that I want to do L8R in there. So cool. Still better off reinventing the wheel 4 now as don't know what I might break if I tried to edit it myself. Parts I can understand then all of a sudden wow head falls off…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 24, 2009 Apr 24, 2009

I must have misunderstood you post. I thought that you were asking how to do the commented lines in your if statement. I don't see where you have a for loop for pathItems in your post.

But no worries - glad you came up with something.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 24, 2009 Apr 24, 2009

You were correct Mike it's just since posting this morning I had done a little more digging about and what you later posted was in fact the same as what I had put here to try out. Many thanks for responding anyhow. I will do some testing with it when I get the time.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 26, 2009 Apr 26, 2009

Im unable to get into www.ps-scripts.com today is it just me or is it down?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 26, 2009 Apr 26, 2009

Always the case the second you say something then go back all is well. I can continue to do some digging happy now…
Was getting a critical error what ever that is?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 26, 2009 Apr 26, 2009

I am close with this but NO cigar!!! What Im try to do if file has multi path items look for a clipping path first if it has one use it else make the first path item clipping and use it. If the file has only one path item check for work path if so save it first then make clipping and use it. What I can't grasp at the minute is the checking of none of the paths being clipping and using the first.

This is where Im at and stuck again!!

var docPathsItems = docRef.pathItems.length

  if (docPathsItems >= 2) {

     alert("File has multi Path Items");

     // Here I need to do some other checks

     var clippingPath = false

     for(var a = 0;a<docPathsItems;a++){

if(docRef.pathItems.kind == PathKind.CLIPPINGPATH){

clippingPath = true

docRef.pathItems.getByName(docRef.pathItems.name).makeClippingPath(0.5);

docRef.pathItems.getByName(docRef.pathItems.name).makeSelection(0, true, SelectionType.REPLACE);

docRef.pathItems.getByName(docRef.pathItems.name).deselect();

}

}

// What do I have wrong with this?

if (clippingPath = false) {

  docRef.pathItems[0].makeClippingPath(0.5);

docRef.pathItems[0].makeSelection(0, true, SelectionType.REPLACE);

docRef.pathItems[0].deselect()

}

}

   if (docPathsItems == 1) {

     alert("File has a one Path Item");

     if(docRef.pathItems[0].kind == PathKind.WORKPATH){

     docRef.pathItems[0].name = "Saved Workpath"

     }

  docRef.pathItems[0].makeClippingPath(0.5);

docRef.pathItems[0].makeSelection(0, true, SelectionType.REPLACE);

docRef.pathItems[0].deselect()

  }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 26, 2009 Apr 26, 2009

You can use the function clippingPathIndex to see the the doc has a clipping path.

I think you need to save a workpath before it can be used as clipping

if ( clippingPath = false && docRef.pathItems[0].kind != PathKind.WORKPATH) {// if already saved

  docRef.pathItems[0].makeClippingPath(0.5);

docRef.pathItems[0].makeSelection(0, true, SelectionType.REPLACE);

docRef.pathItems[0].deselect()

}else{// if not save then convert

    if(docRef.pathItems[0].kind == PathKind.WORKPATH){// check just to be sure

      docRef.pathItems[0].name = "Saved Workpath"

      docRef.pathItems[0].makeClippingPath(0.5);

      docRef.pathItems[0].makeSelection(0, true, SelectionType.REPLACE);

      docRef.pathItems[0].deselect()

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 26, 2009 Apr 26, 2009

That error normally means that the forum app can not connect to the database. I assume that it is an issue with Andrew's server as it happens about the same time of day every so often. It doesn't last long.

Glad to see the you have become a member of PS-Scripts.

Mike

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 26, 2009 Apr 26, 2009

Its already being a big help on my learning path lots of stuff to dig my way through. I have more PDF documentation to be reading than I can shake a stick at. It lots of back a forth and slow progress at the moment until I start getting to grips with the terminology.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 01, 2009 May 01, 2009
LATEST

Got there in the end with this and all appears to be working as I wished.

// Use clipping path else use path 1 even if its a work path

function ProcessPaths(){

if (docRef.pathItems.length >= 2) {

   for(var a = 0;a < docRef.pathItems.length;a++){

   if(docRef.pathItems.kind == PathKind.CLIPPINGPATH){

   docRef.pathItems.makeClippingPath(0.5);

   docRef.pathItems.makeSelection(0, true, SelectionType.REPLACE);

   docRef.pathItems.deselect();

   }

   }

}

if (docRef.pathItems.length == 1) {

   if(docRef.pathItems[0].kind == PathKind.WORKPATH){

   docRef.pathItems[0].name = "Clipping Path"

   }

   docRef.pathItems[0].makeClippingPath(0.5);

   docRef.pathItems[0].makeSelection(0, true, SelectionType.REPLACE);

   docRef.pathItems[0].deselect()

   }

}

Thanks for the help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 24, 2009 Apr 24, 2009

You can use this function to test for a clipping path without the need to loop through the paths

///////////////////////////////////////////////////////////////////////////////
// Function: clippingPathIndex
// Description: Gets the index of the activeDocument's clipping path
// Usage: clippingPathIndex()
// Input: None
// Return: Index as Integer. -1 if there is no clipping path
///////////////////////////////////////////////////////////////////////////////
function clippingPathIndex(){
var ref = new ActionReference();
    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet( ref );
var clippingPath =  desc.getObjectValue(charIDToTypeID("Clpg"));
return  clippingPath.getInteger(charIDToTypeID("ClpI" ));
};
clippingPathIndex();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines