Copy link to clipboard
Copied
What I want to achieve is to randomize selection between 'Smooth', 'Chisel Hard' and 'Chisel Soft' in Bevel & Emboss under 'Structure' section:
desc6.putEnumerated(cTID('bvlT'), cTID('bvlT'), cTID('SfBL'));
So, I guess cTID('SfBL') is to be randomized?
How can I achieve this with an example if possible?
The code:
function functionExample() {
// Set
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Prpr'), cTID('Lefx'));
ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
var desc2 = new ActionDescriptor();
desc2.putUnitDouble(cTID('Scl '), cTID('#Prc'), 416.666666666667);
var desc3 = new ActionDescriptor();
desc3.putBoolean(cTID('enab'), true);
desc3.putBoolean(sTID("present"), true);
desc3.putBoolean(sTID("showInDialog"), true);
desc3.putEnumerated(cTID('Md '), cTID('BlnM'), cTID('Mltp'));
var desc4 = new ActionDescriptor();
desc4.putDouble(cTID('Rd '), 0);
desc4.putDouble(cTID('Grn '), 0);
desc4.putDouble(cTID('Bl '), 0);
desc3.putObject(cTID('Clr '), sTID("RGBColor"), desc4);
desc3.putUnitDouble(cTID('Opct'), cTID('#Prc'), 17);
desc3.putBoolean(cTID('uglg'), false);
desc3.putUnitDouble(cTID('lagl'), cTID('#Ang'), 90);
desc3.putUnitDouble(cTID('Dstn'), cTID('#Pxl'), 1);
desc3.putUnitDouble(cTID('Ckmt'), cTID('#Pxl'), 0);
desc3.putUnitDouble(cTID('blur'), cTID('#Pxl'), 0);
desc3.putUnitDouble(cTID('Nose'), cTID('#Prc'), 0);
desc3.putBoolean(cTID('AntA'), false);
var desc5 = new ActionDescriptor();
desc5.putString(cTID('Nm '), "Linear");
desc3.putObject(cTID('TrnS'), cTID('ShpC'), desc5);
desc3.putBoolean(sTID("layerConceals"), true);
desc2.putObject(cTID('DrSh'), cTID('DrSh'), desc3);
var desc6 = new ActionDescriptor();
desc6.putBoolean(cTID('enab'), true);
desc6.putBoolean(sTID("present"), true);
desc6.putBoolean(sTID("showInDialog"), true);
desc6.putEnumerated(cTID('hglM'), cTID('BlnM'), cTID('Lmns'));
var desc7 = new ActionDescriptor();
desc7.putDouble(cTID('Rd '), 247.000000476837);
desc7.putDouble(cTID('Grn '), 247.000000476837);
desc7.putDouble(cTID('Bl '), 247.000000476837);
desc6.putObject(cTID('hglC'), sTID("RGBColor"), desc7);
desc6.putUnitDouble(cTID('hglO'), cTID('#Prc'), 71);
desc6.putEnumerated(cTID('sdwM'), cTID('BlnM'), cTID('Drkn'));
var desc8 = new ActionDescriptor();
desc8.putDouble(cTID('Rd '), 0);
desc8.putDouble(cTID('Grn '), 0);
desc8.putDouble(cTID('Bl '), 0);
desc6.putObject(cTID('sdwC'), sTID("RGBColor"), desc8);
desc6.putUnitDouble(cTID('sdwO'), cTID('#Prc'), 26);
desc6.putEnumerated(cTID('bvlT'), cTID('bvlT'), cTID('SfBL')); // this is the line to be randomized
desc6.putEnumerated(cTID('bvlS'), cTID('BESl'), cTID('InrB'));
desc6.putBoolean(cTID('uglg'), false);
desc6.putUnitDouble(cTID('lagl'), cTID('#Ang'), 90);
desc6.putUnitDouble(cTID('Lald'), cTID('#Ang'), 30);
desc6.putUnitDouble(cTID('srgR'), cTID('#Prc'), Math.floor((Math.random() * 1000) + 50));
desc6.putUnitDouble(cTID('blur'), cTID('#Pxl'), 1);
desc6.putEnumerated(cTID('bvlD'), cTID('BESs'), cTID('In '));
var desc9 = new ActionDescriptor();
var list1 = new ActionList();
var desc10 = new ActionDescriptor();
desc10.putDouble(cTID('Hrzn'), 0);
desc10.putDouble(cTID('Vrtc'), 0);
list1.putObject(cTID('CrPt'), desc10);
var desc11 = new ActionDescriptor();
desc11.putDouble(cTID('Hrzn'), 59);
desc11.putDouble(cTID('Vrtc'), 22);
list1.putObject(cTID('CrPt'), desc11);
var desc12 = new ActionDescriptor();
desc12.putDouble(cTID('Hrzn'), 109);
desc12.putDouble(cTID('Vrtc'), 47);
list1.putObject(cTID('CrPt'), desc12);
var desc13 = new ActionDescriptor();
desc13.putDouble(cTID('Hrzn'), 152);
desc13.putDouble(cTID('Vrtc'), 128);
list1.putObject(cTID('CrPt'), desc13);
var desc14 = new ActionDescriptor();
desc14.putDouble(cTID('Hrzn'), 193);
desc14.putDouble(cTID('Vrtc'), 218);
list1.putObject(cTID('CrPt'), desc14);
var desc15 = new ActionDescriptor();
desc15.putDouble(cTID('Hrzn'), 255);
desc15.putDouble(cTID('Vrtc'), 255);
list1.putObject(cTID('CrPt'), desc15);
desc9.putList(cTID('Crv '), list1);
desc6.putObject(cTID('TrnS'), cTID('ShpC'), desc9);
desc6.putBoolean(sTID("antialiasGloss"), true);
desc6.putUnitDouble(cTID('Sftn'), cTID('#Pxl'), 0);
desc6.putBoolean(sTID("useShape"), true);
var desc16 = new ActionDescriptor();
desc16.putString(cTID('Nm '), "Pressed 2");
var list2 = new ActionList();
var desc17 = new ActionDescriptor();
desc17.putDouble(cTID('Hrzn'), 0);
desc17.putDouble(cTID('Vrtc'), 0);
list2.putObject(cTID('CrPt'), desc17);
var desc18 = new ActionDescriptor();
desc18.putDouble(cTID('Hrzn'), 42);
desc18.putDouble(cTID('Vrtc'), 71);
list2.putObject(cTID('CrPt'), desc18);
var desc19 = new ActionDescriptor();
desc19.putDouble(cTID('Hrzn'), 66);
desc19.putDouble(cTID('Vrtc'), 122);
list2.putObject(cTID('CrPt'), desc19);
var desc20 = new ActionDescriptor();
desc20.putDouble(cTID('Hrzn'), 140);
desc20.putDouble(cTID('Vrtc'), 139);
list2.putObject(cTID('CrPt'), desc20);
var desc21 = new ActionDescriptor();
desc21.putDouble(cTID('Hrzn'), 174);
desc21.putDouble(cTID('Vrtc'), 192);
list2.putObject(cTID('CrPt'), desc21);
var desc22 = new ActionDescriptor();
desc22.putDouble(cTID('Hrzn'), 220);
desc22.putDouble(cTID('Vrtc'), 140);
list2.putObject(cTID('CrPt'), desc22);
var desc23 = new ActionDescriptor();
desc23.putDouble(cTID('Hrzn'), 255);
desc23.putDouble(cTID('Vrtc'), 0);
list2.putObject(cTID('CrPt'), desc23);
desc16.putList(cTID('Crv '), list2);
desc6.putObject(cTID('MpgS'), cTID('ShpC'), desc16);
desc6.putBoolean(cTID('AntA'), true);
desc6.putUnitDouble(cTID('Inpr'), cTID('#Prc'), 80);
desc6.putBoolean(sTID("useTexture"), false);
desc2.putObject(cTID('ebbl'), cTID('ebbl'), desc6);
desc1.putObject(cTID('T '), cTID('Lefx'), desc2);
executeAction(cTID('setd'), desc1, dialogMode);
};
step1(); // Set
};
Thank you,
teslaball
Basically just put in a switch statement where it calls for that parameter. Then add a variable that gets assigned by a random number, The result is then used in the switch. It looks like two are the same, so something like this inserted in the AM code.
var ranNum = Math.floor(Math.random()*2);
switch (ranNum){
case 0:
desc6.putEnumerated(cTID('bvlT');
break;
case 1:
desc6.putEnumerated(cTID('SfBL')
break;
}
Copy link to clipboard
Copied
Basically just put in a switch statement where it calls for that parameter. Then add a variable that gets assigned by a random number, The result is then used in the switch. It looks like two are the same, so something like this inserted in the AM code.
var ranNum = Math.floor(Math.random()*2);
switch (ranNum){
case 0:
desc6.putEnumerated(cTID('bvlT');
break;
case 1:
desc6.putEnumerated(cTID('SfBL')
break;
}
Copy link to clipboard
Copied
Does it mean I have to put the variable and switch inside the function in the example I provided?
Copy link to clipboard
Copied
You need to put at least the switch. The random statement, you can put outside or inside.
Copy link to clipboard
Copied
Thank you, it works now.