Anyone, especially newbies, asking for help with photoshop scripting and photoshop automation - as opposed to those contributing to discussion about an aspect of photoshop scripting
Moderators: Patrick, Mike Hale, xbytor, Larry Ligon, Andrew, PS-Moderators
by vbrajan » Tue Apr 22, 2008 8:49 am
Hi all
I have RGB images with around 25 alpha channels with names not starting with alph....... I want to load these channels one by one and convert the selected area into a new layer with layer names same as channel names.
Later I can convert this layered image to new smaller images using a script avialble with me. Is there any script available to do the first part or anybody can help me out
Rajan
-
vbrajan
-
- Posts: 13
- Joined: Sun Sep 30, 2007 3:48 pm
by rogerdodger » Tue Apr 22, 2008 4:44 pm
first you will need to loop through the channels collection (array of all the channels).
then for each iteration:
- you will make a selection from that channel.
not sure of the method for this. but you could just record an action and call the action from your script.
- then copy the selection
app.activeDocument.selection.copy()
- then make a new layer and paste
app.activeDocument.paste()
- then name the current layer to the name of the current channel
-
rogerdodger
-
- Posts: 57
- Joined: Thu May 17, 2007 8:14 pm
by Mike Hale » Tue Apr 22, 2008 10:11 pm
This is close to rogerdodger's outline
- Code: Select all
var doc = activeDocument;
var lyr = doc.activeLayer;
var cnt = doc.channels.length;
for(var i = 1 ;i < cnt;i++){
if(activeDocument.channels[i].kind != ChannelType.MASKEDAREA) {continue}
doc.selection.load(doc.channels[i]);
executeAction( charIDToTypeID( "CpTL" ), undefined, DialogModes.NO );
doc.activeLayer.name = doc.channels[i].name;
doc.activeLayer = lyr;
}
Mike
-
Mike Hale
- Site Admin
-
- Posts: 2794
- Joined: Fri Sep 30, 2005 10:52 pm
- Location: USA
-
by vbrajan » Wed Apr 23, 2008 6:56 am
Hi Mike
It is working fine, thanks for your support
Rajan
-
vbrajan
-
- Posts: 13
- Joined: Sun Sep 30, 2007 3:48 pm
by Mike Hale » Wed Apr 23, 2008 11:29 pm
In a PM vbrajan asked how to delete the alpha channels after the new layer is created.
- Code: Select all
var doc = activeDocument;
var lyr = doc.activeLayer;
var cnt = doc.channels.length - 1;
for(var i = cnt ;i > 1; i--){
if(activeDocument.channels[i].kind != ChannelType.MASKEDAREA) {continue}
doc.selection.load(doc.channels[i]);
executeAction( charIDToTypeID( "CpTL" ), undefined, DialogModes.NO );
doc.activeLayer.name = doc.channels[i].name;
doc.channels[i].remove();
doc.activeLayer = lyr;
};
-
Mike Hale
- Site Admin
-
- Posts: 2794
- Joined: Fri Sep 30, 2005 10:52 pm
- Location: USA
-
by vbrajan » Thu Apr 24, 2008 3:27 am
Hi all
Mike thanks once again.
I tried with following line in the code. This also working fine.
tifSaveOptions.alphaChannels = false;
Now I am trying to create channels for layers present in the image. Channel names should be layer names. Could you help me on this.
Rajan
-
vbrajan
-
- Posts: 13
- Joined: Sun Sep 30, 2007 3:48 pm
by Mike Hale » Thu Apr 24, 2008 9:43 am
vbrajan wrote:Now I am trying to create channels for layers present in the image. Channel names should be layer names. Could you help me on this.
I am not sure what you are asking. Wouldn't the channels created from layers be the same as the channels used to create the layers? Seems to me that the answer would be not to delete the channels.
Mike
-
Mike Hale
- Site Admin
-
- Posts: 2794
- Joined: Fri Sep 30, 2005 10:52 pm
- Location: USA
-
by vbrajan » Fri Apr 25, 2008 3:45 am
Hi Mike
My new task has no connection with earlier ones.
In this case I have to join smaller image tiles to make a bigger one. Do color correction, then cut it into smaller ones & save with their original name.
For this I am using a script which creates an image with bigger canvas size.
Then opens smaller images, copy paste all of them into the bigger one with image names as layer name. I manually arrange them to their correct position.
Here I need to create channels for each layer, so that, later I can cut this flattend bigger image into smaller ones with correct names.
-
vbrajan
-
- Posts: 13
- Joined: Sun Sep 30, 2007 3:48 pm
by Paul MR » Fri Apr 25, 2008 12:29 pm
I think this should do it.
Paul.
- Code: Select all
doc =activeDocument;
for (var a =0;a<doc.layers.length;a++){
doc.activeLayer = doc.layers[a];
if(!activeDocument.activeLayer.isBackgroundLayer){
var layerName = doc.layers[a].name;
LB = doc.activeLayer.bounds;
var selRegion = Array(
Array(LB[0], LB[1]),
Array(LB[2], LB[1]),
Array(LB[2], LB[3]),
Array(LB[0], LB[3]),
Array(LB[0], LB[1])
);
doc.selection.select(selRegion);
var contentsChannel = doc.channels.add();
contentsChannel.kind = ChannelType.SELECTEDAREA;
contentsChannel.name = layerName;
doc.selection.store(doc.channels[layerName], SelectionType.REPLACE);
selectRGBChannel();
contentsChannel.visible=false;
doc.selection.deselect();
}
}
function selectRGBChannel() {
function cTID(s) { return app.charIDToTypeID(s); };
var desc35 = new ActionDescriptor();
var ref41 = new ActionReference();
ref41.putEnumerated( cTID('Chnl'), cTID('Chnl'), cTID('RGB ') );
desc35.putReference( cTID('null'), ref41 );
executeAction( cTID('slct'), desc35, DialogModes.NO );
}
-
Paul MR
-
- Posts: 724
- Joined: Wed Oct 18, 2006 2:44 pm
- Location: Bradford,UK
by vbrajan » Thu May 01, 2008 11:55 am
Thanks Paul. It is working fine
-
vbrajan
-
- Posts: 13
- Joined: Sun Sep 30, 2007 3:48 pm
by elentiv » Sat Jul 31, 2010 9:35 pm
Hi
The Mike Hale script works really fine, but I would ask if is possible to perform a "copy" of each alpha channel into new layer
The problem is quite the same as vbrajan
I have a document with many alpha channel ( each one with a name that i have assigned) and i need to create for each alpha channel an exact copy on a new layer
The steps i'm looking for are:
select alpha channel ,
perform a select all ( of the alpha channel)
copy (the alpha channel)
and past the channel copy into new layer ( with the same alpha channel name)
and loop the same for the other alpha channel in my document
I hope for an help
elen
-
elentiv
-
- Posts: 9
- Joined: Sat Jul 31, 2010 7:50 pm
by Mike Hale » Sat Jul 31, 2010 9:57 pm
How about this...
- Code: Select all
function copyAlphaToLayer( alphaName ) {
var lyr = app.activeDocument.artLayers.add();
lyr.name = alphaName;
var desc = new ActionDescriptor();
var desc1 = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( charIDToTypeID('Chnl'), alphaName );
desc1.putReference( charIDToTypeID('T '), ref );
desc.putObject( charIDToTypeID('With'), charIDToTypeID('Clcl'), desc1 );
executeAction( charIDToTypeID('AppI'), desc, DialogModes.NO );
return lyr;
};
for( var c = 0; c < app.activeDocument.channels.length;c++ ){
if( app.activeDocument.channels[c].kind == ChannelType.SELECTEDAREA ) {
copyAlphaToLayer( app.activeDocument.channels[c].name );
}
}
-
Mike Hale
- Site Admin
-
- Posts: 2794
- Joined: Fri Sep 30, 2005 10:52 pm
- Location: USA
-
by elentiv » Sat Jul 31, 2010 11:01 pm
Hi Mike
thanks for your replay
I'm newbe
I tried the script but He tell me execution finished but nothing happen
Where I'm wrong?
I notice in the script that it perform an "apply Image " and if it is possible I would prefer a " copy" instead
-
elentiv
-
- Posts: 9
- Joined: Sat Jul 31, 2010 7:50 pm
by elentiv » Sun Aug 01, 2010 12:32 am
I changed channelType.SELECTEDAREA with channelType.MASKEDAREA and it runs perfectly.
I hope that it will be the chance to use a " Copy" command instead of Apply Image
Thank You again
-
elentiv
-
- Posts: 9
- Joined: Sat Jul 31, 2010 7:50 pm
by Mike Hale » Sun Aug 01, 2010 4:33 am
I used Apply Image because it is faster, shorter, and gives better results than going through the clipboard(copy/paste). Using the clipboard almost always changes the gamma of the channel when pasted into a layer.
However here is one way to copy/paste the alpha channels into layers.
- Code: Select all
function copyAlphaToLayer( alphaChannel ){
var lyr = app.activeDocument.artLayers.add();
lyr.name = alphaChannel.name;
var compChannels = app.activeDocument.activeChannels;
app.activeDocument.activeChannels = [ alphaChannel ];
app.activeDocument.selection.selectAll();
app.activeDocument.selection.copy();
app.activeDocument.selection.deselect();
app.activeDocument.activeChannels = compChannels;
app.activeDocument.paste();
}
var doc = activeDocument;
var lyr = doc.activeLayer;
var cnt = doc.channels.length;
for(var i = 1 ;i < cnt;i++){
if(activeDocument.channels[i].kind != ChannelType.MASKEDAREA) {continue}
copyAlphaToLayer( doc.channels[i] );
}
-
Mike Hale
- Site Admin
-
- Posts: 2794
- Joined: Fri Sep 30, 2005 10:52 pm
- Location: USA
-
Return to Help Me
Who is online
Users browsing this forum: No registered users and 1 guest