5 Replies Latest reply on Aug 21, 2012 4:50 PM by s.mahn

    Transferring multiple paths

    s.mahn Level 2

      When an image needs complex pathing I often outsource the pathing work. I send out a proxy flattened file for pathing, and recieve back a file with several path layers attached, and those path layers I will then want to bring into my real working file.

       

      If PS worked the way I'd like it to I'd be able to shift=click alll the paths and drag them from one file to the other, but since PS doesn't allow more than one path layer to be selected at a time, the dragging/droping of the many path layers gets tedious (especially since, if you forget to deactivate the last layer moved the next layer brought in gets compunded to it.)

       

      Is there a script that can simplify this path transfer process for me?

       

      (As I write this I realize it might just be simpler to trasnfer my layers from my working file to the proxy path file instead, but then there are alpha channels and sometimes file name issues to contend with.)

       

      Anyway, you guys have always been extremely helpful, I look forward to hearing your advice.

       

      (I'm using CS6, if it matters)

        • 1. Re: Transferring multiple paths
          JJMack Most Valuable Participant

          I'm scure a script could be written to do the job.  However creating scripts is work for me.  If you do this very often it may be worth the effort to write the script.  For some thing that you don't do often  it may simply be easier to create an action to transfer the paths to other documents.  Its quite easy to create such an action.

           

          Open the document you get back with all the paths in the paths palette.

          In the action palette create a new action set name it Transfer Paths.Next start recording a new action name it Paths for project x.

          Next hit the stop recording button.

          Then highlight the first path in the paths palette

          Use the action's plaette's fly-out menu item insert path.

          repeat this highligh and insesrt path process for the rest of the path in the paths palette.

          Then click the record button in the actions palette

          In the Paths Palette drag the "Work Path" to the New Path icon in the bottom of the Paths palette.

          Click the stop recording  button in the action's palette.

          Next hold down the Alt|options Key and drag a copy of the last step Make path to after all the other Set Work Path steps

           

          transferPaths.jpg

          Here is an example open a new document 1000px by 1000px and play this action

          http://www.mouseprints.net/old/dpr/transferpaths.atn

          • 2. Re: Transferring multiple paths
            c.pfaffenbichler Level 9

            and recieve back a file with several path layers attached,

            Do you mean Paths or Layers with Vector Masks?

            • 3. Re: Transferring multiple paths
              c.pfaffenbichler Level 9

              If you are talking about straight paths this might work:

              // transfer paths;
              // this splits subpathelements with multiple elements up into multiple subpathelements;
              // 2012; use it at your own risk;
              #target photoshop
              if (app.documents.length > 1) {
              var myDoc = app.activeDocument;
              // collect paths;
              var theNames = new Array;
              var theArrays = new Array;
              for (var m = 0; m < myDoc.pathItems.length; m++) {
                        var thisPath = myDoc.pathItems[m];
                        theNames.push(thisPath.name);
                        theArrays.push(collectPathInfoFromDesc2012(myDoc, thisPath));
                        };
              //alert (theArrays.join("\n\n"))
              if (app.documents.length == 2) {
              // switch doc;
              var idslct = charIDToTypeID( "slct" );
                  var desc4 = new ActionDescriptor();
                  var idnull = charIDToTypeID( "null" );
                      var ref4 = new ActionReference();
                      var idDcmn = charIDToTypeID( "Dcmn" );
                      ref4.putOffset( idDcmn, 1 );
                  desc4.putReference( idnull, ref4 );
              executeAction( idslct, desc4, DialogModes.NO );
              // create paths;
                        for (var n = 0; n < theNames.length; n++) {
                                  createPath2012(theArrays[n], theNames[n])
                                  }
                        }
              else {
              // dialog for document-selection;
              var dlg = new Window('dialog', "select target document", [500,300,840,525]);
              // list of docs;
              dlg.docs = dlg.add('panel', [15,15,325,145], 'select a doc');
              dlg.docs.docList = dlg.docs.add('listbox', [15,15,295,110], 'field', {multiselect: false});
              // populate the list with the docs’ names;
              for (var p = 0; p < app.documents.length; p++) {
                        dlg.docs.docList.add ("item", app.documents[p].name);
                        };
              dlg.docs.docList.items[0].selected = true;
              // buttons for ok, and cancel;
              dlg.buttons = dlg.add('panel', [15,160,325,210], '');
              dlg.buttons.buildBtn = dlg.buttons.add('button', [13,13,145,33], 'OK', {name:'ok'});
              dlg.buttons.cancelBtn = dlg.buttons.add('button', [155,13,290,33], 'Cancel', {name:'cancel'});
              // show the dialog;
              dlg.center();
              var myReturn = dlg.show ();
              ////////////////////////////////////
              if (myReturn == true) {
                        app.activeDocument = app.documents.getByName(dlg.docs.docList.selection);
              // create paths;
                        for (var n = 0; n < theNames.length; n++) {
                                  createPath2012(theArrays[n], theNames[n])
                                  }
                        };
              }
              };
              ////// 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[l];
                        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[s] || cTID[s] = app.charIDToTypeID(s); };
              function sTID (s) { return sTID[s] || sTID[s] = 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[m];
              
                  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[n];
              
                  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) {
              var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1];
              }
              else {
              var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2];
              };
              myPathItem.name = thePathsName;
              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;
              };
              
              • 4. Re: Transferring multiple paths
                JJMack Most Valuable Participant

                That script worked well for me with two document open it added the paths in the first to the second. With no open documents I did not get any dialog that the script seems to be doing. I'm on a PC windows 7 only tried with CS6 64bit module.  Ok I see with three open I get the dialog to select the target doc and that the script checks path names so  dupe names will not be created very good. I would just add an alert if document count is one or less.

                • 5. Re: Transferring multiple paths
                  s.mahn Level 2

                  Chris,

                   

                  Fantastic !!!!

                   

                  Many thanks.