How do I add a progress bar to this code

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

meiyunyou
Posts: 13
Joined: Tue May 26, 2020 9:11 am

How do I add a progress bar to this code

Post by meiyunyou »

Code: Select all

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

function s() {
  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var desc2 = new ActionDescriptor();
    desc2.putString(cTID('Nm  '), "001");
    desc2.putString(sTID("preset"), "A4");
    desc1.putObject(cTID('Nw  '), cTID('Dcmn'), desc2);
    executeAction(sTID('make'), desc1, dialogMode);
  };

  function step2(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('Lyr '), cTID('Bckg'));
    desc1.putReference(cTID('null'), ref1);
    var desc2 = new ActionDescriptor();
    desc2.putUnitDouble(cTID('Opct'), cTID('#Prc'), 100);
    desc2.putEnumerated(cTID('Md  '), cTID('BlnM'), cTID('Nrml'));
    desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
    executeAction(sTID('set'), desc1, dialogMode);
  };

  function step3(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.putEnumerated(cTID('Md  '), cTID('BlnM'), cTID('Nrml'));
    desc3.putUnitDouble(cTID('Opct'), cTID('#Prc'), 100);
    var desc4 = new ActionDescriptor();
    desc4.putString(cTID('Nm  '), "$$$/DefaultGradient/Spectrum=Spectrum");
    desc4.putEnumerated(cTID('GrdF'), cTID('GrdF'), cTID('CstS'));
    desc4.putDouble(cTID('Intr'), 4096);
    var list1 = new ActionList();
    var desc5 = new ActionDescriptor();
    var desc6 = new ActionDescriptor();
    desc6.putDouble(cTID('Rd  '), 255);
    desc6.putDouble(cTID('Grn '), 0);
    desc6.putDouble(cTID('Bl  '), 0);
    desc5.putObject(cTID('Clr '), sTID("RGBColor"), desc6);
    desc5.putEnumerated(cTID('Type'), cTID('Clry'), cTID('UsrS'));
    desc5.putInteger(cTID('Lctn'), 0);
    desc5.putInteger(cTID('Mdpn'), 50);
    list1.putObject(cTID('Clrt'), desc5);
    var desc7 = new ActionDescriptor();
    var desc8 = new ActionDescriptor();
    desc8.putDouble(cTID('Rd  '), 255);
    desc8.putDouble(cTID('Grn '), 0);
    desc8.putDouble(cTID('Bl  '), 255);
    desc7.putObject(cTID('Clr '), sTID("RGBColor"), desc8);
    desc7.putEnumerated(cTID('Type'), cTID('Clry'), cTID('UsrS'));
    desc7.putInteger(cTID('Lctn'), 614);
    desc7.putInteger(cTID('Mdpn'), 50);
    list1.putObject(cTID('Clrt'), desc7);
    var desc9 = new ActionDescriptor();
    var desc10 = new ActionDescriptor();
    desc10.putDouble(cTID('Rd  '), 0);
    desc10.putDouble(cTID('Grn '), 0);
    desc10.putDouble(cTID('Bl  '), 255);
    desc9.putObject(cTID('Clr '), sTID("RGBColor"), desc10);
    desc9.putEnumerated(cTID('Type'), cTID('Clry'), cTID('UsrS'));
    desc9.putInteger(cTID('Lctn'), 1352);
    desc9.putInteger(cTID('Mdpn'), 50);
    list1.putObject(cTID('Clrt'), desc9);
    var desc11 = new ActionDescriptor();
    var desc12 = new ActionDescriptor();
    desc12.putDouble(cTID('Rd  '), 0);
    desc12.putDouble(cTID('Grn '), 255);
    desc12.putDouble(cTID('Bl  '), 255);
    desc11.putObject(cTID('Clr '), sTID("RGBColor"), desc12);
    desc11.putEnumerated(cTID('Type'), cTID('Clry'), cTID('UsrS'));
    desc11.putInteger(cTID('Lctn'), 2007);
    desc11.putInteger(cTID('Mdpn'), 50);
    list1.putObject(cTID('Clrt'), desc11);
    var desc13 = new ActionDescriptor();
    var desc14 = new ActionDescriptor();
    desc14.putDouble(cTID('Rd  '), 0);
    desc14.putDouble(cTID('Grn '), 255);
    desc14.putDouble(cTID('Bl  '), 0);
    desc13.putObject(cTID('Clr '), sTID("RGBColor"), desc14);
    desc13.putEnumerated(cTID('Type'), cTID('Clry'), cTID('UsrS'));
    desc13.putInteger(cTID('Lctn'), 2744);
    desc13.putInteger(cTID('Mdpn'), 50);
    list1.putObject(cTID('Clrt'), desc13);
    var desc15 = new ActionDescriptor();
    var desc16 = new ActionDescriptor();
    desc16.putDouble(cTID('Rd  '), 255);
    desc16.putDouble(cTID('Grn '), 255);
    desc16.putDouble(cTID('Bl  '), 0);
    desc15.putObject(cTID('Clr '), sTID("RGBColor"), desc16);
    desc15.putEnumerated(cTID('Type'), cTID('Clry'), cTID('UsrS'));
    desc15.putInteger(cTID('Lctn'), 3441);
    desc15.putInteger(cTID('Mdpn'), 50);
    list1.putObject(cTID('Clrt'), desc15);
    var desc17 = new ActionDescriptor();
    var desc18 = new ActionDescriptor();
    desc18.putDouble(cTID('Rd  '), 255);
    desc18.putDouble(cTID('Grn '), 0);
    desc18.putDouble(cTID('Bl  '), 0);
    desc17.putObject(cTID('Clr '), sTID("RGBColor"), desc18);
    desc17.putEnumerated(cTID('Type'), cTID('Clry'), cTID('UsrS'));
    desc17.putInteger(cTID('Lctn'), 4096);
    desc17.putInteger(cTID('Mdpn'), 50);
    list1.putObject(cTID('Clrt'), desc17);
    desc4.putList(cTID('Clrs'), list1);
    var list2 = new ActionList();
    var desc19 = new ActionDescriptor();
    desc19.putUnitDouble(cTID('Opct'), cTID('#Prc'), 100);
    desc19.putInteger(cTID('Lctn'), 0);
    desc19.putInteger(cTID('Mdpn'), 50);
    list2.putObject(cTID('TrnS'), desc19);
    var desc20 = new ActionDescriptor();
    desc20.putUnitDouble(cTID('Opct'), cTID('#Prc'), 100);
    desc20.putInteger(cTID('Lctn'), 4096);
    desc20.putInteger(cTID('Mdpn'), 50);
    list2.putObject(cTID('TrnS'), desc20);
    desc4.putList(cTID('Trns'), list2);
    desc3.putObject(cTID('Grad'), cTID('Grdn'), desc4);
    desc3.putUnitDouble(cTID('Angl'), cTID('#Ang'), 90);
    desc3.putEnumerated(cTID('Type'), cTID('GrdT'), cTID('Rdl '));
    desc3.putBoolean(cTID('Rvrs'), false);
    desc3.putBoolean(cTID('Dthr'), false);
    desc3.putBoolean(cTID('Algn'), true);
    desc3.putUnitDouble(cTID('Scl '), cTID('#Prc'), 113);
    var desc21 = new ActionDescriptor();
    desc21.putUnitDouble(cTID('Hrzn'), cTID('#Prc'), 0);
    desc21.putUnitDouble(cTID('Vrtc'), cTID('#Prc'), 0);
    desc3.putObject(cTID('Ofst'), cTID('Pnt '), desc21);
    desc2.putObject(cTID('GrFl'), cTID('GrFl'), desc3);
    desc1.putObject(cTID('T   '), cTID('Lefx'), desc2);
    executeAction(sTID('set'), desc1, dialogMode);
  };

  function step4(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    desc1.putEnumerated(cTID('What'), sTID("rasterizeItem"), sTID("layerStyle"));
    executeAction(sTID('rasterizeLayer'), desc1, dialogMode);
  };

  function step5(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    desc1.putEnumerated(cTID('Cnvr'), cTID('Cnvr'), cTID('PlrR'));
    executeAction(sTID('polar'), desc1, dialogMode);
  };

  function step6(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    desc1.putInteger(cTID('Angl'), 570);
    executeAction(sTID('twirl'), desc1, dialogMode);
  };

  function step7(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    desc1.putEnumerated(sTID("presetKind"), sTID("presetKindType"), sTID("presetKindCustom"));
    desc1.putBoolean(cTID('Clrz'), false);
    var list1 = new ActionList();
    var desc2 = new ActionDescriptor();
    desc2.putInteger(cTID('H   '), 111);
    desc2.putInteger(cTID('Strt'), 0);
    desc2.putInteger(cTID('Lght'), 0);
    list1.putObject(cTID('Hst2'), desc2);
    desc1.putList(cTID('Adjs'), list1);
    executeAction(sTID('hueSaturation'), desc1, dialogMode);
  };

  step1();     
  step2();     
  step3();      
  step4();      
  step5();     
  step6();    
  step7();     
};

s.main = function () {
  s();
};

s.main();
How do I add a progress bar to this code

Although I know the code looks like this

But I don't know how to add it

Code: Select all

var array = new Array (5);
var window = new Window("palette", "title");
window.progressBar = window.add ('progressbar', undefined, 0, array.length);
window.progressBar.preferredSize.width = 300;
window.show();
for (var i = 0; i < array.length; i++)
{
	window.progressBar.value = i+1;
	app.refresh();
}
Ask for help,Thank you for your attention

User avatar
Kukurykus
Posts: 301
Joined: Mon Jul 25, 2016 12:36 pm

Re: How do I add a progress bar to this code

Post by Kukurykus »

I don't see the need to add progress bar to be updated after each step of your code. It works very fast, around one second.

meiyunyou
Posts: 13
Joined: Tue May 26, 2020 9:11 am

Re: How do I add a progress bar to this code

Post by meiyunyou »

Kukurykus wrote:
Thu Jun 11, 2020 1:39 pm
I don't see the need to add progress bar to be updated after each step of your code. It works very fast, around one second.
Just give a demonstration,As long as a demonstration

Thank you very much