-
1. Re: Creating my first Photoshop plugin
MOMIR ZECEVIC Jan 20, 2014 4:34 PM (in response to sohail2rahman)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 May 8, 2014 1:27 AM (in response to sohail2rahman)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
Atiqur Sumon May 8, 2014 2:12 AM (in response to cbuliarca)Thank you cbuliarca for your answer.

