Skip to main content
Known Participant
August 13, 2014
Answered

Add selection as add and intersect commands combined

  • August 13, 2014
  • 3 replies
  • 2796 views

Hello, I want to add selection to a selection so it acts as the two commands combined: add command and intersect command. Where parts of a selection intersect i want to act it as the add command - it simply adds selection to a selection. Where it does not intersect, i want it to act as the intersect command - it deletes the part of the selection that doesnt intersect. Can this be scripted?

This topic has been closed for replies.
Correct answer c.pfaffenbichler

By the way: The Script would only provide the expected result if the second Selection is one contiguous area.

Edit: This should also handle discontinuous segments for the second Selection.

// store selection on first run, on second run add overlapping parts of the sstored selection to the new selection;

// 2014, use at your own risk;

#target photoshop

if (app.documents.length > 0) {

activeDocument.suspendHistory("something with selections", "main()");

};

////// the stuff //////

function main () {

var myDocument = app.activeDocument;

var theChannelName = "removeThisChannelLaterOn";

if (hasSelection() == true) {

// if channel exists;

try {

var theChannel = myDocument.channels.getByName(theChannelName);

// store the selection;

var theOtherChannel = myDocument.channels.add();

myDocument.selection.store(theOtherChannel);

theOtherChannel.name = theChannelName+"Too";

// fill;

myDocument.activeChannels = [theChannel];

var theColor = new SolidColor();

theColor.rgb.red = 255;

theColor.rgb.green = 255;

theColor.rgb.blue = 255;

myDocument.selection.fill(theColor);

// get path information;

var path1 = workPathFromChannel (myDocument, theChannel);

var path2 = workPathFromChannel (myDocument, theOtherChannel);

// check for identical point;

var theCheck = checkForIdenticalPoints (path1, path2);

if (theCheck != false) {

var thePath = createPath2012(theCheck, "removeThisPathLaterOn");

// load;

thePath.makeSelection(0, false, SelectionType.REPLACE);

myDocument.selection.expand(1);

myDocument.selection.load(theChannel, SelectionType.INTERSECT, false)

// clean up;

thePath.remove();

}

// clean up;

theChannel.remove();

theOtherChannel.remove();

}

// if channel does not exist;

catch (e) {

// store the selection;

var theMask = myDocument.channels.add();

myDocument.selection.store(theMask);

theMask.name = theChannelName;

compositeChannels ();

showChannel (theChannelName);

myDocument.selection.deselect();

}

};

};

////// get work path  info from channel //////

function workPathFromChannel (myDocument, theChannel) {

// load;

myDocument.selection.load(theChannel, SelectionType.REPLACE);

// use threshold to heighten non black pixels;

myDocument.quickMaskMode = true;

myDocument.activeLayer.threshold(1);

myDocument.quickMaskMode = false;

// create work path;

// =======================================================

var idMk = charIDToTypeID( "Mk  " );

    var desc16 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref12 = new ActionReference();

        var idPath = charIDToTypeID( "Path" );

        ref12.putClass( idPath );

    desc16.putReference( idnull, ref12 );

    var idFrom = charIDToTypeID( "From" );

        var ref13 = new ActionReference();

        var idcsel = charIDToTypeID( "csel" );

        var idfsel = charIDToTypeID( "fsel" );

        ref13.putProperty( idcsel, idfsel );

    desc16.putReference( idFrom, ref13 );

    var idTlrn = charIDToTypeID( "Tlrn" );

    var idPxl = charIDToTypeID( "#Pxl" );

    desc16.putUnitDouble( idTlrn, idPxl, 1.000000 );

executeAction( idMk, desc16, DialogModes.NO );

// get information;

var theArray = collectPathInfoFromDesc2012 (myDocument, myDocument.pathItems[myDocument.pathItems.length - 1]);

return theArray

};

////// check for selection //////

function hasSelection(){

var ref10 = new ActionReference();

ref10.putEnumerated( charIDToTypeID( "Dcmn" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

var docDesc = executeActionGet(ref10);

return docDesc.hasKey(stringIDToTypeID("selection"));

};

////// go to composite channels //////

function compositeChannels () {

// =======================================================

var idslct = charIDToTypeID( "slct" );

    var desc2 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref2 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idChnl = charIDToTypeID( "Chnl" ); 

switch (activeDocument.mode) {

    case DocumentMode.RGB:

        var idComposite = charIDToTypeID( "RGB " );

        break;

    case DocumentMode.CMYK:

        var idComposite = charIDToTypeID( "CMYK" );

        break;

    case DocumentMode.LAB:

        var idComposite = charIDToTypeID( "Lab " );

        break;

    case DocumentMode.GRAYSCALE:

        var idComposite = charIDToTypeID( "Blck" );

        break;

        };

        ref2.putEnumerated( idChnl, idChnl, idComposite );

    desc2.putReference( idnull, ref2 );

executeAction( idslct, desc2, DialogModes.NO );

};

////// chow channel of name //////

function showChannel (theName) {

// =======================================================

var idShw = charIDToTypeID( "Shw " );

    var desc3 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var list1 = new ActionList();

            var ref3 = new ActionReference();

            var idChnl = charIDToTypeID( "Chnl" );

            ref3.putName( idChnl, theName );

        list1.putReference( ref3 );

    desc3.putList( idnull, list1 );

executeAction( idShw, desc3, DialogModes.NO );

};

////// collect path info from actiondescriptor, smooth added //////

function collectPathInfoFromDesc2012 (myDocument, thePath) {

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.POINTS;

// based of functions from xbytor’s stdlib;

var ref = new ActionReference();

for (var l = 0; l < myDocument.pathItems.length; l++) {

  var thisPath = myDocument.pathItems;

  if (thisPath == thePath && thisPath.name == "Work Path") {

  ref.putProperty(cTID("Path"), cTID("WrPt"));

  };

  if (thisPath == thePath && thisPath.name != "Work Path" && thisPath.kind != PathKind.VECTORMASK) {

  ref.putIndex(cTID("Path"), l + 1);

  };

  if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {

        var idPath = charIDToTypeID( "Path" );

        var idPath = charIDToTypeID( "Path" );

        var idvectorMask = stringIDToTypeID( "vectorMask" );

        ref.putEnumerated( idPath, idPath, idvectorMask );

  };

  };

var desc = app.executeActionGet(ref);

var pname = desc.getString(cTID('PthN'));

// create new array;

var theArray = new Array;

var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));

// for subpathitems;

for (var m = 0; m < pathComponents.count; m++) {

  var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));

  var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));

  switch (operation1) {

  case 1097098272:

  var operation = 1097098272 //cTID('Add ');

  break;

  case 1398961266:

  var operation = 1398961266 //cTID('Sbtr');

  break;

  case 1231975538:

  var operation = 1231975538 //cTID('Intr');

  break;

  default:

// case 1102:

  var operation = sTID('xor') //ShapeOperation.SHAPEXOR;

  break;

  };

// for subpathitem’s count;

  for (var n = 0; n < listKey.count; n++) {

  theArray.push(new Array);

  var points = listKey.getObjectValue(n).getList(sTID('points'));

  try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}

  catch (e) {var closed = false};

// for subpathitem’s segment’s number of points;

  for (var o = 0; o < points.count; o++) {

  var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));

  var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];

  var thisPoint = [anchor];

  try {

  var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));

  var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];

  thisPoint.push(leftDirection)

  }

  catch (e) {

  thisPoint.push(anchor)

  };

  try {

  var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));

  var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];

  thisPoint.push(rightDirection)

  }

  catch (e) {

  thisPoint.push(anchor)

  };

  try {

  var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));

  thisPoint.push(smoothOr)

  }

  catch (e) {thisPoint.push(false)};

  theArray[theArray.length - 1].push(thisPoint);

  };

  theArray[theArray.length - 1].push(closed);

  theArray[theArray.length - 1].push(operation);

  };

  };

// by xbytor, thanks to him;

function cTID (s) { return cTID || cTID = app.charIDToTypeID(s); };

function sTID (s) { return sTID || sTID = app.stringIDToTypeID(s); };

// reset;

app.preferences.rulerUnits = originalRulerUnits;

return theArray;

};

////// create a path from collectPathInfoFromDesc2012-array //////

function createPath2012(theArray, thePathsName) {

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.POINTS;

// thanks to xbytor;

cTID = function(s) { return app.charIDToTypeID(s); };

sTID = function(s) { return app.stringIDToTypeID(s); };

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putProperty(cTID('Path'), cTID('WrPt'));

    desc1.putReference(sTID('null'), ref1);

    var list1 = new ActionList();

for (var m = 0; m < theArray.length; m++) {

  var thisSubPath = theArray;

    var desc2 = new ActionDescriptor();

    desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);

    var list2 = new ActionList();

    var desc3 = new ActionDescriptor();

    desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);

    var list3 = new ActionList();

for (var n = 0; n < thisSubPath.length - 2; n++) {

  var thisPoint = thisSubPath;

    var desc4 = new ActionDescriptor();

    var desc5 = new ActionDescriptor();

    desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);

    desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);

    desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);

    var desc6 = new ActionDescriptor();

    desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);

    desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);

    desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);

    var desc7 = new ActionDescriptor();

    desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);

    desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);

    desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);

    desc4.putBoolean(cTID('Smoo'), thisPoint[3]);

    list3.putObject(cTID('Pthp'), desc4);

  };

    desc3.putList(cTID('Pts '), list3);

    list2.putObject(cTID('Sbpl'), desc3);

    desc2.putList(cTID('SbpL'), list2);

    list1.putObject(cTID('PaCm'), desc2);

  };

    desc1.putList(cTID('T   '), list1);

    executeAction(cTID('setd'), desc1, DialogModes.NO);

if (hasVectorMask() == false) {

if (thePathsName != undefined) {app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1].name = thePathsName};

var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1];

}

else {

if (thePathsName != undefined) {app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2].name = thePathsName};

var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2];

};

app.preferences.rulerUnits = originalRulerUnits;

return myPathItem

};

// from »Flatten All Masks.jsx« by jeffrey tranberry;

///////////////////////////////////////////////////////////////////////////////

// Function: hasVectorMask

// Usage: see if there is a vector layer mask

// Input: <none> Must have an open document

// Return: true if there is a vector mask

///////////////////////////////////////////////////////////////////////////////

function hasVectorMask() {

  var hasVectorMask = false;

  try {

  var ref = new ActionReference();

  var keyVectorMaskEnabled = app.stringIDToTypeID( 'vectorMask' );

  var keyKind = app.charIDToTypeID( 'Knd ' );

  ref.putEnumerated( app.charIDToTypeID( 'Path' ), app.charIDToTypeID( 'Ordn' ), keyVectorMaskEnabled );

  var desc = executeActionGet( ref );

  if ( desc.hasKey( keyKind ) ) {

  var kindValue = desc.getEnumerationValue( keyKind );

  if (kindValue == keyVectorMaskEnabled) {

  hasVectorMask = true;

  }

  }

  }catch(e) {

  hasVectorMask = false;

  }

  return hasVectorMask;

};

////// check for identical pathpoints //////

function checkForIdenticalPoints (array1, array2) {

var theReturn = new Array;

// the subpathitems;

for (var m = 0; m < array1.length; m++) {

var firstCheck = false;

var thisSub = array1;

var someReturn = compareSubPathWithPath (thisSub, array2);

if (someReturn != undefined) {theReturn.push(someReturn)};

////// return subpathitem if ine point is idetical //////

function compareSubPathWithPath (thisSub, array2) {

// the other subpathitems;

for (var n = 0; n < array2.length; n++) {

var thisOtherSub = array2;

// the points;

for (var o = 0; o < thisSub.length - 2; o++) {

var thisPoint = thisSub[0];

// other point:

for (var p = 0; p < thisOtherSub.length - 2; p++) {

var otherPoint = thisOtherSub

[0];

// terminate if one identical pont is found;

if (thisPoint[0] == otherPoint[0] && thisPoint[1] == otherPoint[1]) {return thisSub}

}

}

}

};

////////////////////////////////////

};

if (theReturn.length > 0) {return theReturn}

else {return false}

};

3 replies

c.pfaffenbichler
Community Expert
Community Expert
August 19, 2014

I hope you noticed the edited code in the last post.

Anyway, if you were willing to change your procedure a bit one could get away with a one-stop-Script, I suppose.

You’d have to switch to Quick Mask Mode after making the first Selection, then make the second Selection and after that run a new Script.

MonstrikAuthor
Known Participant
August 25, 2014

Dear c.pfaffenbichler

I appreciate your help so much. But Im forced to ask for more help from you... The problem is that i dont know how to use the script you wrote for me. As i said earlier your skills are way more advanced than mine. I meant i know nothing about scripting, i dont even know how to run a script.

Other question arised is how should i call my selections so the script recognises the selections when the script is being run? Please find screenshots attached.. For example, i have these two selections: "Selection C" and "Selection A". (Let's assume Selection D doesnt exist. "Selection D" is what i want to accomplish. So, i have these two selections stored: A and C. How do i begin to use the script you wrote? To get the result D? Can you please attach some screenshots? Can you please give me step by step instructions?

also, as i tried to explain earlier, the selection C will always be part of or with the selection's D boundaries (or the be clear - part of the selection A)



MonstrikAuthor
Known Participant
August 27, 2014

Make a Selection.

Run the Script (the newly amended one from post 17).

Make another Selection.

Run the Script again.


Christoph when you say "make a selection" do you mean load selection?

i mean the selections are already made.. I just need to use them to get what i want... Please explain

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
August 18, 2014

By the way: The Script would only provide the expected result if the second Selection is one contiguous area.

Edit: This should also handle discontinuous segments for the second Selection.

// store selection on first run, on second run add overlapping parts of the sstored selection to the new selection;

// 2014, use at your own risk;

#target photoshop

if (app.documents.length > 0) {

activeDocument.suspendHistory("something with selections", "main()");

};

////// the stuff //////

function main () {

var myDocument = app.activeDocument;

var theChannelName = "removeThisChannelLaterOn";

if (hasSelection() == true) {

// if channel exists;

try {

var theChannel = myDocument.channels.getByName(theChannelName);

// store the selection;

var theOtherChannel = myDocument.channels.add();

myDocument.selection.store(theOtherChannel);

theOtherChannel.name = theChannelName+"Too";

// fill;

myDocument.activeChannels = [theChannel];

var theColor = new SolidColor();

theColor.rgb.red = 255;

theColor.rgb.green = 255;

theColor.rgb.blue = 255;

myDocument.selection.fill(theColor);

// get path information;

var path1 = workPathFromChannel (myDocument, theChannel);

var path2 = workPathFromChannel (myDocument, theOtherChannel);

// check for identical point;

var theCheck = checkForIdenticalPoints (path1, path2);

if (theCheck != false) {

var thePath = createPath2012(theCheck, "removeThisPathLaterOn");

// load;

thePath.makeSelection(0, false, SelectionType.REPLACE);

myDocument.selection.expand(1);

myDocument.selection.load(theChannel, SelectionType.INTERSECT, false)

// clean up;

thePath.remove();

}

// clean up;

theChannel.remove();

theOtherChannel.remove();

}

// if channel does not exist;

catch (e) {

// store the selection;

var theMask = myDocument.channels.add();

myDocument.selection.store(theMask);

theMask.name = theChannelName;

compositeChannels ();

showChannel (theChannelName);

myDocument.selection.deselect();

}

};

};

////// get work path  info from channel //////

function workPathFromChannel (myDocument, theChannel) {

// load;

myDocument.selection.load(theChannel, SelectionType.REPLACE);

// use threshold to heighten non black pixels;

myDocument.quickMaskMode = true;

myDocument.activeLayer.threshold(1);

myDocument.quickMaskMode = false;

// create work path;

// =======================================================

var idMk = charIDToTypeID( "Mk  " );

    var desc16 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref12 = new ActionReference();

        var idPath = charIDToTypeID( "Path" );

        ref12.putClass( idPath );

    desc16.putReference( idnull, ref12 );

    var idFrom = charIDToTypeID( "From" );

        var ref13 = new ActionReference();

        var idcsel = charIDToTypeID( "csel" );

        var idfsel = charIDToTypeID( "fsel" );

        ref13.putProperty( idcsel, idfsel );

    desc16.putReference( idFrom, ref13 );

    var idTlrn = charIDToTypeID( "Tlrn" );

    var idPxl = charIDToTypeID( "#Pxl" );

    desc16.putUnitDouble( idTlrn, idPxl, 1.000000 );

executeAction( idMk, desc16, DialogModes.NO );

// get information;

var theArray = collectPathInfoFromDesc2012 (myDocument, myDocument.pathItems[myDocument.pathItems.length - 1]);

return theArray

};

////// check for selection //////

function hasSelection(){

var ref10 = new ActionReference();

ref10.putEnumerated( charIDToTypeID( "Dcmn" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

var docDesc = executeActionGet(ref10);

return docDesc.hasKey(stringIDToTypeID("selection"));

};

////// go to composite channels //////

function compositeChannels () {

// =======================================================

var idslct = charIDToTypeID( "slct" );

    var desc2 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref2 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idChnl = charIDToTypeID( "Chnl" ); 

switch (activeDocument.mode) {

    case DocumentMode.RGB:

        var idComposite = charIDToTypeID( "RGB " );

        break;

    case DocumentMode.CMYK:

        var idComposite = charIDToTypeID( "CMYK" );

        break;

    case DocumentMode.LAB:

        var idComposite = charIDToTypeID( "Lab " );

        break;

    case DocumentMode.GRAYSCALE:

        var idComposite = charIDToTypeID( "Blck" );

        break;

        };

        ref2.putEnumerated( idChnl, idChnl, idComposite );

    desc2.putReference( idnull, ref2 );

executeAction( idslct, desc2, DialogModes.NO );

};

////// chow channel of name //////

function showChannel (theName) {

// =======================================================

var idShw = charIDToTypeID( "Shw " );

    var desc3 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var list1 = new ActionList();

            var ref3 = new ActionReference();

            var idChnl = charIDToTypeID( "Chnl" );

            ref3.putName( idChnl, theName );

        list1.putReference( ref3 );

    desc3.putList( idnull, list1 );

executeAction( idShw, desc3, DialogModes.NO );

};

////// collect path info from actiondescriptor, smooth added //////

function collectPathInfoFromDesc2012 (myDocument, thePath) {

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.POINTS;

// based of functions from xbytor’s stdlib;

var ref = new ActionReference();

for (var l = 0; l < myDocument.pathItems.length; l++) {

  var thisPath = myDocument.pathItems;

  if (thisPath == thePath && thisPath.name == "Work Path") {

  ref.putProperty(cTID("Path"), cTID("WrPt"));

  };

  if (thisPath == thePath && thisPath.name != "Work Path" && thisPath.kind != PathKind.VECTORMASK) {

  ref.putIndex(cTID("Path"), l + 1);

  };

  if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {

        var idPath = charIDToTypeID( "Path" );

        var idPath = charIDToTypeID( "Path" );

        var idvectorMask = stringIDToTypeID( "vectorMask" );

        ref.putEnumerated( idPath, idPath, idvectorMask );

  };

  };

var desc = app.executeActionGet(ref);

var pname = desc.getString(cTID('PthN'));

// create new array;

var theArray = new Array;

var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));

// for subpathitems;

for (var m = 0; m < pathComponents.count; m++) {

  var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));

  var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));

  switch (operation1) {

  case 1097098272:

  var operation = 1097098272 //cTID('Add ');

  break;

  case 1398961266:

  var operation = 1398961266 //cTID('Sbtr');

  break;

  case 1231975538:

  var operation = 1231975538 //cTID('Intr');

  break;

  default:

// case 1102:

  var operation = sTID('xor') //ShapeOperation.SHAPEXOR;

  break;

  };

// for subpathitem’s count;

  for (var n = 0; n < listKey.count; n++) {

  theArray.push(new Array);

  var points = listKey.getObjectValue(n).getList(sTID('points'));

  try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}

  catch (e) {var closed = false};

// for subpathitem’s segment’s number of points;

  for (var o = 0; o < points.count; o++) {

  var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));

  var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];

  var thisPoint = [anchor];

  try {

  var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));

  var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];

  thisPoint.push(leftDirection)

  }

  catch (e) {

  thisPoint.push(anchor)

  };

  try {

  var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));

  var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];

  thisPoint.push(rightDirection)

  }

  catch (e) {

  thisPoint.push(anchor)

  };

  try {

  var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));

  thisPoint.push(smoothOr)

  }

  catch (e) {thisPoint.push(false)};

  theArray[theArray.length - 1].push(thisPoint);

  };

  theArray[theArray.length - 1].push(closed);

  theArray[theArray.length - 1].push(operation);

  };

  };

// by xbytor, thanks to him;

function cTID (s) { return cTID || cTID = app.charIDToTypeID(s); };

function sTID (s) { return sTID || sTID = app.stringIDToTypeID(s); };

// reset;

app.preferences.rulerUnits = originalRulerUnits;

return theArray;

};

////// create a path from collectPathInfoFromDesc2012-array //////

function createPath2012(theArray, thePathsName) {

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.POINTS;

// thanks to xbytor;

cTID = function(s) { return app.charIDToTypeID(s); };

sTID = function(s) { return app.stringIDToTypeID(s); };

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putProperty(cTID('Path'), cTID('WrPt'));

    desc1.putReference(sTID('null'), ref1);

    var list1 = new ActionList();

for (var m = 0; m < theArray.length; m++) {

  var thisSubPath = theArray;

    var desc2 = new ActionDescriptor();

    desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);

    var list2 = new ActionList();

    var desc3 = new ActionDescriptor();

    desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);

    var list3 = new ActionList();

for (var n = 0; n < thisSubPath.length - 2; n++) {

  var thisPoint = thisSubPath;

    var desc4 = new ActionDescriptor();

    var desc5 = new ActionDescriptor();

    desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);

    desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);

    desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);

    var desc6 = new ActionDescriptor();

    desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);

    desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);

    desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);

    var desc7 = new ActionDescriptor();

    desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);

    desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);

    desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);

    desc4.putBoolean(cTID('Smoo'), thisPoint[3]);

    list3.putObject(cTID('Pthp'), desc4);

  };

    desc3.putList(cTID('Pts '), list3);

    list2.putObject(cTID('Sbpl'), desc3);

    desc2.putList(cTID('SbpL'), list2);

    list1.putObject(cTID('PaCm'), desc2);

  };

    desc1.putList(cTID('T   '), list1);

    executeAction(cTID('setd'), desc1, DialogModes.NO);

if (hasVectorMask() == false) {

if (thePathsName != undefined) {app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1].name = thePathsName};

var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1];

}

else {

if (thePathsName != undefined) {app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2].name = thePathsName};

var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2];

};

app.preferences.rulerUnits = originalRulerUnits;

return myPathItem

};

// from »Flatten All Masks.jsx« by jeffrey tranberry;

///////////////////////////////////////////////////////////////////////////////

// Function: hasVectorMask

// Usage: see if there is a vector layer mask

// Input: <none> Must have an open document

// Return: true if there is a vector mask

///////////////////////////////////////////////////////////////////////////////

function hasVectorMask() {

  var hasVectorMask = false;

  try {

  var ref = new ActionReference();

  var keyVectorMaskEnabled = app.stringIDToTypeID( 'vectorMask' );

  var keyKind = app.charIDToTypeID( 'Knd ' );

  ref.putEnumerated( app.charIDToTypeID( 'Path' ), app.charIDToTypeID( 'Ordn' ), keyVectorMaskEnabled );

  var desc = executeActionGet( ref );

  if ( desc.hasKey( keyKind ) ) {

  var kindValue = desc.getEnumerationValue( keyKind );

  if (kindValue == keyVectorMaskEnabled) {

  hasVectorMask = true;

  }

  }

  }catch(e) {

  hasVectorMask = false;

  }

  return hasVectorMask;

};

////// check for identical pathpoints //////

function checkForIdenticalPoints (array1, array2) {

var theReturn = new Array;

// the subpathitems;

for (var m = 0; m < array1.length; m++) {

var firstCheck = false;

var thisSub = array1;

var someReturn = compareSubPathWithPath (thisSub, array2);

if (someReturn != undefined) {theReturn.push(someReturn)};

////// return subpathitem if ine point is idetical //////

function compareSubPathWithPath (thisSub, array2) {

// the other subpathitems;

for (var n = 0; n < array2.length; n++) {

var thisOtherSub = array2;

// the points;

for (var o = 0; o < thisSub.length - 2; o++) {

var thisPoint = thisSub[0];

// other point:

for (var p = 0; p < thisOtherSub.length - 2; p++) {

var otherPoint = thisOtherSub

[0];

// terminate if one identical pont is found;

if (thisPoint[0] == otherPoint[0] && thisPoint[1] == otherPoint[1]) {return thisSub}

}

}

}

};

////////////////////////////////////

};

if (theReturn.length > 0) {return theReturn}

else {return false}

};

MonstrikAuthor
Known Participant
August 27, 2014

Christoph You are a Magician...!!!  I dont know how you did it but it works!!! It really does...!!! Thank you very much!!!

c.pfaffenbichler
Community Expert
Community Expert
August 13, 2014
Where it does not intersect, i want it to act as the intersect command

Say what?

Could you maybe post a sketch/screenshot to clarify?

MonstrikAuthor
Known Participant
August 13, 2014

MonstrikAuthor
Known Participant
August 13, 2014

Sorry it didnt come out in the right order, as i posted these from my mobile phone. i hope you get the idea