Extract part of path) and button Cancel - not work at cancel)

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

klevteev
Posts: 17
Joined: Wed Nov 06, 2019 1:22 pm

Extract part of path) and button Cancel - not work at cancel)

Post by klevteev »

Hello!
1. is it possible to extract part of the text from the file path? 6-digit number
2. Button "ok" - do script / Button "Cancel" - do script too(


1. filePath.slice("ish") ?
Example path to part 6digit-number
\\FS\M\200508\ish\bbb\1card.tif to 200508
\\FS\M\200509\ish\a1.tif to 200509
\\FS\M\200601\ish\bl-prok\print\test.tif to 200601

2. Cancel not work at Cancel.
var dlg = new Window('dialog', 'Parametres:');
dlg.frameLocation = [200, 200];
...
dlg.msgPnl.msgHeight = dlg.msgPnl.add('group');
dlg.msgPnl.selectFolder = dlg.msgPnl.add('group');

with (dlg.msgPnl) { ..... }
var bolUserCancel = false;
dlg.buttons2 = dlg.add('group');

dlg.buttons2.btnClose = dlg.buttons2.add("button", undefined , "Ok" );
dlg.buttons2.btnClose.onClick = function() { this.parent.close(0); };
dlg.buttons2.btnCancel = dlg.buttons2.add("button", undefined , "Cancel" );
dlg.buttons2.btnCancel.onClick = function() { bolUserCancel = false; this.parent.close(0); };
dlg.show();

delete dlg;


and my script:

Code: Select all

var strtRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.MM;
    var docRef = app.activeDocument;
//  filePath = docRef.path;  //
   
    var fileName = docRef.name.slice(".")
var dlg = new Window('dialog', 'Parametres:');
dlg.frameLocation = [200, 200];

dlg.msgPnl = dlg.add('panel', undefined, 'Parametres');
dlg.msgPnl.alignChildren = "right";
dlg.msgPnl.Z = dlg.msgPnl.add('group');
dlg.msgPnl.P = dlg.msgPnl.add('group');
dlg.msgPnl.F = dlg.msgPnl.add('group');

dlg.msgPnl.msgHeight = dlg.msgPnl.add('group');
dlg.msgPnl.selectFolder = dlg.msgPnl.add('group');

with (dlg.msgPnl) {
  Z.st = Z.add('statictext', undefined, 'Number:');
//  Z.et = Z.add('edittext', undefined, '200508');
  Z.et = Z.add('edittext', undefined, filePath); // filePath - Full 
  Z.et.preferredSize = [160,20];

  P.st = P.add('statictext', undefined, ' Position:');
  P.et = P.add('edittext', undefined, '01');
  P.et.preferredSize = [160,20];

  F.st = F.add('statictext', undefined, '  File Name:');
  F.et = F.add('edittext', undefined, fileName);
  F.et.preferredSize = [160,20];

};

var bolUserCancel = false;
dlg.buttons2 = dlg.add('group');

dlg.buttons2.btnClose = dlg.buttons2.add("button", undefined , "Ok" );
dlg.buttons2.btnClose.onClick = function() { this.parent.close(0);  };
dlg.buttons2.btnCancel = dlg.buttons2.add("button", undefined , "Cancel" );
dlg.buttons2.btnCancel.onClick = function() { bolUserCancel = false; this.parent.close(0); };  
dlg.show();

var Z = parseFloat (dlg.msgPnl.Z.et.text);
var P = parseFloat (dlg.msgPnl.P.et.text);
var F = parseFloat (dlg.msgPnl.F.et.text);

delete dlg;

    var W = Math.round(docRef.width);
    var H = Math.round(docRef.height);
      
    function SaveAsTIFF( saveAsName ) {
       var tso = new TiffSaveOptions();
       tso.embedColorProfile = false;
       tso.imageCompression = TIFFEncoding.NONE;
       tso.byteOrder = ByteOrder.IBM;
       docRef.saveAs( File( saveAsName ), tso );
    }

docRef.flatten()
  
SaveAsTIFF ("//FS//M//" + dlg.msgPnl.Z.et.text + "//"+ dlg.msgPnl.P.et.text + "_" + W +"x" + H + "mm_" + dlg.msgPnl.F.et.text );

app.preferences.rulerUnits = strtRulerUnits;
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Extract part of path) and button Cancel - not work at cancel)

Post by Kukurykus »

Change:

Code: Select all

//  filePath = docRef.path;  //
to:

Code: Select all

filePath = docRef.path

Change:

Code: Select all

dlg.buttons2.btnClose.onClick = function() { this.parent.close(0);  };
to:

Code: Select all

dlg.buttons2.btnClose.onClick = function() {this.parent.parent.close(0)}

Change:

Code: Select all

dlg.buttons2.btnCancel.onClick = function() { bolUserCancel = false; this.parent.close(0); };  
to:

Code: Select all

dlg.buttons2.btnCancel.onClick = function() {bolUserCancel = false, this.parent.parent.close(0)}

Change:

Code: Select all

var Z = parseFloat (dlg.msgPnl.Z.et.text);
to:

Code: Select all

dlg.msgPnl.Z.et.text.match(/[^\/\/A-Z]+/i)

Change:

Code: Select all

SaveAsTIFF ("//FS//M//" + dlg.msgPnl.Z.et.text + "//"+ dlg.msgPnl.P.et.text + "_" + W +"x" + H + "mm_" + dlg.msgPnl.F.et.text );
to:

Code: Select all

if (!bolUserCancel) SaveAsTIFF(dlg.msgPnl.Z.et.text + "//"+ dlg.msgPnl.P.et.text + "_" + W +"x" + H + "mm_" + dlg.msgPnl.F.et.text )
klevteev
Posts: 17
Joined: Wed Nov 06, 2019 1:22 pm

Re: Extract part of path) and button Cancel - not work at cancel)

Post by klevteev »

Something's wrong anyway
I've already confused myself

Code: Select all

var strtRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.MM;
    var docRef = app.activeDocument;
  filePath = docRef.path;  
   
    var fileName = docRef.name.slice(".")
var dlg = new Window('dialog', 'Параметры:');
dlg.frameLocation = [200, 200];

dlg.msgPnl = dlg.add('panel', undefined, 'Parametres');
dlg.msgPnl.alignChildren = "right";
dlg.msgPnl.Z = dlg.msgPnl.add('group');
dlg.msgPnl.P = dlg.msgPnl.add('group');
dlg.msgPnl.F = dlg.msgPnl.add('group');

dlg.msgPnl.msgHeight = dlg.msgPnl.add('group');
dlg.msgPnl.selectFolder = dlg.msgPnl.add('group');

with (dlg.msgPnl) {
  Z.st = Z.add('statictext', undefined, 'Номер заказа:');
  Z.et = Z.add('edittext', undefined, '210420');
//  Z.et = Z.add('edittext', undefined, filePath);
  Z.et.preferredSize = [160,20];

  P.st = P.add('statictext', undefined, ' Подпозиция:');
  P.et = P.add('edittext', undefined, '01');
  P.et.preferredSize = [160,20];


  F.st = F.add('statictext', undefined, '  Имя файла:');
  F.et = F.add('edittext', undefined, fileName);
  F.et.preferredSize = [160,20];

};


dlg.buttons2 = dlg.add('group');
var bolUserCancel = false;

dlg.buttons2.btnClose = dlg.buttons2.add("button", undefined , "Ok" );
dlg.buttons2.btnClose.onClick = function() {this.parent.parent.close(0)}
dlg.buttons2.btnCancel = dlg.buttons2.add("button", undefined , "Cancel" );
dlg.buttons2.btnCancel.onClick = function() {bolUserCancel = false, this.parent.parent.close(0)}
dlg.show();

//var Z = parseFloat (dlg.msgPnl.Z.et.text);
dlg.msgPnl.Z.et.text.match(/[^\/\/A-Z]+/i)
var P = parseFloat (dlg.msgPnl.P.et.text);
var F = parseFloat (dlg.msgPnl.F.et.text);

delete dlg;

    var W = Math.round(docRef.width);
    var H = Math.round(docRef.height);
      
    function SaveAsTIFF( saveAsName ) {
       var tso = new TiffSaveOptions();
       tso.embedColorProfile = false;
       tso.imageCompression = TIFFEncoding.NONE;
       tso.byteOrder = ByteOrder.IBM;
       docRef.saveAs( File( saveAsName ), tso );
    }

docRef.flatten()


//    SaveAsTIFF ("//DC//l//001073//" + (dlg.msgPnl.N.et.text + "_" + W +"x" + H + "mm_" + fileName));
//    SaveAsTIFF ("//DC//l//210420//" + (dlg.msgPnl.N.et.text + "_" + fileName));
// SaveAsTIFF ("//DC//l//" + dlg.msgPnl.Z.et.text + "//"+ dlg.msgPnl.P.et.text + "_" + W +"x" + H + "mm_" + dlg.msgPnl.F.et.text );

if (!bolUserCancel) SaveAsTIFF(dlg.msgPnl.Z.et.text + "//"+ dlg.msgPnl.P.et.text + "_" + W +"x" + H + "mm_" + dlg.msgPnl.F.et.text); 

//    SaveAsTIFF ("//DC//l//210420//" + dlg.msgPnl.N.et.text);
//    SaveAsTIFF ("//DC//k//000440//" + (dlg.msgPnl.N.et.text + "_" + fileName));

app.preferences.rulerUnits = strtRulerUnits;
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Extract part of path) and button Cancel - not work at cancel)

Post by Kukurykus »

Change:

Code: Select all

  Z.et = Z.add('edittext', undefined, '210420');
//  Z.et = Z.add('edittext', undefined, filePath);
to:

Code: Select all

//  Z.et = Z.add('edittext', undefined, '200508');
  Z.et = Z.add('edittext', undefined, filePath); // filePath - Full 
klevteev
Posts: 17
Joined: Wed Nov 06, 2019 1:22 pm

Re: Extract part of path) and button Cancel - not work at cancel)

Post by klevteev »

but, FullPath
2020-05-12_13-51-52.png
2020-05-12_13-51-52.png (5.17 KiB) Viewed 5359 times
I need 6 digits only in the first line

p.s.: and Cancel not Cancel ((( Worked at OK))
and now... on the red cross - not closes))) - Work script
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Extract part of path) and button Cancel - not work at cancel)

Post by Kukurykus »

I made mistake, change:

Code: Select all

dlg.buttons2.btnCancel.onClick = function() {bolUserCancel = false, this.parent.parent.close(0)}
to:

Code: Select all

dlg.buttons2.btnCancel.onClick = function() {bolUserCancel = true, this.parent.parent.close(0)}

Change:

Code: Select all

dlg.buttons2.btnCancel = dlg.buttons2.add("button", undefined , "Cancel" );
to:

Code: Select all

dlg.buttons2.btnCancel = dlg.buttons2.add("button", undefined , "Cancel" , {name: 'cancel'});

Change order of:

Code: Select all

dlg.buttons2.btnClose = dlg.buttons2.add("button", undefined , "Ok" );
dlg.buttons2.btnClose.onClick = function() {this.parent.parent.close(0)}
with:

Code: Select all

dlg.buttons2.btnCancel = dlg.buttons2.add("button", undefined , "Cancel" , {name: 'cancel'});
dlg.buttons2.btnCancel.onClick = function() {bolUserCancel = true, this.parent.parent.close(0)}

remove:

Code: Select all

dlg.msgPnl.Z.et.text.match(/[^\/\/A-Z]+/i)

Change:

Code: Select all

  Z.et = Z.add('edittext', undefined, filePath); // filePath - Full 
to:

Code: Select all

  Z.et = Z.add('edittext', undefined, String(filePath).match(/[^\/\/A-Z]+/i)); // filePath - Full 
klevteev
Posts: 17
Joined: Wed Nov 06, 2019 1:22 pm

Re: Extract part of path) and button Cancel - not work at cancel)

Post by klevteev »

Wow! Great Job!
I can imagine how difficult it is to dig into someone else's code)

on "true" changed even before that, and did not work, in the end, and tangled
It remains only Alt+F4 to configure - the script works when closing for now.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Extract part of path) and button Cancel - not work at cancel)

Post by Kukurykus »

Actually use bolUserCancel = true, from cancel part remove bolUserCancel = true, then add to ok part bolUserCancel = false
klevteev
Posts: 17
Joined: Wed Nov 06, 2019 1:22 pm

Re: Extract part of path) and button Cancel - not work at cancel)

Post by klevteev »

ahahaha! how cool) Thank you very much!))
klevteev
Posts: 17
Joined: Wed Nov 06, 2019 1:22 pm

Re: Extract part of path) and button Cancel - not work at cancel)

Post by klevteev »

Hello All!
How can I add information about alpha-channels to this script, in dialog box?
or delete everything except CMYK
2.jpg
2.jpg (12.76 KiB) Viewed 2589 times
1.jpg
1.jpg (16.52 KiB) Viewed 2589 times