3 Replies Latest reply: May 8, 2014 2:12 AM by Atiqur Sumon RSS

    Creating my first Photoshop plugin

    sohail2rahman Community Member

      Hi all,

       

      I am a programmer, I program in PHP, and Obj-C, I know C++ quite fair. I also Design web templates & code them. I need a plugin for photoshop, I searched it but I couldn't find it. So I thought I will try creating it for mysel & if it was nice I will share it too. But unfortunately I don't much help online for creating a very basic photoshop plugin.

       

      By the way, here are my requirments for that plugin:

       

      Most when I create my templates, I group layers e.g Button, Banner, CommentBox etc etc. Now all the related layers are gouped, but if I sometime want to move 2 layers from Buttons, 3 layers from Banner, & 1 layer from CommentBox group, so I select all those layers (Searching for them in my Layer palette ) & move all together. Now I want to move them again I will search for all these layers again across those groups, so I want to save layer selections. e.g I select a few layers across different groups, & save the selection as 'LeftObjects' & similarly select some more layers and save this layer selection as 'RightObjects'. Now whenever I need to select all those left layers together I click the 'LeftObjects' selection & select all the layers for me saving me from searching for those layers.

       

      I would really appreciate if someone could help, or suggest me  a step by step guide to a basic Photoshop plugin. I am a pretty good learner, so I would do it, but I just need a start.

       

      Thank you all

       

      Cheers.

        • 1. Re: Creating my first Photoshop plugin
          MOMIR ZECEVIC Community Member

          Automation plug-in is what you really need. samplecode\automation\automationfilter from SDK examples is good startingpoint. To runn it you also have to compile and install samplecode\filter\hidden filter plugin. For GUI I think your best choice is a panel that will call the plug-in. There are threads here about creating a panel. However I don't think (I am not sure) that you can now what are selected layers (if more than one is selected, maybe someone here know more about that). On the other hand you can  know (one) active layer and put one by one into groups that your plug-in will track.

           

          Regards,

          Momir Zecevic

           

          PS.It would be really cool plugin

          • 2. Re: Creating my first Photoshop plugin
            cbuliarca Community Member

            Actually you can do that with java script and a flex panel, but I don't see why because you can just use the link layers already in Photoshop, the only downside of linking is that you can't define any name for the link layer set.

             

            Anyway if you still want to develop that you can do it with javascript and flex or html5 for CC.

            For the Flash panels (Cs4,Cs5,Cs6) you can find the documentation here: Adobe Photoshop Panel Developer's Guide, as for the html5 panels for CC there are some great tutorials here: http://www.davidebarranca.com/.

             

            Also here are some java script functions to get the selected layers id's and select an array of id's.

             

            function getSelectedLayersIds(){// get the selected layers identifiers

              //( these id's are unique and they will not change if the layer name is changed or it's position in the layers editor will change)

              var idxs = getSelectedLayersIdx();// first get the indexes

              var selectedLayersIds = [];

              //for each index get the layer id

              for( var i=0;i<idxs.length;i++){

              selectedLayersIds.push(getIdfromIdx(idxs[i]));

              }

              return selectedLayersIds;

            }

            function hasBackground(){// function to check if there is a background layer

                var res = undefined;

                try{

                    var ref = new ActionReference();

                    ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID("Nm  "));

                    ref.putIndex( charIDToTypeID("Lyr "), 0 );

                    executeActionGet(ref).getString(charIDToTypeID("Nm  ") );

                    res = true;

                }catch(e){ res = false}

                return res;

            }

            function getIdfromIdx( idx ){// get the id from index

              var ref = new ActionReference();

              ref.putIndex(charIDToTypeID('Lyr '), idx);

                var desc = executeActionGet(ref);

                desc = desc.getInteger(charIDToTypeID("LyrI"));

                return desc;

            }

             

             

            function getSelectedLayersIdx(){// get the selected layers index( positon in layer editor)

                 var selectedLayers = new Array;

                 var ref = new ActionReference();

                 ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

                 var desc = executeActionGet(ref);

                 var add = 1;

                 if(hasBackground()){alert('hBck');add = 0}

                 if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){

                      desc = desc.getList( stringIDToTypeID( 'targetLayers' ));

                      var c = desc.count

                      var selectedLayers = new Array();

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

                           selectedLayers.push(  (desc.getReference( i ).getIndex()) + add);

                      }

                 }else{

                      var ref = new ActionReference();

                      ref.putProperty( charIDToTypeID('Prpr') , charIDToTypeID( 'ItmI' ));

                      ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

                      srs = hasBackground()?executeActionGet(ref).getInteger(charIDToTypeID( 'ItmI' ))-1:executeActionGet(ref).getInteger(charIDToTypeID( 'ItmI' ));

                      selectedLayers.push( srs);

                 }

                 return selectedLayers;

            }

             

             

            function doesIdExists( id ){// function to check if the id exists

              var res = true;

              var ref = new ActionReference();

              ref.putIdentifier(charIDToTypeID('Lyr '), id);

                try{var desc = executeActionGet(ref)}catch(err){res = false};

                return res;

            }

            function multiSelectByIDs(ids) {

              if( ids.constructor != Array ) ids = [ ids ];

                var layers = new Array();

                var id54 = charIDToTypeID( "slct" );

                var desc12 = new ActionDescriptor();

                var id55 = charIDToTypeID( "null" );

                var ref9 = new ActionReference();

                for (var i = 0; i < ids.length; i++) {

                if(doesIdExists(ids[i]) == true){// a check to see if the id stil exists

                     layers[i] = charIDToTypeID( "Lyr " );

                     ref9.putIdentifier(layers[i], ids[i]);

                }

                }

                desc12.putReference( id55, ref9 );

                var id58 = charIDToTypeID( "MkVs" );

                desc12.putBoolean( id58, false );

                executeAction( id54, desc12, DialogModes.NO );

            }

             

             

             

             

            The way I see the panel will be like this:

            first get the selected id's with the "getSelectedLayersIds()"  command , and create a metadata with the name of the set and the array of id's, also add in the panel one button with the name of the new set. I am thinking of the metadata because you can save it with the document and every time you will open the document you can read that data to populate your panel with the already saved sets.

             

            When you want to select back the layers from one set, just click on the button set from the panel, and from the metadata of the document search the name of the set and get the corresponding array of id's, than just use the "multiSelectByIDs( the array)" to select the layers.

             

            That's it I hope I was clear enough.

            • 3. Re: Creating my first Photoshop plugin
              Community Member

              Thank you