Looking for help with "Open()" command

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

sak1364

Looking for help with "Open()" command

Post by sak1364 »

I'm brand new to writing scripts. I need to have a script in Photoshop that opens an Illustrator (.ai) file. Normally when you do that manually, Photoshop brings up a dialog box called "Import PDF". Once the user selects the file to open, I need the script to set 3 of the parameters in that dialog box.

It looks like I need to use this command but I'm not positive:
Code: Select all     open(File(openDialog()));
That works fine. But it sets those parameters to their default values.

I think I need to set the parameters this way:
Code: Select allvar OpenAIFile = new PDFOpenOptions
    OpenAIFile.antiAlias = false
    OpenAIFile.mode = OpenDocumentMode.CMYK
    OpenAIFile.resolution = 300

But how do I insert these parameters into the Open command? There must be a simple way to do this.
I'm having a hard time trying to figure out Adobe's scripting documentation. I appreciate any help.

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

txuku

Looking for help with "Open()" command

Post by txuku »

Bonjour

Anything like that :
Code: Select all//PDFOpenOptions.jsx
        var OpenAIFile = new PDFOpenOptions;
        OpenAIFile.antiAlias = false;
        OpenAIFile.mode = OpenDocumentMode.CMYK;
        OpenAIFile.resolution = 300;
   
    var myFolder = Folder.selectDialog("select folder");

    if(myFolder != null)
    {
      var fileList = myFolder.getFiles(/\.(pdf)$/i);
      for(var i = 0 ;i < fileList.length; i++)
      {
        if(fileList instanceof File)
        {
          var doc= open(fileList,OpenAIFile);
        }
      }
    };

sak1364

Looking for help with "Open()" command

Post by sak1364 »

Merci beaucoup.

I pasted the code into ExtendScript, but the For loop doesn't execute.
I am trying to understand just what your script does. (As I said I'm very new at writing Java Script.) I understand the the user is asked to select a folder. But does the user ever actually select the file? Or is the script choosing a file from the folder? The second won't work for me. I need to have the user select his/her file and let the script set the open/import parameters so that it can continue to manipulate the file.
txuku

Looking for help with "Open()" command

Post by txuku »

Forgive me!

file .ai did not be file .pdf

This is better :
Code: Select all//PDFOpenOptions.jsx
        var OpenAIFile = new PDFOpenOptions;
        OpenAIFile.antiAlias = false;
        OpenAIFile.mode = OpenDocumentMode.CMYK;
        OpenAIFile.resolution = 300;
   
    var myFolder = Folder.selectDialog("select folder");

    if(myFolder != null)
    {
      var fileList = myFolder.getFiles(/\.(ai)$/i);              //  (pdf)$/i);
      for(var i = 0 ;i < fileList.length; i++)
      {
        if(fileList instanceof File)
        {
          var doc= open(fileList,OpenAIFile);
        }
      }
    };

sak1364

Looking for help with "Open()" command

Post by sak1364 »

txuku, thank you so much for your help. Your solution isn't quite what I needed, because I want the user to specify 1 file. But, I was able to use your solution to figure out how to do it. I knew there had to be a simple solution:

Code: Select all    var OpenAIFile = new PDFOpenOptions;
        OpenAIFile.antiAlias = false;
        OpenAIFile.mode = OpenDocumentMode.CMYK;
        OpenAIFile.resolution = 300;
   
    var SelectedFilePath = File.openDialog("Select the file"); // Prompt user to select the .ai file
    var CurrentFile = open(SelectedFilePath, OpenAIFile); // Open the .ai file and set parameters


Thank you again for your time & help!
txuku

Looking for help with "Open()" command

Post by txuku »


Excuse me

This is a careless mistake on my part ........

you can also specify the type of file line 6:
Code: Select allvar SelectedFilePath = File.openDialog("Select the file ai","ai:*.ai"  );