Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Copy text for filename

New Here ,
May 29, 2013 May 29, 2013

I've looked around for this but haven't found much. I have a server with thousands of print proof sheets, and since the beginning, long before me, the files were saved with verbal descriptive names. It would be a lot better if they were saved according to the PO number. All the proof sheets have a po number listed in pretty much the same place on the sheet... is there a way to copy that PO number from the field within the pdf, and save the file to a new folder using that number as the filename using a script?

Thanks in advance.

TOPICS
Scripting
4.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 27, 2013 Jun 27, 2013

Perhaps so:

// Find645_NumberInDoc.jsx

// http://forums.adobe.com/thread/1221811

// regards pixxxelschubser

//var destFolder, sourceFolder, files, fileType, sourceDoc;   // "your" sourceDoc is in the other part always defined as aDoc

var destFolder, sourceFolder, files, fileType;

var aDoc, DocName, aDocPath, aTFrame;

var searchString = /^6\d{6}/;

var searchString2 = /^6\d{6}_/;

var saveOptions = new PDFSaveOptions();

saveOptions.pDFPreset = "ProofCopy";

//sourceFolder = Folder.current;

sourceFolder = Folder

...
Translate
Adobe
Community Expert ,
May 29, 2013 May 29, 2013

if there's something unique in the PO text frame that the script can identify, yes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 29, 2013 May 29, 2013

Unfortunately, none of the text frames are named, but what about if they all begin with the same 2 or 3 digits?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2013 May 29, 2013

Show (or give) us an example, please.

Some questions:

- The documents were created with different versions of Illustrator?

- With which?

- Is the text always text (and not paths)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 29, 2013 May 29, 2013

The documents were made with Illustrator versions going back to CS2. Currently we're using CS6, but most were done with 5 and 4. Text is always text, and it is roughly (but not exactly) in the same place on all documents. Also, the text field is just a PO number, from one of a number of customers we sell to, so if I could pull all the proof sheets with the PO beginning with "345" I would have a folder of all proofs for a single customer, renamed according to PO number, which would be awesome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2013 May 29, 2013

post screen shot of such text frame selected, and showing in the layers palette too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 29, 2013 May 29, 2013

Well I couldn't get the "insert image" function to work, but if you are really interested, I uploaded it here:

http://www.filedropper.com/screenshot_1

Anyway, the field that begins with 645XXXX is the one that I want to use as the filename of all the "saved as" files. While I was fumbling around with the insert image, it looks like pixxxel shubser found something.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2013 May 29, 2013

regardless of this you can try:


// Find345_NumberInDoc.jsx

// http://forums.adobe.com/thread/1221811

// regards pixxxelschubser

var aDoc = app.activeDocument;

var aTFrame = aDoc.textFrames;

var searchString = /^345\d/; //how many digits has your PO-number?

var count = 0;

for (i=aTFrame.length-1; i>=0; i--) {

    contentString = aTFrame.textRange.contents;

    result = contentString.match (searchString);

    if (result) {

    alert (contentString + "_" + aDoc.name);

    count++;

    }

}

if (count == 0) {

    alert ("Nothing found");

    } else {

        if (count > 1) {

            alert ("found too much");

            }

        }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 29, 2013 May 29, 2013

You'll have to forgive me because I'm not a programmer, but I subbed in 645XXXX for 345, and got it to alert the new filename...

Two things: can I lop off everything after the 7th digit (no biggie if not, just curious but I forgot that we put which proof this is on that line, and it's not really useful in the filename) and also, how do I get the script to run on a folder full of these and "save as" them all as "contentString" + ".pdf"?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2013 May 29, 2013

Step by step!

At first you should say, if this "update" works better for you:

// Find645_NumberInDoc.jsx

// http://forums.adobe.com/thread/1221811

// regards pixxxelschubser

var aDoc = app.activeDocument;

var aTFrame = aDoc.textFrames;

//var searchString = /^345\d/; //how many digits has your PO-number?

var searchString = /^645\d{4}/; // update

var count = 0;

for (i=aTFrame.length-1; i>=0; i--) {

    contentString = aTFrame.textRange.contents;

    result = contentString.match (searchString);

    if (result) {

    alert (contentString.slice (0, 7) + "_" + aDoc.name); //update

    count++;

    }

}

if (count == 0) {

    alert ("Nothing found");

    } else {

        if (count > 1) {

            alert ("found too much");

            }

        }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 30, 2013 May 30, 2013

This update returns exactly what I want the filename to be in the alert... so how do we get to the next step?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 30, 2013 May 30, 2013

Did you have tested this "update" with files from different Illustrator versions?

Sometimes (when open an older file in a newer version) the textlines are broken and Regex doesn't find a result. Please test it exactly with more files before the next step is coming.

You always have PDF with PO-number and you will save the new-named PDF in the same folder or in another place? I hope so you won't save directly in network.

By the way – you can mark helpful or correct answers as such, you know?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 30, 2013 May 30, 2013

On the really old files the text needs to be updated from legacy text, but it seems to work fine on all the files created since 2008 or so, which is a lot!

I guess I would rather they save in a different folder, but it doesn't matter so much to me since I can easily move them to a different folder afterwards. This is all on my machine, not the network.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 04, 2013 Jun 04, 2013

Okay, try though I may... I'm still stuck with trying to get the returned filename that is alerted to become the filename for the new file. The best I have been able to do so far is get Illustrator to open a new blank file. Any ideas?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 09, 2013 Jun 09, 2013

It's time for the next step.

// Find645_NumberInDoc.jsx

// http://forums.adobe.com/thread/1221811

// regards pixxxelschubser

var aDoc = app.activeDocument;

var DocName = aDoc.name;

var aDocPath = aDoc.path.fsName;

var aTFrame = aDoc.textFrames;

var searchString = /^645\d{4}/;

var searchString2 = /^645\d{4}_/;

for (i=aTFrame.length-1; i>=0; i--) {

    contentString = aTFrame.textRange.contents;

    result = contentString.match (searchString);

    DocName = DocName.replace (searchString2,'');

    if (result) {

    var SaveName = aDocPath + "/" + result + "_" + DocName;

    i=0;  // find now only the first result!

    }

}

var saveOptions = new IllustratorSaveOptions();

saveOptions.compatibility = Compatibility.ILLUSTRATOR13; // or your version

saveOptions.fontSubsetThreshold = 0.0;

app.activeDocument.saveAs( new File(SaveName), saveOptions );

Ask, if you have questions.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 10, 2013 Jun 10, 2013

Thanks! I didn't want to beg... I'll probably have questions later today.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 10, 2013 Jun 10, 2013

Wow! That worked so beautifully it took me a few seconds to figure out that it had already worked! As I've started looking though the folder of these files, I've noticed that the PO number that I am trying to capture sometimes starts with other digits, but it is always in the same basic location. Is there a way to make the searchString be the numbers in that location on the artboard? I don't want the script to be confused by other number fields that are also in the document.


Even if I have to do a bunch of searches and change the three digit prefix a few dozen times, this is going to be a lifesaver... that is, provided I can do this magic to a whole folder.

Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 14, 2013 Jun 14, 2013

I've come up with a further complication. I'd like these to save as pdf. I played around with the SaveAsPDF script that comes with Illustrator, and tried to combine the best of both worlds, so that it saves the file as "645xxxx_filename.pdf" but am so far unable to get the SaveName to be the the name of the pdf.

Thanks for all your help so far! I had no idea what I was getting into, but I'm learning a lot.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2013 Jun 14, 2013

var SaveName = aDocPath + "/" + result + "_" + DocName;

// add the following line and add the PDF-saveOptions

SaveName = SaveName.replace(/\.ai$/,'.pdf');

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 26, 2013 Jun 26, 2013

I've been away for a while, so of course I had to re-teach myself all the stuff I had only barely learned a couple weeks ago. But it works! I set up a pdf preset with all the settings I need and call it in the pdf save options.

here's what I have so far:

var aDoc = app.activeDocument;

var DocName = aDoc.name;

var aDocPath = aDoc.path.fsName;

var aTFrame = aDoc.textFrames;

var searchString = /^646\d{4}/;

var searchString2 = /^646\d{4}_/;

for (i=aTFrame.length-1; i>=0; i--) {

    contentString = aTFrame.textRange.contents;

    result = contentString.match (searchString);

    DocName = DocName.replace (searchString2,'');

    if (result) {

    var SaveName = aDocPath + "/" + result + "_" + DocName;

        SaveName = SaveName.replace(/\.ai$/,'.pdf');

        i=0;  // find now only the first result!

    }

}

var saveOptions = new PDFSaveOptions();

    saveOptions.pDFPreset = "ProofCopy";

app.activeDocument.saveAs( new File(SaveName), saveOptions );

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 27, 2013 Jun 27, 2013

So I tried to cobble together something to get it to perform this function on the current folder, but it only does one and then stops. I still can't get it to repeat the rename function on other files in the folder. It just does the open document then stops.

This is what I have:

// Find645_NumberInDoc.jsx

// http://forums.adobe.com/thread/1221811

// regards pixxxelschubser

var destFolder, sourceFolder, files, fileType, sourceDoc;

sourceFolder = Folder.current;

if ( sourceFolder != null )

{

    files = new Array();

    fileType = "*.pdf";

    files = sourceFolder.getFiles( fileType );

    if ( files.length > 0 )

    {

        destFolder = sourceFolder;

        for ( f = 0; f < files.length; f++ )

        {

            sourceDoc = app.open(files); // returns the document object

}

}

}

var aDoc = app.activeDocument;

var DocName = aDoc.name;

var aDocPath = aDoc.path.fsName;

var aTFrame = aDoc.textFrames;

var searchString = /^6\d{6}/;

var searchString2 = /^6\d{6}_/;

for (i=aTFrame.length-1; i>=0; i--) {

    contentString = aTFrame.textRange.contents;

    result = contentString.match (searchString);

    DocName = DocName.replace (searchString2,'');

    if (result) {

    var SaveName = aDocPath + "/" + result + "_" + DocName;

        SaveName = SaveName.replace(/\.ai$/,'.pdf');

        i=0;  // find now only the first result!

    }

}

var saveOptions = new PDFSaveOptions();

    saveOptions.pDFPreset = "ProofCopy";

app.activeDocument.saveAs( new File(SaveName), saveOptions );

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 27, 2013 Jun 27, 2013

The replace-part is outside of your file open loop. Only the last file will be changed.

You should bring the part into the loop and add file.close before the next file will be open.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 27, 2013 Jun 27, 2013

Hmmm... not sure which part and where. I've been trying but missing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 27, 2013 Jun 27, 2013

Perhaps so:

// Find645_NumberInDoc.jsx

// http://forums.adobe.com/thread/1221811

// regards pixxxelschubser

//var destFolder, sourceFolder, files, fileType, sourceDoc;   // "your" sourceDoc is in the other part always defined as aDoc

var destFolder, sourceFolder, files, fileType;

var aDoc, DocName, aDocPath, aTFrame;

var searchString = /^6\d{6}/;

var searchString2 = /^6\d{6}_/;

var saveOptions = new PDFSaveOptions();

saveOptions.pDFPreset = "ProofCopy";

//sourceFolder = Folder.current;

sourceFolder = Folder.selectDialog();

if ( sourceFolder != null )

{

    files = new Array();

    fileType = "*.ai";

    files = sourceFolder.getFiles( fileType );

    if ( files.length > 0 )

    {

        destFolder = sourceFolder;

        //for ( f = 0; f < files.length; f++ )

        for ( f = 0; f < 4; f++ )   // --------------- only 4 files for your testing

        {

            aDoc = app.open(files);

           

           

           

            //alert(aDoc + " opened");

            // --------------- now was opened a document

            // --------------- and here should be the rest

            DocName = aDoc.name;

            aDocPath = aDoc.path.fsName;

            aTFrame = aDoc.textFrames;

            for (i=aTFrame.length-1; i>=0; i--) {

                contentString = aTFrame.textRange.contents;

                result = contentString.match (searchString);

                DocName = DocName.replace (searchString2,'');

                if (result) {

                    var SaveName = aDocPath + "/" + result + "_" + DocName;

                    SaveName = SaveName.replace(/\.ai$/,'.pdf');

                    i=0;

                    }

                }

           

            if (result) {

                alert("SaveName: "+SaveName);   // --------------- only for your test

                aDoc.saveAs( new File(SaveName), saveOptions );

                // --------------- now close the active Document and go to the next in the loop

                aDoc.close (SaveOptions.DONOTSAVECHANGES);

                } else {

                    alert ("No match found - document remains open")

                    }

               

               

               

}

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 28, 2013 Jun 28, 2013

I owe you, pixxxel. Do you like beer?

Perfect.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines