Manipulate Action Manager Code to return Select and Mask Values?

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

dbell
Posts: 2
Joined: Fri Jan 26, 2018 5:34 pm

Manipulate Action Manager Code to return Select and Mask Values?

Post by dbell »

I am trying to create a function to run Select and Mask that will return the values the user enters (slider values, not the manual brushing). I have done a similar thing with user editing a Solid Color layer where it returns the RGB values the user set. Mike Hale helped with that one a few years back.

I have tried a bunch of ways but I just don't understand AM code well enough to pull it off.

Here is the function of Select and MAsk made from script listener.

function selectAndMask(radius,smooth,feather,contrast,shift){
// =======================================================
var idsmartBrushWorkspace = stringIDToTypeID( "smartBrushWorkspace" );
var desc18 = new ActionDescriptor();
var idsmartBrushRadius = stringIDToTypeID( "smartBrushRadius" );
desc18.putInteger( idsmartBrushRadius, radius );
var idsmartBrushSmooth = stringIDToTypeID( "smartBrushSmooth" );
desc18.putInteger( idsmartBrushSmooth, smooth );
var idsmartBrushFeather = stringIDToTypeID( "smartBrushFeather" );
var idPxl = charIDToTypeID( "#Pxl" );
desc18.putUnitDouble( idsmartBrushFeather, idPxl, feather );
var idsmartBrushContrast = stringIDToTypeID( "smartBrushContrast" );
var idPrc = charIDToTypeID( "#Prc" );
desc18.putUnitDouble( idsmartBrushContrast, idPrc, contrast );
var idsmartBrushShiftEdge = stringIDToTypeID( "smartBrushShiftEdge" );
var idPrc = charIDToTypeID( "#Prc" );
desc18.putUnitDouble( idsmartBrushShiftEdge, idPrc, shift );
var idsampleAllLayers = stringIDToTypeID( "sampleAllLayers" );
desc18.putBoolean( idsampleAllLayers, false );
var idsmartBrushUseSmartRadius = stringIDToTypeID( "smartBrushUseSmartRadius" );
desc18.putBoolean( idsmartBrushUseSmartRadius, false );
var idsmartBrushDecontaminate = stringIDToTypeID( "smartBrushDecontaminate" );
desc18.putBoolean( idsmartBrushDecontaminate, false );
var idsmartBrushDeconAmount = stringIDToTypeID( "smartBrushDeconAmount" );
var idPrc = charIDToTypeID( "#Prc" );
desc18.putUnitDouble( idsmartBrushDeconAmount, idPrc, 100.000000 );
var idrefineEdgeOutput = stringIDToTypeID( "refineEdgeOutput" );
var idrefineEdgeOutput = stringIDToTypeID( "refineEdgeOutput" );
var idselectionOutputToUserMask = stringIDToTypeID( "selectionOutputToUserMask" );
desc18.putEnumerated( idrefineEdgeOutput, idrefineEdgeOutput, idselectionOutputToUserMask );
executeAction( idsmartBrushWorkspace, desc18, DialogModes.ALL );
}


Here is code for updating values for a solid color layer where it returns the RGB values when the user changes them. I am wanting to use this method to return the 5 slider values from the Select an Mask function and possibly the true/false for the smart radius brush as well.

var desc = editSolidColor(128,128,128);

ToDesc=desc.getObjectValue(charIDToTypeID( "T " ));
list=ToDesc.getList(charIDToTypeID( "Clr " ));
levelDesc=list.getObjectValue(0);

var redValue=Math.round(levelDesc.getDouble(charIDToTypeID( "Rd " )));
var greenValue=Math.round(levelDesc.getDouble(charIDToTypeID( "Grn " )));
var blueValue=Math.round(levelDesc.getDouble(charIDToTypeID( "Bl " )));

alert(redValue+','+greenValue+','+blueValue);

function editSolidColor(red,green,blue){
var id30 = charIDToTypeID( "setd" );
var desc7 = new ActionDescriptor();
var id31 = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var id32 = stringIDToTypeID( "contentLayer" );
var id33 = charIDToTypeID( "Ordn" );
var id34 = charIDToTypeID( "Trgt" );
ref2.putEnumerated( id32, id33, id34 );
desc7.putReference( id31, ref2 );
var id35 = charIDToTypeID( "T " );
var desc8 = new ActionDescriptor();
var id36 = charIDToTypeID( "Clr " );
var desc9 = new ActionDescriptor();
var id37 = charIDToTypeID( "Rd " );
desc9.putDouble( id37, red );
var id38 = charIDToTypeID( "Grn " );
desc9.putDouble( id38, green );
var id39 = charIDToTypeID( "Bl " );
desc9.putDouble( id39, blue );
var id40 = charIDToTypeID( "RGBC" );
desc8.putObject( id36, id40, desc9 );
var id41 = stringIDToTypeID( "solidColorLayer" );
desc7.putObject( id35, id41, desc8 );
return userRGB = executeAction( id30, desc7, DialogModes.ALL );
}
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Manipulate Action Manager Code to return Select and Mask Values?

Post by Kukurykus »

Regarding Select and Mask I write script for somewhere in future ;) Currently try this one. It works in C6 EXTENDED with Rafine Edge:

Code: Select all

function sTT(v) {return stringIDToTypeID(v)} p = {0: 'UnitDouble', 1: 'Integer', 2:'Boolean', 3: 'Enumerated'}

arr = [br = 'BorderRadius', fr = 'FeatherRadius', dw = 'DeconWeight', bc = 'BorderContrast',
c = 'Choke', s = 'Smooth', ar = 'AutoRadius', d = 'Decontaminate', o = 'Output'], refEd = 'refineEdge'

function refineSelectionEdge(v1, v2, v3, v4, v5, v6, v7, v8, v9) {
var dsc, rE, arr = [["br), pxl = sTT('pixelsUnit'), v1)", "fr), pxl, v2)",
"dw), prc = sTT('percentUnit'), v3)", "bc), prc, v4)", "c), prc, v5)"],
["s), v6)"], ["ar), v7)", "d), v8)"], ["o), rEO, sTT(rE + o + v9))" ]]

for(I = 0; I < arr.length; I++) for(J = 0; J < arr[I].length; J++) {
eval("(dsc = (dsc ? dsc : new ActionDescriptor())).put" +
p[I] + "(rEO = sTT((rE ? rE : (rE = refEd)) + " + arr[I][J])
}
return executeAction(sTT('refineSelectionEdge'), dsc, DialogModes.ALL)
// v1: (0.0 - 250.0); v2: (0.0 - 1000.0); v3: (0 - 100); v4: (0 - 100); v5: (-100 - 100); v6: (0 - 100); v7: boolean
// v8: boolean; v9: 'Selection', 'UserMask', 'Sheet', 'SheetAndMask', 'Document', 'DocumentAndMask'
}

$.level = 0; try {
activeDocument.selection.bounds, dsc = refineSelectionEdge(25, 2.5, 25, 13, -10, 13, true, true, 'Sheet')

with(dsc) {for(i = arr.length - 1; i >= 0; i--) {if (i == 2 && arr[7].slice(-2) == 'se') {arr[i] += ': '; continue}
arr.splice(i , 1, arr[i] + ': ' + String(eval(((I = i < 8) ? '' : 'typeIDToStringID') + '(get' + (i > 5 && i < 8 ?
p[2] : (i == 5 ? p[1] : (I ? p[0] : 'Enumeration') + 'Value')) + '(sTT(refEd + arr[i])))')).slice(I ? 0 : 16))
}}

alert(arr.join('\n'))
}
catch(err){}
To use it you make selection & run this script. It'll alert all Refine Dialog Inputes. If you rewrite last part of script you can use them for your goal.
Attachments
Refine Edge Inputs.rar
(1.08 KiB) Downloaded 417 times