Help load files into stack script scale height

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: Tom, Kukurykus

boogotti

Help load files into stack script scale height

Post by boogotti »

Great tested the script it is working, just afew problems,
Is there away for the levels can be baked into the layer (AO layer)as the overlay blending mode will only work if the AO image has the level adjustment flatten in.
This is my mistake should of mentioned it. i have other layers in the document, this script works when i only have the layers mentioned. Is there away that the script can ignore the other layers not being used? Then hide all the layers not being used?

thanks mike we almost getting there
Mike Hale

Help load files into stack script scale height

Post by Mike Hale »

Do the required names ever change? In the sample set you gave me there isn't a file named teapot.VRayReflection.tga

There is one named teapot.VRayRawReflection.tga but the script is not expecting 'Raw' in the middle of the required name and throws an error.
boogotti

Help load files into stack script scale height

Post by boogotti »

ah ok thats my bad i'll redo the files again with VrayLighting, yes passes like VrayRawLighting can be hidden but if you can stick to the template, i'll ' sent you and updated passes files again sortly

There be number of passes but i dont want them to be apart of this just need them to be hidden. basicly anything not named in the layers in the script can be hidden.
As these passes names can change depending on the project. So wouldnt be worth it to add each pass name in the script. Can you do a global like, if it does all the layer blending organizing if there's any layers not named X.VRayLighting, X.VRayGlobalIllumination, X.VRayReflection, x.VRayRefraction, x.VRaySpecular, and X.AO) will be hidden after?

really appreciate the help
Mike Hale

Help load files into stack script scale height

Post by Mike Hale »

I don't think I really need another test set. As long as the document will always have at least these layer name X.VRayLighting, X.VRayGlobalIllumination, X.VRayReflection, x.VRayRefraction, x.VRaySpecular, and X.AO then I think the script below does what you want. It hides any layer with name not in that list. Applies the levels to the AO layer. Orders the layer that match the list. Sets the blendModes and adds the layerSet.
Code: Select allvar doc = app.activeDocument;
var layerNameMap = {};
// find the layer's full names
for(var artLayerIndex =0; artLayerIndex < doc.artLayers.length;artLayerIndex++){
    var matchedName = doc.artLayers[artLayerIndex].name.match(/^.+(\..+)\.+/)[1];
    switch(matchedName){
        case '.VRayLighting': layerNameMap['VRayLighting'] = doc.artLayers[artLayerIndex].name; break;
        case '.VRayGlobalIllumination': layerNameMap['VRayGlobalIllumination'] = doc.artLayers[artLayerIndex].name; break;
        case '.VRayReflection': layerNameMap['VRayReflection'] = doc.artLayers[artLayerIndex].name; break;
        case '.VRayRefraction': layerNameMap['VRayRefraction'] = doc.artLayers[artLayerIndex].name; break;
        case '.VRaySpecular': layerNameMap['VRaySpecular'] = doc.artLayers[artLayerIndex].name; break;
        case '.AO': layerNameMap['AO'] = doc.artLayers[artLayerIndex].name; break;
        default: doc.artLayers[artLayerIndex].visible = false;
    }
}
// now sort layers
doc.artLayers.getByName(layerNameMap['VRayLighting']).move(doc.artLayers[doc.artLayers.length-1], ElementPlacement.PLACEAFTER);
doc.artLayers.getByName(layerNameMap['VRayGlobalIllumination']).move(doc.artLayers[doc.artLayers.length-2], ElementPlacement.PLACEAFTER);
doc.artLayers.getByName(layerNameMap['VRayReflection']).move(doc.artLayers[doc.artLayers.length-3], ElementPlacement.PLACEAFTER);
doc.artLayers.getByName(layerNameMap['VRayRefraction']).move(doc.artLayers[doc.artLayers.length-4], ElementPlacement.PLACEAFTER);
doc.artLayers.getByName(layerNameMap['VRaySpecular']).move(doc.artLayers[doc.artLayers.length-4], ElementPlacement.PLACEAFTER);
doc.artLayers.getByName(layerNameMap['AO']).move(doc.artLayers[doc.artLayers.length-5], ElementPlacement.PLACEAFTER);
// select the top layer
doc.activeLayer = doc.layers[0];
// add a layerSet
var IDLayerSet = doc.layerSets.add();
IDLayerSet.name = 'ID';
makeCurveAdjustmentLayer();
selectLayerBelow();
AOLevels();
doc.activeLayer.blendMode = BlendMode.OVERLAY;
selectLayerBelow();
doc.activeLayer.blendMode = BlendMode.SCREEN;
selectLayerBelow();
doc.activeLayer.blendMode = BlendMode.SCREEN;
selectLayerBelow();
doc.activeLayer.blendMode = BlendMode.SCREEN;
selectLayerBelow();
doc.activeLayer.blendMode = BlendMode.SCREEN;

function makeCurveAdjustmentLayer(){
   var desc = new ActionDescriptor();
   var ref = new ActionReference();
     ref.putClass( charIDToTypeID( "AdjL" ) );
   desc.putReference( charIDToTypeID( "null" ), ref );
   var desc1 = new ActionDescriptor();
     desc1.putClass( charIDToTypeID( "Type" ), charIDToTypeID("Crvs" ) );
   desc.putObject( charIDToTypeID( "Usng" ), charIDToTypeID( "AdjL" ), desc1 );
   executeAction( charIDToTypeID( "Mk  " ), desc, DialogModes.NO );
};
function AOLevels() {
    var desc = new ActionDescriptor();
    desc.putEnumerated( stringIDToTypeID('presetKind'), stringIDToTypeID('presetKindType'), stringIDToTypeID('presetKindCustom') );
        var list = new ActionList();
            var desc1 = new ActionDescriptor();
                var ref = new ActionReference();
                ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Cmps') );
            desc1.putReference( charIDToTypeID('Chnl'), ref );
                var list1 = new ActionList();
                list1.putInteger( 0 );
                list1.putInteger( 128 );
            desc1.putList( charIDToTypeID('Otpt'), list1 );
        list.putObject( charIDToTypeID('LvlA'), desc1 );
    desc.putList( charIDToTypeID('Adjs'), list );
    executeAction( charIDToTypeID('Lvls'), desc, DialogModes.NO );
};
function selectLayerBelow(){
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Bckw" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
    desc.putBoolean( charIDToTypeID( "MkVs" ), false );
    executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};
boogotti

Help load files into stack script scale height

Post by boogotti »

thanks mike i'll give it a test drive
boogotti

Help load files into stack script scale height

Post by boogotti »

mike it work great exactly what im after, just a tiny thing, instead of the AO layer getting the level adjustment, any top layer in the document is getting the level adjustment and blending mode set to overlay. the AO pass is just getting set to blending mode screen. it will be great if the AO pass gets the level adjustment and set to overlay.

almost there ish
Mike Hale

Help load files into stack script scale height

Post by Mike Hale »

There was also another error that effected the layer order. I think this fixes both.
Code: Select allvar doc = app.activeDocument;
var layerNameMap = {};
// find the layer's full names
// document must have layers with these string in the middle of the layer name i.e. teapot.VRayLighting.tga
// case matters as does having two, and only two,  'dot' chars in the name
for(var artLayerIndex =0; artLayerIndex < doc.artLayers.length;artLayerIndex++){
    var matchedName = doc.artLayers[artLayerIndex].name.match(/^.+(\..+)\.+/)[1];
    switch(matchedName){
        case '.VRayLighting': layerNameMap['VRayLighting'] = doc.artLayers[artLayerIndex].name; break;
        case '.VRayGlobalIllumination': layerNameMap['VRayGlobalIllumination'] = doc.artLayers[artLayerIndex].name; break;
        case '.VRayReflection': layerNameMap['VRayReflection'] = doc.artLayers[artLayerIndex].name; break;
        case '.VRayRefraction': layerNameMap['VRayRefraction'] = doc.artLayers[artLayerIndex].name; break;
        case '.VRaySpecular': layerNameMap['VRaySpecular'] = doc.artLayers[artLayerIndex].name; break;
        case '.AO': layerNameMap['AO'] = doc.artLayers[artLayerIndex].name; break;
        default: doc.artLayers[artLayerIndex].visible = false;
    }
}
// now sort layers. if layers with required names are not in document these next lines will throw an error
doc.artLayers.getByName(layerNameMap['VRayLighting']).move(doc.artLayers[doc.artLayers.length-1], ElementPlacement.PLACEAFTER);
doc.artLayers.getByName(layerNameMap['VRayGlobalIllumination']).move(doc.artLayers[doc.artLayers.length-2], ElementPlacement.PLACEAFTER);
doc.artLayers.getByName(layerNameMap['VRayReflection']).move(doc.artLayers[doc.artLayers.length-3], ElementPlacement.PLACEAFTER);
doc.artLayers.getByName(layerNameMap['VRayRefraction']).move(doc.artLayers[doc.artLayers.length-4], ElementPlacement.PLACEAFTER);
doc.artLayers.getByName(layerNameMap['VRaySpecular']).move(doc.artLayers[doc.artLayers.length-5], ElementPlacement.PLACEAFTER);
doc.artLayers.getByName(layerNameMap['AO']).move(doc.artLayers[doc.artLayers.length-6], ElementPlacement.PLACEAFTER);
// select the top layer
doc.activeLayer = doc.artLayers.getByName(layerNameMap['AO']);
// add a layerSet
var IDLayerSet = doc.layerSets.add();
IDLayerSet.name = 'ID';
makeCurveAdjustmentLayer();
selectLayerBelow();
AOLevels();
doc.activeLayer.blendMode = BlendMode.OVERLAY;
selectLayerBelow();
doc.activeLayer.blendMode = BlendMode.SCREEN;
selectLayerBelow();
doc.activeLayer.blendMode = BlendMode.SCREEN;
selectLayerBelow();
doc.activeLayer.blendMode = BlendMode.SCREEN;
selectLayerBelow();
doc.activeLayer.blendMode = BlendMode.SCREEN;

function makeCurveAdjustmentLayer(){
   var desc = new ActionDescriptor();
   var ref = new ActionReference();
     ref.putClass( charIDToTypeID( "AdjL" ) );
   desc.putReference( charIDToTypeID( "null" ), ref );
   var desc1 = new ActionDescriptor();
     desc1.putClass( charIDToTypeID( "Type" ), charIDToTypeID("Crvs" ) );
   desc.putObject( charIDToTypeID( "Usng" ), charIDToTypeID( "AdjL" ), desc1 );
   executeAction( charIDToTypeID( "Mk  " ), desc, DialogModes.NO );
};
function AOLevels() {
    var desc = new ActionDescriptor();
    desc.putEnumerated( stringIDToTypeID('presetKind'), stringIDToTypeID('presetKindType'), stringIDToTypeID('presetKindCustom') );
        var list = new ActionList();
            var desc1 = new ActionDescriptor();
                var ref = new ActionReference();
                ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Cmps') );
            desc1.putReference( charIDToTypeID('Chnl'), ref );
                var list1 = new ActionList();
                list1.putInteger( 0 );
                list1.putInteger( 128 );
            desc1.putList( charIDToTypeID('Otpt'), list1 );
        list.putObject( charIDToTypeID('LvlA'), desc1 );
    desc.putList( charIDToTypeID('Adjs'), list );
    executeAction( charIDToTypeID('Lvls'), desc, DialogModes.NO );
};
function selectLayerBelow(){
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Bckw" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
    desc.putBoolean( charIDToTypeID( "MkVs" ), false );
    executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};
boogotti

Help load files into stack script scale height

Post by boogotti »

Thank You Mike works perfect!!
this will save me so much time!!
Mike Hale

Help load files into stack script scale height

Post by Mike Hale »

Glad it is working for you now and thanks for the intro into a cgi workflow.