5 Replies Latest reply on Jan 28, 2010 6:52 PM by Michael L Hale

    convert layer shape to pathItem

    hilukasz Level 1

      I'm trying to get shape of layer (rectangular) and convert it to pathItem

      var art = activeDocument.artLayers.getByName("art");
      var artBounds = activeDocument.activeLayer.bounds;
      app.activeDocument.pathItems.add("myPath", artBounds);
      

       

      seems to lock up photoshop or crash it. maybe I'm missing something.

        • 1. Re: convert layer shape to pathItem
          Michael L Hale Level 5

          See the scripting guide to see how to create a path with scripting. It's not much fun.

           

          Most of the time you can just load the layer as a selection and make a path from that selection

           

          ///////////////////////////////////////////////////////////////////////////////
          // Function: layerPixels2Selection
          // Description: Loads the layer as selection
          //                        same as ctrl-click on layer icon
          // Usage: layerPixels2Selection();
          // Input: 
          // Return: -1 if no selection
          // Note: if layer is empty or Background layer
          //            no selection is made.         
          ///////////////////////////////////////////////////////////////////////////////
          function layerPixels2Selection(){
             if(app.activeDocument.activeLayer.isBackgroundLayer){
                return -1;
             }
             var desc = new ActionDescriptor();
             var ref = new ActionReference();
             ref.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
             desc.putReference( charIDToTypeID( "null" ), ref );
             var ref1 = new ActionReference();
             ref1.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
             desc.putReference( charIDToTypeID( "T   " ), ref1 );
             executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
             try{
                  activeDocument.selection.bounds;
             }catch(e){
                  return -1;
             }
          }
          layerPixels2Selection();
          activeDocument.selection.makeWorkPath();
          
          • 2. Re: convert layer shape to pathItem
            hilukasz Level 1

            I want to also convert the workpath here to normal path and give it a name. I'm assuming I should do this via script listener too?

            • 3. Re: convert layer shape to pathItem
              Michael L Hale Level 5

              You don't need scriptlistner. All you have to do is rename it to convert from a work path to a normal path

               

              The work path will be the last path unless the activeLayer has a vector mask. So check the last path if it's name is Work Path if so - rename, if not check the second to last.

              • 4. Re: convert layer shape to pathItem
                hilukasz Level 1

                might be a silly question but how do you rename a workPath?

                 

                var worthPath = activeDocument.selection.makeWorkPath();
                 workPath.name = "position1";
                

                 

                doesn't seem to work.

                • 5. Re: convert layer shape to pathItem
                  Michael L Hale Level 5

                  makeWorkPath does not return the path it creates so the variable is undefined.

                   

                  try

                   

                  activeDocument.pathItems.getByName('Work Path').name = 'position1';