infrid

Hi,

I purhcased and watched the artist workshop. there was a cool script there for exporing a layer. Can you guys please, please please make it available, or tell us how to do it?
infrid
  • 전체글: 31

Søren

I'll make the script available when I get home tonight :)
사용자 아바타
Søren

Shiu
  • 전체글: 2451

jb.tellez

I'd love to check that out too. Thanks Shiu!
jb.tellez
  • 전체글: 39

infrid

yeah, that'd be awesome..

I'm close - but I can't get it to give me the layer name when I save it.. a lot of alt-tab and F2 going on here :)
infrid
  • 전체글: 31

Søren

Here you go, there are some quirks with it here and there, but it certainly speeds things up.

http://esotericsoftware.com/spine/files/exportPNGwithLayerName.zip
사용자 아바타
Søren

Shiu
  • 전체글: 2451

Nate

What are the quirks? Does the script run quickly?
사용자 아바타
Nate

Nate
  • 전체글: 11932

Søren

As quick as my programming skills allow it to be, it does suffer from having to loop through quite a lot of layers. The main "quirk" is that you can't export multiple layers that are grouped together as a single layer, they will have to merged. I'm sure that a more programmer savvy person could improve it. Maybe a natively written plugin would be the best option, but that's way beyond my skills.

It's still FAR faster than doing it manually though when bound to an action.
사용자 아바타
Søren

Shiu
  • 전체글: 2451

Nate

Unless you are doing actions that are unnecessary, the speed is likely limited by Photoshop. Not sure what you mean by the bold part in "can't export multiple layers that are grouped together as a single layer, they will have to merged". You can have a number of layers in a group, but they are still separate layers. You want them to be merged and exported as a single PNG? Not sure everyone wants that, in which case I guess the script is fine as is. I cleaned up the syntax a little and will put it in the launcher the next time I have to rebuild it.
사용자 아바타
Nate

Nate
  • 전체글: 11932

Søren

Yeah the speed is definitely limited by photoshop, looping through the layers changing visibility is very slow unfortunately. Sometimes you want to export multiple layers a single PNG by adding them to a group, that's what I was talking about :) Then you can use adjustment layers without having to merge first. So if the selected layer is a group exporting the PNG should take that into account, if not it should export as it normally does.
사용자 아바타
Søren

Shiu
  • 전체글: 2451

Nate

But don't you use groups for general organization? How would the script know that some groups should be merged and others traversed and a PNG output for each layer in the group?
사용자 아바타
Nate

Nate
  • 전체글: 11932

ajhager

Shiu, how does your script compare to Photoshop's built in "Export Layers to Files"?
ajhager

Kickstarter Backer
  • 전체글: 6

Søren

I find it to be much faster and it allows you to select a single layer and export it instead of all layers every time. I use a combination of an action where I scale the image to a preferred size and with a layer selected I hit F5 then it writes out the PNG and reverts it back to its original size.
사용자 아바타
Søren

Shiu
  • 전체글: 2451

infrid

I actually had my own action which is much quicker - I duplicate the selected layer, apply mask, copy all, file new, delete the background and save it, closed, doc, delete the original layer.. that's lightning fast. I didn't know about the script recorder, so I didn't know how to do all that with the doc file name : but now I do. I'll post up my resulting script shortly.
infrid
  • 전체글: 31

Søren

Yeah that is a faster way of doing it. One downside to that is if you use adjustment layers which I rely heavily upon. I do have an idea for how to possibly do it faster though. Basically all layers except for the selected one and adjustment layers could be merged into a single layer which could then be hidden. This would be much faster since changing visibility is what takes time.
사용자 아바타
Søren

Shiu
  • 전체글: 2451

infrid

Enclosed is my version of the script.

For those of you who don't have spanish computers, you'll need to change "Fondo" on line 93 to "Background" or whatever it is in your language.

Thanks for the headsup on adjusment layers. I'm gonna make a version of the script whereby you can select all the layers your interested in first , and it will merge them down then do the same thing with that.. that'd be quick too..

Other variations could be all layers in a folder.. I'm not an artist, so I'll just have to keep working up tweaks for my artist as and when she needs them..

Script is in plain text..
========exportLayerWithMask.jsx========
//set the doc and save names

var doc = app.activeDocument;

var Path = app.activeDocument.path;

var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');
var layerName = app.activeDocument.activeLayer.name.replace(/[:\/\\*\?\"\<\>\|]/g, "_");
var saveFile= new File(Path + "
/" + layerName + ".png");

// =======================================================
// create temp layer
var idDplc = charIDToTypeID( "
Dplc" );
var desc30 = new ActionDescriptor();
var idnull = charIDToTypeID( "
null" );
var ref17 = new ActionReference();
var idLyr = charIDToTypeID( "
Lyr " );
var idOrdn = charIDToTypeID( "
Ordn" );
var idTrgt = charIDToTypeID( "
Trgt" );
ref17.putEnumerated( idLyr, idOrdn, idTrgt );
desc30.putReference( idnull, ref17 );
var idNm = charIDToTypeID( "
Nm " );
desc30.putString( idNm, "
""copyTemp""" );
var idVrsn = charIDToTypeID( "
Vrsn" );
desc30.putInteger( idVrsn, 5 );
executeAction( idDplc, desc30, DialogModes.NO );

// =======================================================
// apply mask
var idDlt = charIDToTypeID( "
Dlt " );
var desc31 = new ActionDescriptor();
var idnull = charIDToTypeID( "
null" );
var ref18 = new ActionReference();
var idChnl = charIDToTypeID( "
Chnl" );
var idChnl = charIDToTypeID( "
Chnl" );
var idMsk = charIDToTypeID( "
Msk " );
ref18.putEnumerated( idChnl, idChnl, idMsk );
desc31.putReference( idnull, ref18 );
var idAply = charIDToTypeID( "
Aply" );
desc31.putBoolean( idAply, true );
executeAction( idDlt, desc31, DialogModes.NO );

// =======================================================
//select all
var idsetd = charIDToTypeID( "
setd" );
var desc32 = new ActionDescriptor();
var idnull = charIDToTypeID( "
null" );
var ref19 = new ActionReference();
var idChnl = charIDToTypeID( "
Chnl" );
var idfsel = charIDToTypeID( "
fsel" );
ref19.putProperty( idChnl, idfsel );
desc32.putReference( idnull, ref19 );
var idT = charIDToTypeID( "
T " );
var idOrdn = charIDToTypeID( "
Ordn" );
var idAl = charIDToTypeID( "
Al " );
desc32.putEnumerated( idT, idOrdn, idAl );
executeAction( idsetd, desc32, DialogModes.NO );

// =======================================================
//copy
var idcopy = charIDToTypeID( "
copy" );
executeAction( idcopy, undefined, DialogModes.NO );

// =======================================================
//new document
var idMk = charIDToTypeID( "
Mk " );
var desc33 = new ActionDescriptor();
var idNw = charIDToTypeID( "
Nw " );
var desc34 = new ActionDescriptor();
var idpreset = stringIDToTypeID( "
preset" );
desc34.putString( idpreset, "
""Portapapeles""" );
var idDcmn = charIDToTypeID( "
Dcmn" );
desc33.putObject( idNw, idDcmn, desc34 );
executeAction( idMk, desc33, DialogModes.NO );

// =======================================================
//paste
var idpast = charIDToTypeID( "
past" );
var desc35 = new ActionDescriptor();
var idAntA = charIDToTypeID( "
AntA" );
var idAnnt = charIDToTypeID( "
Annt" );
var idAnno = charIDToTypeID( "
Anno" );
desc35.putEnumerated( idAntA, idAnnt, idAnno );
executeAction( idpast, desc35, DialogModes.NO );

// =======================================================
//select background layer
var idslct = charIDToTypeID( "
slct" );
var desc36 = new ActionDescriptor();
var idnull = charIDToTypeID( "
null" );
var ref20 = new ActionReference();
var idLyr = charIDToTypeID( "
Lyr " );
ref20.putName( idLyr, "
Fondo" );
desc36.putReference( idnull, ref20 );
var idMkVs = charIDToTypeID( "
MkVs" );
desc36.putBoolean( idMkVs, false );
executeAction( idslct, desc36, DialogModes.NO );

// =======================================================
//delete layer
var idDlt = charIDToTypeID( "
Dlt " );
var desc37 = new ActionDescriptor();
var idnull = charIDToTypeID( "
null" );
var ref21 = new ActionReference();
var idLyr = charIDToTypeID( "
Lyr " );
var idOrdn = charIDToTypeID( "
Ordn" );
var idTrgt = charIDToTypeID( "
Trgt" );
ref21.putEnumerated( idLyr, idOrdn, idTrgt );
desc37.putReference( idnull, ref21 );
executeAction( idDlt, desc37, DialogModes.NO );

// =======================================================
//save as
var idsave = charIDToTypeID( "
save" );
var desc38 = new ActionDescriptor();
var idAs = charIDToTypeID( "
As " );
var desc39 = new ActionDescriptor();
var idPGIT = charIDToTypeID( "
PGIT" );
var idPGIT = charIDToTypeID( "
PGIT" );
var idPGIN = charIDToTypeID( "
PGIN" );
desc39.putEnumerated( idPGIT, idPGIT, idPGIN );
var idPNGf = charIDToTypeID( "
PNGf" );
var idPNGf = charIDToTypeID( "
PNGf" );
var idPGAd = charIDToTypeID( "
PGAd" );
desc39.putEnumerated( idPNGf, idPNGf, idPGAd );
var idCmpr = charIDToTypeID( "
Cmpr" );
desc39.putInteger( idCmpr, 9 );
var idPNGF = charIDToTypeID( "
PNGF" );
desc38.putObject( idAs, idPNGF, desc39 );
var idIn = charIDToTypeID( "
In " );
desc38.putPath( idIn, new File( saveFile) );
var idDocI = charIDToTypeID( "
DocI" );
desc38.putInteger( idDocI, 1165 );
var idCpy = charIDToTypeID( "
Cpy " );
desc38.putBoolean( idCpy, true );
var idLwCs = charIDToTypeID( "
LwCs" );
desc38.putBoolean( idLwCs, true );
var idsaveStage = stringIDToTypeID( "
saveStage" );
var idsaveStageType = stringIDToTypeID( "
saveStageType" );
var idsaveBegin = stringIDToTypeID( "
saveBegin" );
desc38.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
executeAction( idsave, desc38, DialogModes.NO );

// =======================================================
var idsave = charIDToTypeID( "
save" );
var desc40 = new ActionDescriptor();
var idAs = charIDToTypeID( "
As " );
var desc41 = new ActionDescriptor();
var idPGIT = charIDToTypeID( "
PGIT" );
var idPGIT = charIDToTypeID( "
PGIT" );
var idPGIN = charIDToTypeID( "
PGIN" );
desc41.putEnumerated( idPGIT, idPGIT, idPGIN );
var idPNGf = charIDToTypeID( "
PNGf" );
var idPNGf = charIDToTypeID( "
PNGf" );
var idPGAd = charIDToTypeID( "
PGAd" );
desc41.putEnumerated( idPNGf, idPNGf, idPGAd );
var idCmpr = charIDToTypeID( "
Cmpr" );
desc41.putInteger( idCmpr, 9 );
var idPNGF = charIDToTypeID( "
PNGF" );
desc40.putObject( idAs, idPNGF, desc41 );
var idIn = charIDToTypeID( "
In " );
desc40.putPath( idIn, new File( saveFile ) );
var idDocI = charIDToTypeID( "
DocI" );
desc40.putInteger( idDocI, 1165 );
var idCpy = charIDToTypeID( "
Cpy " );
desc40.putBoolean( idCpy, true );
var idLwCs = charIDToTypeID( "
LwCs" );
desc40.putBoolean( idLwCs, true );
var idsaveStage = stringIDToTypeID( "
saveStage" );
var idsaveStageType = stringIDToTypeID( "
saveStageType" );
var idsaveSucceeded = stringIDToTypeID( "
saveSucceeded" );
desc40.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
executeAction( idsave, desc40, DialogModes.NO );

// =======================================================
//close document
var idCls = charIDToTypeID( "
Cls " );
var desc42 = new ActionDescriptor();
var idSvng = charIDToTypeID( "
Svng" );
var idYsN = charIDToTypeID( "
YsN " );
var idN = charIDToTypeID( "
N " );
desc42.putEnumerated( idSvng, idYsN, idN );
executeAction( idCls, desc42, DialogModes.NO );

// =======================================================
//dlete temp layer
var idDlt = charIDToTypeID( "
Dlt " );
var desc43 = new ActionDescriptor();
var idnull = charIDToTypeID( "
null" );
var ref22 = new ActionReference();
var idLyr = charIDToTypeID( "
Lyr " );
var idOrdn = charIDToTypeID( "
Ordn" );
var idTrgt = charIDToTypeID( "
Trgt" );
ref22.putEnumerated( idLyr, idOrdn, idTrgt );
desc43.putReference( idnull, ref22 );
executeAction( idDlt, desc43, DialogModes.NO );
=========endofscript========
ps
code is verbose becuase I recorded it... http://blogs.adobe.com/crawlspace/2006/ ... and_1.html
Søren 님에 의해 30 03 2013, 08:57 에 마지막으로 수정되었으며, 1 번 편집하였습니다.
이유: Placed code tags around the script
infrid
  • 전체글: 31

Søren

Remember to disable the recording script again, it will slow down lots of things in photoshop ;) thanks for sharing
사용자 아바타
Søren

Shiu
  • 전체글: 2451

infrid

good call :) thanks.
infrid
  • 전체글: 31


다시 돌아감: Editor