Copy link to clipboard
Copied
Does anyone know if the Refine Mask tool can be ran via a script in CC 2017? Refine Mask can still be accessed in CC 2017 from the top menu by using shift + click on the Select and Mask tool under the Selection dropdown. The refine mask will record also in the script listener in CC 2017. The script listener code matches when it is recorded from CC 2015. However, when that script listener code is ran, Photoshop defaults to the Select and Mask and won't run Refine Mask.
There are still a lot if issues with Select and Mask. Select and Mask doesn't give the same results on different computers using the same image and same settings. It also tends to over-erase things. I think the differences between computers may be graphics card driven but I'm not sure. When using Refine Mask in the script in CC 2015 and earlier it is much more repeatable and reliable with no differences between computers. Using the shift+click method to launch Refine Mask in CC 2017 yields the same results as using Refine Mask in CC 2015. If I could just get Refine Mask to run from the script then my life would be a whole lot better.
My gut feeling is it isn't possible but I just have to ask just in case.
Copy link to clipboard
Copied
I would also say that it's not going to be possible. The refine edge mask - I think - using learning algorithms, so as you refine, it detects what you sort of have in mind. There is also, most likely some random seed code in there to mix things up which allows for different results.
Copy link to clipboard
Copied
Actually, Refine Mask works great in my script and I've been using it for many years. I'm not using it for interactively painting. I'm using it to apply the smart radius, shift edge, contrast, etc to already existing masks to clean up the edges automatically.
Select and Mask replaced Refine Mask so my script now uses Select an Mask for CC 2015.5/2017 and uses refine Mask for CS5 - CC 2015. The Refine Mask seems to work better than Select and Mask for my script so I would just like to be able to script CC 2017 to use it. Refine Mask is still available in CC 2017 by shift clicking on Select and Mask in the Select dropdown menu. It brings up the old Refine Mask tool and works just as expected. I just can't get the Refine Mask to run from script in CC 2017. When the script tries to run refine Mask, CC 2017 overrides it and runs the new Select an Mask tool instead.
Copy link to clipboard
Copied
Can you please post a sample code? Besides, are you testing on Mac or Windows?
Thanks!
Davide
Copy link to clipboard
Copied
Here are the function recorded from script listener. I know the refine Mask wors in CS5-CC2015 on both Windows and Mac. The Select and Mask function works on both Windows and Mac for CC2015.5 and CC 2017. For CC 2017, I've only tested the refine mask function on Windows. It uses Select and Mask instead. I just recently found out that CC 2017 still had the old Refine Mask feature hidden but it works. I was hoping it could also run from script.
//selectAndMask(100,10,0.5,20,-20);
refineMask(100,10,0.5,20,-20);
function selectAndMask(radius,smooth,feather,contrast,shift){
// =======================================================
var idsmartBrushWorkspace = stringIDToTypeID( "smartBrushWorkspace" );
var desc125 = new ActionDescriptor();
var idsmartBrushRadius = stringIDToTypeID( "smartBrushRadius" );
desc125.putInteger( idsmartBrushRadius, radius );
var idsmartBrushSmooth = stringIDToTypeID( "smartBrushSmooth" );
desc125.putInteger( idsmartBrushSmooth, smooth );
var idsmartBrushFeather = stringIDToTypeID( "smartBrushFeather" );
var idPxl = charIDToTypeID( "#Pxl" );
desc125.putUnitDouble( idsmartBrushFeather, idPxl, feather );
var idsmartBrushContrast = stringIDToTypeID( "smartBrushContrast" );
var idPrc = charIDToTypeID( "#Prc" );
desc125.putUnitDouble( idsmartBrushContrast, idPrc, contrast );
var idsmartBrushShiftEdge = stringIDToTypeID( "smartBrushShiftEdge" );
var idPrc = charIDToTypeID( "#Prc" );
desc125.putUnitDouble( idsmartBrushShiftEdge, idPrc, shift );
var idsampleAllLayers = stringIDToTypeID( "sampleAllLayers" );
desc125.putBoolean( idsampleAllLayers, false );
var idsmartBrushUseSmartRadius = stringIDToTypeID( "smartBrushUseSmartRadius" );
desc125.putBoolean( idsmartBrushUseSmartRadius, true );
var idsmartBrushDecontaminate = stringIDToTypeID( "smartBrushDecontaminate" );
desc125.putBoolean( idsmartBrushDecontaminate, false );
var idrefineEdgeOutput = stringIDToTypeID( "refineEdgeOutput" );
var idrefineEdgeOutput = stringIDToTypeID( "refineEdgeOutput" );
var idselectionOutputToUserMask = stringIDToTypeID( "selectionOutputToUserMask" );
desc125.putEnumerated( idrefineEdgeOutput, idrefineEdgeOutput, idselectionOutputToUserMask );
executeAction( idsmartBrushWorkspace, desc125, DialogModes.ALL );
}
function refineMask(radius,smooth,feather,contrast,shift){
// =======================================================
var idrefineSelectionEdge = stringIDToTypeID( "refineSelectionEdge" );
var desc12 = new ActionDescriptor();
var idrefineEdgeBorderRadius = stringIDToTypeID( "refineEdgeBorderRadius" );
var idPxl = charIDToTypeID( "#Pxl" );
desc12.putUnitDouble( idrefineEdgeBorderRadius, idPxl, radius );
var idrefineEdgeBorderContrast = stringIDToTypeID( "refineEdgeBorderContrast" );
var idPrc = charIDToTypeID( "#Prc" );
desc12.putUnitDouble( idrefineEdgeBorderContrast, idPrc, contrast );
var idrefineEdgeSmooth = stringIDToTypeID( "refineEdgeSmooth" );
desc12.putInteger( idrefineEdgeSmooth, smooth );
var idrefineEdgeFeatherRadius = stringIDToTypeID( "refineEdgeFeatherRadius" );
var idPxl = charIDToTypeID( "#Pxl" );
desc12.putUnitDouble( idrefineEdgeFeatherRadius, idPxl, feather );
var idrefineEdgeChoke = stringIDToTypeID( "refineEdgeChoke" );
var idPrc = charIDToTypeID( "#Prc" );
desc12.putUnitDouble( idrefineEdgeChoke, idPrc, shift );
var idrefineEdgeAutoRadius = stringIDToTypeID( "refineEdgeAutoRadius" );
desc12.putBoolean( idrefineEdgeAutoRadius, true );
var idrefineEdgeDecontaminate = stringIDToTypeID( "refineEdgeDecontaminate" );
desc12.putBoolean( idrefineEdgeDecontaminate, false );
var idrefineEdgeOutput = stringIDToTypeID( "refineEdgeOutput" );
var idrefineEdgeOutput = stringIDToTypeID( "refineEdgeOutput" );
var idrefineEdgeOutputUserMask = stringIDToTypeID( "refineEdgeOutputUserMask" );
desc12.putEnumerated( idrefineEdgeOutput, idrefineEdgeOutput, idrefineEdgeOutputUserMask );
executeAction( idrefineSelectionEdge, desc12, DialogModes.ALL );
}
Copy link to clipboard
Copied
Hi,
refineMask doesn't work at all for me on CC2015.5 (Mac), nor on CC2017 (Mac), and doesn't seem to default to Select and Mask as you've reported for Windows. Works properly on CC2015, as you said.
I've tried with a recorded ScriptListener code for Refine Mask, and indeed it seems to work (CC2017, Mac) – is that perhaps any different from your own function? I paste it below
var idrefineSelectionEdge = stringIDToTypeID( "refineSelectionEdge" );
var desc23 = new ActionDescriptor();
var idrefineEdgeBorderRadius = stringIDToTypeID( "refineEdgeBorderRadius" );
var idPxl = charIDToTypeID( "#Pxl" );
desc23.putUnitDouble( idrefineEdgeBorderRadius, idPxl, 9.500000 );
var idrefineEdgeBorderContrast = stringIDToTypeID( "refineEdgeBorderContrast" );
var idPrc = charIDToTypeID( "#Prc" );
desc23.putUnitDouble( idrefineEdgeBorderContrast, idPrc, 0.000000 );
var idrefineEdgeSmooth = stringIDToTypeID( "refineEdgeSmooth" );
desc23.putInteger( idrefineEdgeSmooth, 45 );
var idrefineEdgeFeatherRadius = stringIDToTypeID( "refineEdgeFeatherRadius" );
var idPxl = charIDToTypeID( "#Pxl" );
desc23.putUnitDouble( idrefineEdgeFeatherRadius, idPxl, 77.800000 );
var idrefineEdgeChoke = stringIDToTypeID( "refineEdgeChoke" );
var idPrc = charIDToTypeID( "#Prc" );
desc23.putUnitDouble( idrefineEdgeChoke, idPrc, 0.000000 );
var idrefineEdgeAutoRadius = stringIDToTypeID( "refineEdgeAutoRadius" );
desc23.putBoolean( idrefineEdgeAutoRadius, false );
var idrefineEdgeDecontaminate = stringIDToTypeID( "refineEdgeDecontaminate" );
desc23.putBoolean( idrefineEdgeDecontaminate, false );
var idrefineEdgeOutput = stringIDToTypeID( "refineEdgeOutput" );
var idrefineEdgeOutput = stringIDToTypeID( "refineEdgeOutput" );
var idselectionOutputToUserMask = stringIDToTypeID( "selectionOutputToUserMask" );
desc23.putEnumerated( idrefineEdgeOutput, idrefineEdgeOutput, idselectionOutputToUserMask );
executeAction( idrefineSelectionEdge, desc23, DialogModes.NO );
Davide
Copy link to clipboard
Copied
Did you switch to DialogMode.ALL to verify it was using Refine Mask and Not Select and Mask? On my computer with your script, CC 2017 runs Select and Mask, not Refine Mask. When set to DialogMode.ALL, it brings up the Select and Mask UI instead of the Refine Mask UI. With DialogMode.NO, the mask results show Select and Mask was ran, not Refine Mask.
Your script listener code looks the same as what I recorded like. At least on my computer, CC 2017 apperas to override the Refine Mask script and use Select and Mask instead.
Copy link to clipboard
Copied
I'm not really into Refine Mask and similar stuff myself, so I'm wildly guessing: can't it be that the DialogModes.NO runs the older engine, while DialogModes.ALL triggers the newer interface? I've hardwired some pretty extreme values in my ScriptListener example, and they – at least at first sight – looked like the application of Refine Mask. Perhaps you have a better-trained eye to spot the differences...
Copy link to clipboard
Copied
I already thought of that. I ran a test using a given set of values with Select and Mask though the UI, Refine Mask through the UI, the Refine Mask scipt with DialogMode.NO, and the Select and Mask script with DialogMode.NO. I then compared all 4 masks. The 3 masks from the Select and Mask script, Refine Mask script and the Select and Mask through the UI all matched pixel for pixel.The Refine Mask through the UI did not match any of the others. So in my case, the script with DialogMode.NO was for sure using the Select and Mask algorithm and not the Refine Mask algorithm.
Copy link to clipboard
Copied
Hi,
I've asked whether this is an intended behavior or a bug, I'll report you back as soon as I have information to share.
Davide
Copy link to clipboard
Copied
Thanks, I'll be interested to know. I'm leaning towards it being by design.
Copy link to clipboard
Copied