Skip to main content
Inspiring
January 28, 2019
Answered

script unfunction

  • January 28, 2019
  • 3 replies
  • 717 views

Hi experts,

my script like this:

var
  cName, mLinks, cLink, matchCount = 0,
  checkLinkName,
  manual = false;
if (cFile.name.match(/\.indb/i))
  manual = true;
  else {
   mLinks = cFile.links.everyItem().getElements();
   while (cLink = mLinks.shift()) {
     cName = cLink.name.match(/[ec]\d{4}_..\.eps/);
     if (!cName || !cName.length) continue;
     cName = cName[0].split(/_..\.eps/)[0];
     matchCount++;
     }
    if(matchCount > 1 || matchCount == 0) manual = true;
    }

if (manual) {
        var
        ourstockcode = mDialog();
        manualStockCode  = String(ourstockcode);
        cName = manualStockCode;
        }

cTime = new Date;
if (!File(cPath.exists))
  Folder(cPath).create();
cName += ".pdf";
return File(cPath + cName);
}

    function mDialog ()
    {
        var
        w = new Window("dialog","Input Stock Code", undefined, {closeButton: false}),
        p = w.add("panel"),
            mLine = p.add("group"),
                mStat1 = mLine.add("statictext", undefined, "Stock code:"),
                mEdit1 = mLine.add("edittext", undefined, ""),
        mB = w.add("group");
       
        mB.add ('button', undefined, "取り消す", {name: "Cancel"});
        mB.add ('button', undefined, "OK", {name: "OK"}); 
       
        mLine.alignChildren = "left";
        mEdit1.characters = 8;
        mB.spacing = 50;

        if (w.show() == 1)
            return Number(mEdit1.text);
        else exit();          
        }

if the link like this :

I suppose the file name will like this:

but it return to:

how can I fix it.

thanks

regard

John

This topic has been closed for replies.
Correct answer Manan Joshi

Replace your while loop i.e. line no 9 to 14 with the following and then try

while (cLink = mLinks.shift()) {

var tmp = cLink.name.match(/[ec]\d{4}_..\.eps/);

if (!tmp || !tmp.length) continue;

cName = tmp[0].split(/_..\.eps/)[0];

matchCount++;

}

-Manan

3 replies

JohnwhiteAuthor
Inspiring
January 28, 2019

so,

thanks so much.

John

JohnwhiteAuthor
Inspiring
January 28, 2019

thank you Manan,

It works

thank so much.

John

Adobe Expert
January 28, 2019

Thats nice to hear, so the issue with your code was that you were using the same variable CName to match the name and also store the final name that was split. So if the file that did not match your pattern was encountered the CName variable was set to null and hence the issue. What i did was use separate variables for both these tasks.

-Manan

Adobe Expert
January 28, 2019

Do one thing remove Setting 1.eps and Setting 2.eps from your InDesign document and then run your script. I suppose this should give correct results. Let me know what happens if it works then i will let you know what is wrong in your code.

-Manan

JohnwhiteAuthor
Inspiring
January 28, 2019

Hi Manan,

If remove the Setting1.eps and Setting 2.eps it will give me correct result.

my goal like:

if doc has link which name. match [ec]\d{4}_[bw4c].eps and the length = 1

the pdf name will like:

e6878.eps

no matter the doc has other links if which name no match [ec]\d{4}_[bw4c].eps

John

Manan JoshiCorrect answer
Adobe Expert
January 28, 2019

Replace your while loop i.e. line no 9 to 14 with the following and then try

while (cLink = mLinks.shift()) {

var tmp = cLink.name.match(/[ec]\d{4}_..\.eps/);

if (!tmp || !tmp.length) continue;

cName = tmp[0].split(/_..\.eps/)[0];

matchCount++;

}

-Manan