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

Saving a file to local server with script

Explorer ,
May 22, 2024 May 22, 2024

I have a script that I use for creating flexographic plates from proofs that were sent to the customer. The thing is, the flat proof shows how the print will look, but the plate needs to be slightly condensed in width to compensate for the slight stretch distortion that happens when a flat plate is wrapped around a cylinder. That's the function of the script and it works great.

 

After it runs it resaves the file into the source folder. That was mostly a workaround because I eventually had to stop trying to get it to save to the local server and move on. Once I have created plates for a set of prints, I manually drag all the recently saved files into the server. It's something I just got used to doing that way, but now that things have slowed down I'd like to get this fixed. I'd really like the final step of this script to just be to save the file to the local server, perhaps with the word "_plate" concatenated to the existing file name.
 

 

var myDocument = app.activeDocument;  
var selectedObject = myDocument.selection[0];  
  
//Identify left edge of repeat  
var repeatBounds = app.activeDocument.groupItems['repeat'].geometricBounds;  
var r1 = repeatBounds[0];  
  
// Get position of selection bounds and create condense ratio  
var myBounds = selectedObject.geometricBounds;  
var x1 = myBounds[0];  
var x2 = myBounds[2];
var rawRepeat = (r1 - x1); 
var rawGap = (r1 - x2);
var rawPrintWidth = myBounds[2] - myBounds[0];
var condenseRatio = ((rawRepeat - 21) / rawRepeat) * 100;
var expandRatio = (100/condenseRatio) * 100;

selectedObject.resize(
    condenseRatio, // x
    100.0, // y
    true, // changePositions
    true, // changeFillPatterns
    true, // changeFillGradients
    true, // changeStrokePattern
    true, // changeLineWidths
    Transformation.LEFT); // scaleAbout
    
copy();

selectedObject.resize(
    expandRatio, // x
    100.0, // y
    true, // changePositions
    true, // changeFillPatterns
    true, // changeFillGradients
    true, // changeStrokePattern
    true, // changeLineWidths
    Transformation.LEFT); // scaleAbout

if ( app.documents.length > 0 ) {
myDocument = app.activeDocument;
myDocument.close( SaveOptions.SAVECHANGES );
myDocument = null;
}

 

 

So how do I get these proofs (the myDocument in question) to save to the local G drive server once the script runs? Any help would be greatly appreciated. It's really driving me nuts. Have mercy on me, I'm a graphics guy not a coder. 

TOPICS
How-to , Scripting
574
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

Participant , May 28, 2024 May 28, 2024

if you try to save it asdoc.name+suffix. it will fail to save the file since .pdf_plateno isnt a file type. You will need to do what I wrote in my previous reply about pulling the .pdf part out of the filename, so it becomes Filename+suffix+".pdf"

var fileNameOnly = app.activeDocument.name.substring(0,app.activeDocument.name.lastIndexOf("."))
var newFullName = fileNameOnly+suffix+".pdf"
Translate
Adobe
Participant ,
May 22, 2024 May 22, 2024

you'll have to write out the path location to save it.

for instance say the current file, Test.ai, is on my desktop. the Filepath would look like 

 

/* Mac Scenario */
var myFileLocation = "/Users/USERNAME/Desktop/Test.ai"

 

 if I wanted to save the file in a new location say a cloud storage location. I just need to change where the path is drawing to.

Here is an example use Box as a mounted location

 

/* Mac Scenario */
var myOriginalFile = "/Users/USERNAME/Desktop/Test.ai"
var myNewLocation = new File("Users/USERNAME/Library/CloudStorage/Box-Box/FolderOnBox/Test.ai")
app.activeDocument.saveAs(myNewLocation);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES)

 

I don't do Windows Pathing often, if ever, so not sure the syntax for the file path is the same, but the idea should be the same.

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
Explorer ,
May 22, 2024 May 22, 2024

Thanks RobOctopus,

 

That's similar to some of the things I tried earlier without much success... the thing I don't quite get here is that it seems to have the file name of the file I'd be working on spelled out in the script. How to I get "Test.ai" to be "TheCurrentFileName.pdf" (we only save things as PDF).

 

When I tried using this with the file path changed to another folder on my compuer just to test it, I get an error that "Acrobat PDF is having difficulties. The file may be read-only (nope) or another user may have it open (just me). Please save the document with a different name or in a different folder."

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
Participant ,
May 22, 2024 May 22, 2024

not sure I'm understanding the question, but hopefully this helps

 

app.activeDocument.fullName /* is equal to "~/Desktop/Test.ai" or "/Users/USERNAME/Desktop/Test.ai" */
app.activeDocument.name /* is equal to "Test.ai" */

 

if you wish to remove the .ai, theres a few options, here is one

 

 

var fileNameOnly = app.activeDocument.name.substring(0,app.activeDocument.name.lastIndexOf("."))

 

it will kick back as just "Test"
you can then formulate your new Path location using the string
 

 

var newFileLocation = New File("/Folder/Folder/Folder/"+fileNameOnly+".pdf")
var PDFopts = new PDFSaveOptions();
/* can add any save options here */
app.activeDocument.saveAs(newFileLocation, PDFopts);

 

 

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
Explorer ,
May 22, 2024 May 22, 2024

Well I should say that I do everything as PDFs because we are sending them out to customers to approve, so it's really just saving the file as it already is (a PDF) rather than saving an AI file as PDF. I meant Save As more in the sense of saving to a new location.

 

This does make sense though... I'll have to play around a little while pretending to still get work done, and get back to you. Haha. Thanks again.

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
Explorer ,
May 28, 2024 May 28, 2024

Ok now I'm getting somewhere... I added this to the end of the script and it's almost there:

Everything is working except my attempt to concatenate "_plateno" to the filename saved to the server. The alert tells me that it saved the filename as "file.pdf_plateno" but so far as I can tell it doesn't (and I would think that wouldn't be good anyway.) I want it to save as file_plateno.pdf". 

 

What am I doing wrong?

 

 

if (app.documents.length > 0) {
// Define the destination folder on the server
var serverFolder = "G:\_Emailed Proofs";
var suffix = "_plateno";
var fileName = app.activeDocument.name + suffix;

// Create a new file object with the destination path
var serverFile = new File(serverFolder + "\\" + fileName );

// Save the document as PDF to the server
myDocument.saveAs(serverFile, PDFOpts);

// Display a message to confirm the file was saved
alert("File saved to server: " + serverFile.fsName);

myDocument.close(SaveOptions.DONOTSAVECHANGES);
myDocument = null;
}

 

 

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
Participant ,
May 28, 2024 May 28, 2024

if you try to save it asdoc.name+suffix. it will fail to save the file since .pdf_plateno isnt a file type. You will need to do what I wrote in my previous reply about pulling the .pdf part out of the filename, so it becomes Filename+suffix+".pdf"

var fileNameOnly = app.activeDocument.name.substring(0,app.activeDocument.name.lastIndexOf("."))
var newFullName = fileNameOnly+suffix+".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
Explorer ,
May 28, 2024 May 28, 2024
LATEST

Welp you did tell me that already. And sonofagun, it worked!

 

Thanks for all the help!

 

 

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 22, 2024 May 22, 2024

Are you trying to save the edited/condensed artwork as a file in the exact same folder as the open file just with the "_plate" appended to the name like the example below?

 

G-Drive Server

    > Folder A

    > Folder B

    ˇ Artwork Folder

        • artwork.ai

        • artwork_plate.ai <<<< IS THIS WHAT YOU WANT? >>>>

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
Explorer ,
May 22, 2024 May 22, 2024

Hi jduncan,

 

Not quite. The script runs and copies a condensed version of the customer's artwork to the clipboard, so that I can place it into a file for making a plate. After that it (currently) undoes the condensing (because we really don't want to change the proof) and resaves the file to the original folder. What would be better is that the script runs, and saves a copy of the unchanged proof to the server (with _plate added so that they can later more easily add a plate number to the file name when they assign one. Also this will prevent accidentally saving over old files that might have the same file name. This way all the new files in the server that have _plate at the end are files that I just ordered plates for in the last day or two.

 

So really what I want is the active document to be saved to the G server folder called "_Emailed Proofs" and then the script to run and donotsavechanges (on the folder on my computer). So maybe I was thinking of it backwards. It could save first and then run the script.

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