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

Script for Proofing Template

Explorer ,
Nov 28, 2016 Nov 28, 2016

Copy link to clipboard

Copied

Was wondering if it would be possible to create a Script that would take a Selection or image and re-size it proportionally into an 11"w x 8.5" H document and place it Centered in a 10.5" x 6" box located at the top of the page. If possible if it can detect the size as being less than 10.5" x 6" then don't scale, but if larger scale down to fit Proportionately.... Then Provide a dialog box that would let me enter my job # and today's date in a pre-determined location. I've attached a sample of what I'm trying to accomplish for the finished look. I'm also Assuming the base elements will need to reference a file (or template) that would contain the proofing information if so we'll call it "Proof_Temp.ai"

Huge thanks in advance for anyone that can assist...

Proof Sample.jpg

TOPICS
Scripting

Views

2.9K

Translate

Translate

Report

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
Adobe
Community Expert ,
Nov 28, 2016 Nov 28, 2016

Copy link to clipboard

Copied

Yes. All of that is completely doable. In fact I've done very similar tasks many times.

Do you have any code written that we can help with? We're more than happy to answer questions or help debug your code, but if you want the code written for you, I'd encourage you to hire any of the fantastic professionals around here who donate their time to help everyone learn together. 😃

Votes

Translate

Translate

Report

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
Valorous Hero ,
Nov 28, 2016 Nov 28, 2016

Copy link to clipboard

Copied

Indeed, it would seem like this workflow enhancement would yield monetary savings to whomever utilizes it, and depending on the volume of work, this value could be substantial..

Votes

Translate

Translate

Report

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 ,
Nov 28, 2016 Nov 28, 2016

Copy link to clipboard

Copied

I understand your point.. However, we are a relatively small shop and I was just looking for a way to improve our overall look to customers when proofing... I've seen several large companies use a proof template when sending proofs... Was just hoping there was something that someone had already done that was similar and I could modify to our particular needs...

Votes

Translate

Translate

Report

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 ,
Nov 28, 2016 Nov 28, 2016

Copy link to clipboard

Copied

Understandable. But you would still be using something that a professional created. Like I said. We would all be very glad to help with any issues you have along the way or even show you how to write the processes or connect them all together.. But if you're looking for someone to do it for you, you should reimburse them.

Even if it's a small shop, it sounds like the ROI would be worth it so a compelling case could be made for a small investment. To be clear, I'm not saying that you should pay me to do it. I'm merely saying that everyone here is volunteering to help and it's important to respect the effort someone put into gaining the knowledge necessary to complete the task for you.

But again, I can't stress enough how willing we are to help you along the way if you decide to write the code.

Votes

Translate

Translate

Report

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
Valorous Hero ,
Nov 28, 2016 Nov 28, 2016

Copy link to clipboard

Copied

Then this would be an excellent opportunity to join us and gain amazing scripting knowledge! Due to every different workflow having unique features which require the need for customized, specialized scripts, there isn't a large amount of one-size-fits-all scripts to accomplish these tasks. You already have a first step outlined - that is the mapping of your process, now you need to take all those steps and write down the code requirements. For example for your very first step, you would need to figure out what kind of code will let you grab hold of a selection, and after that what code would create a new document of a particular size, etc.

Votes

Translate

Translate

Report

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 ,
Nov 28, 2016 Nov 28, 2016

Copy link to clipboard

Copied

Silly-V... I would love to gain more knowledge... is there a good location/resource that list the commands available... I'm 100% games for giving it a shot... just haven't found a good resource that tells me how to word the commands appropriately... I know what I need it to do... just missing the actual languages...

Any help or direction is greatly appreciated....

Votes

Translate

Translate

Report

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 ,
Nov 28, 2016 Nov 28, 2016

Copy link to clipboard

Copied

Illustrator Scripting | Adobe Developer Connection

Here you'll find a list of guides that reference specific versions of Illustrator and different languages available (javascript, applescript, and vbscript).

The examples are poor i think. But it will give you a great guide to determine the available objects, properties and methods. If you run into syntax issues or you just don't understand how to get or set some property, just let us know.

If you post a step by step list of what you need to get done, we can help you work through it step by step.

Votes

Translate

Translate

Report

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
Valorous Hero ,
Nov 28, 2016 Nov 28, 2016

Copy link to clipboard

Copied

You have come to the right place!

Here you will find all the PDF documents for the commands:

http://www.adobe.com/devnet/illustrator/scripting.html

We mostly stick to "Javascript" here, as it's cross-platform.

However in addition to the PDF documentation, you will also find a built-in Object Model Viewer help window inside the ExtendScript Tool Kit program to be quite useful.

The ExtendScript ToolKit is what you have to download from here:

JavaScript development toolkit | Download Adobe ExtendScript Toolkit CC

(To access the OMV once inside, go to Help > Object Model Viewer.)

In addition to all this, you will find that they have supplied you with sample scripts that you can study and edit to experiment with.

This is going to be inside the Illustrator's app folder - on Windows this would be inside here:

C:\Program Files\Adobe\Adobe Illustrator CC 2017\Scripting\Sample Scripts

If you are starting out from absolute scratch regarding Javascript, you will find many many YouTube tutorials on the subject, which is both good and not-great, due to the fact that 99.99% of the JS tutorials out there focus on the web browser, Javascript living inside websites. In our purposes, this isn't the case, and past the very basic Javascript features, the web-centric information will be useless. On the same note, javascript for the web is continually developed with more features being added, which makes web JS even more different from Adobe's ExtendScript JS. Adobe's version of JS is from back when JS was at version 3 - so many of the current (version 5) native JS functions aren't even available. That's ok though- learning from the basics is great for getting a foundation in programming.

I personally many years ago used this tutorial to get into the game: https://www.lynda.com/JavaScript-tutorials/JavaScript-Essential-Training/81266-2.html

Votes

Translate

Translate

Report

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 ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

OK.. I've started by taking some elements of another script I found... and I've tried to modify to allow me to start by getting a dialog box that allows me to select what file to open... However I'm getting an error.. This was originally intended for opening a multi-page .pdf and I think I've changed it to select any file type...

Error 21: undefined is not an object.

Line: 18

-> var btnOK = btnGroup.add("button", undefined, "Open");

Thanks for any help... just trying to get step 1 of my project done...

*****************Script Below ***************************

#target illustrator

#targetengine session

// script.name = PROOF Template.jsx;

// script.description = Opens Image and Places on Proof Template;

//----------------------- START UI CODE, create user interface

var win = new Window ("dialog", "Open File for Proof Template");

var fileGroup = win.add("group"); // this is the group on the left, it holds the File button and the Font label note

var btnFile = fileGroup.add("button", undefined, "File..."); // button to select the PDF to open

var grpRight = win.add("group"); // group on the right, to hold everything else

var txtFile = grpRight.add("edittext",undefined);

var btnGroup = grpPanel.add("group");

var btnOk = btnGroup.add("button", undefined, "Open");

var btnCancel = btnGroup.add("button", undefined, "Cancel");

var lblStatus = grpRight.add("statictext",undefined,"Dynagraphics - PROOF Template");

win.orientation = pagesPanel.orientation = "row"; // two items fileGroup and grpRight

win.alignChildren = "right";

fileGroup.orientation = "column";

fileGroup.alignment = "top";

txtFile.alignment = ["fill","top"];

lblStatus.alignment = "left";

grpRight.orientation = "column";

btnGroup.orientation = "column";

btnOk.enabled = false; // disable this button until a valid file is supplied

txtFrom.characters = txtTo.characters = 3;

btnFile.active = true; // receive the first "Enter"

//------------------------ get the file

btnFile.onClick = function(){

  txtFile.text = ""; // clear previous File path if any

  btnOk.enabled = false; // disable the Ok button

  var fileRef = File.openDialog ("Select File...", "*.*"); // get the file

  fileRef = new File(fileRef.fsName.replace("file://",""));

  if(fileRef!= null && fileRef.exists) // check if it is valid file, it should be, unless after clicking a file, the name gets edited

  {

  txtFile.text = fileRef.fsName; // show the file Path here

  btnOk.enabled = true; // enable the Ok button

  txtTo.active = true; // move focus to change the last page to open

  }

}

//------------------------

btnOk.onClick = function(){

  doSomething(); // call main function.

  win.close(); // close when done

}

//------------------------ on leaving this text, check again if file exist, in case file path is typed instead of clicking the File...button

txtFile.onDeactivate = function(){

  //alert("on deactivate")

  var file = File(txtFile.text); // create a file based on the text edit control

  if (file.exists){ // and chekc for existance, if it does

  btnOk.enabled = true; // enable the Ok button

  }

  else { // if it does not exist

  btnOk.enabled = false; // disable the Ok button

  }

}

//------------------------

win.center ();

win.show();

//-------------------------END UI CODE

Votes

Translate

Translate

Report

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
Valorous Hero ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

Don't start editing codes or messing with ScriptUI just yet- if you're  beginner: you can use a simpler File.openDialog() command to open a file or a Folder.selectDialog() to choose a folder.

Votes

Translate

Translate

Report

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 ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

this line right here:

var btnGroup = grpPanel.add("group");

grpPanel is undefined. ergo, btnGroup is going to be undefined because you can't add a group to "undefined". the error message you're getting is saying "grpPanel is not an object".

Votes

Translate

Translate

Report

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 ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

Silly-V

I tried your command... definitely much simpler and to the point... However.. It does bring the dialog up and allows me to select a file... but never actually opens the file....  Sorry to Ask... is there an end of command or something that's missing..

#target illustrator

#targetengine session

// script.name = PROOF Template.jsx;

// script.description = Opens Image and Places on Proof Template;

File.openDialog()

Also Williamadowling... I tried removing that line but obviously prompted further errors... Is there a way to "Define" what's missing?

Thanks to both of you for your help....

Votes

Translate

Translate

Report

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 ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

As Silly-V said, much of this is probably over your head if you're just starting out with all this. I still struggle with ScriptUI from time to time and I've been using it for a while. That said, I'll still answer your questions if you want because the knowledge can't hurt.

File.openDialog() returns a path to the file you selected. It's not an "open" command in terms of opening files, it just opens a dialog. So you have to save the return value of "File.openDialog()" to a variable and then do something with the variable like this:

var theFile = File.openDialog();

app.open(theFile);

Back to your question regarding the ScriptUI and undefined variables..

The script can't tell you what's missing. If it could, there wouldn't really be much need for programmers. Computers can't really infer what you want to happen, It can only tell you when it tries to do something that is missing. but anything that's missing beyond that point won't be known until the script fails at that point. It's up to you to be able to read the code and make sure that the necessary elements are there.

removing that line creates more errors because the subsequent lines attempt to access the variable "btnGroup". So removing the line doesn't fix a problem so much as transfer the problem elsewhere.

a potential fix is to declare a variable called "grpPanel" and give it a value. Another potential fix is to define "btnGroup" as a child of something that already does exist. but the best fix is to start from scratch. that way you're only working with variables you yourself created, and thus it's far easier to know what you have access to.

Editing existing code to work for your needs can be a very difficult thing to do and requires a really solid grasp of how to read the code and figure out exactly what it's doing. Most often, you're better off writing the code from scratch, as it's much easier to understand while you're developing it. You can take it logically from step to step and make sure that you've covered your bases. Start out by giving us a detailed step by step of your process, and then we can break it down into chunks of code.

Votes

Translate

Translate

Report

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 ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

Thanks William... I've attempted the simple version that Silly-V mention... but It's not producing any results....  I've tried looking at other scripts to see if there is a missing end of command line of something I'm missing.. but have yet to gain success.... This is just the simple first step of opening a file...

#target illustrator

#targetengine session

// script.name = PROOF Template.jsx;

// script.description = Opens Image and Places on Proof Template;

File.openDialog()

Votes

Translate

Translate

Report

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 ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

I addressed this question in my last response.

File.openDialog(); does not open a file. It simply returns a path to a file. You need to save the result as a variable and then use another command to open the file. like this:

var theFile = File.openDialog();

app.open(theFile);

it's the second line of that snippet that actually opens the file.

Votes

Translate

Translate

Report

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 ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

Sorry Missed that...

Thanks

Votes

Translate

Translate

Report

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
Valorous Hero ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

Yea - sorry I was on my phone and in the middle of something - I should have mentioned something about how openDialog works. Probably would have helped

Votes

Translate

Translate

Report

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 ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

OK I'm making some progress... but I'm missing something in the option of selecting an item.....

I'm getting an error on the line " var theImg = curr_file.selection.selectAll(); "  What I'm trying to do is select the image that was opened in the first steps... so that I can size the Artboard to the same size... (I currently have a specific file named there, but eventually want to be able to use it for various size files...

Secondly... Can you double check the final section about centering on the artboard...  I can't get that part ran yet because of the selection error... but want to just have you take a look to verify...

Thanks

*****Script Below ********

#target illustrator

#targetengine session

// script.name = PROOF Template.jsx;

// script.description = Opens Image and Places on Proof Template;

// File Open Command for Template

var theFile = File('~/Desktop/Proof Sample.jpg');

app.open(theFile);

//Command to Set Artboard size to File

var docRef = app.activeDocument;

var theImg = curr_file.selection.selectAll();

theImg.left = 0;

theImg.top = 0;

var docSize = [theImg.width,theImg.height];

artboards[0].artboardRect = [0,0,docSize[0],-(docSize[1])];

//Place New Image

doc = app.activeDocument;

var image = File('~/Desktop/shutterstock_319903532.eps');

var doc = app.activeDocument; 

var newimage = doc.placedItems.add(); 

newimage.file = image; 

newimage.position = [0,-792]; 

//Command to Center on Artboard

var aDoc = app.activeDocument; 

app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM; 

var abIdx = aDoc.artboards.getActiveArtboardIndex(); 

var actAbBds = aDoc.artboards[abIdx].artboardRect; 

var obj2move = aDoc.selection[0]; 

obj2move.position = new Array ((actAbBds[2]-actAbBds[0])/2 - obj2move.width/2, (actAbBds[3]-actAbBds[1])/2  + obj2move.height/2);

Votes

Translate

Translate

Report

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
Valorous Hero ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

If you are opening an image and Illustrator makes a new document with just that image inside you can do this:

var theImg = doc.pageItems[0];

Votes

Translate

Translate

Report

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 ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

Ok. There are a couple of issues i can see right off the bat. Number one. See Silly-V's last comment. You don't have to "Select all". In fact, it's better if you avoid things like that because they only work on newer versions of illustrator and thus you risk losing portability.

It's better to use selection by index as he demonstrated with:

theImage = doc.pageItems[0]; //this means take the first page item of "doc" (indexes in JavaScript are zero based, so zero means 1).

so, the problem you're having on the line: var theImg = curr_file.selection.selectAll(); is two fold:

Number one, curr_file is not defined. If you're trying to select the image that you just opened, you need to use "docRef" because that's the variable you just created to represent the activeDocument. now we're back to selecting the first pageItem. so change that line to this:

var theImg = docRef.pageItems[0];

Number two, curr_file.selection.selectAll doesn't work. "selection" is merely an array of selected items. If you just opened a document, there is nothing selected by default. additionally, "selectAll()" is not a method of "selection" because "selection" doesn't have any methods associated with it. Again, this goes back to docRef.pageItems[0]. However, at the risk of confusing the situation, here's how you WOULD use a "selectAll" method (which again, is not recommended if you can avoid it because you lose portability as this functionality only exists in CS6+).

app.open(theFile);

app.executeMenuCommand("selectall");

I'll also take this opportunity to reinforce my point about why it's better to write something from scratch than it is to piece together existing code. In the code you've posted above, you're defining 3 different variables to "app.activeDocument" and trying to utilize a variable (that looks like it's intended to point to app.activeDocument) that doesn't exist.

in the code block labeled "//Command to Set Artboard size to File"

you declare the variable docRef and set it equal to app.activeDocument;

then in the code block labeled "//Place New Image"

you set a global variable "doc" equal to app.activeDocument, then 2 lines later, you declare a new variable called "doc" and set it equal to app.activeDocument;

then in "//Command to Center on Artboard"

you declare a new variable called aDoc and set it equal to app.activeDocument.

Not only does this add unnecessary file size and computing time to your script, it makes it confusing to read and debug. You need only set the activeDocument once at the beginning of your script, then (provided proper scope) you can access it from the rest of the script without having to redefine it over and over.

lastly, i think the center on artboard function at the end is needlessly complex if not unnecessary. At the beginning of your script, you changed the artboard bounds to match the image bounds. The image should already be centered on the artboard because you defined the artboard based on the image bounds.

Sorry, i know that's a lot to digest...

Votes

Translate

Translate

Report

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
Valorous Hero ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

Yea also let's get 'em on the breakpoints bandwagon before we get too far ahead!

Votes

Translate

Translate

Report

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 ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

You explained it a lot better to me than i think i could explain it. fire away, captain!

Votes

Translate

Translate

Report

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 ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

OK.. My apologies... I've tried it after the open dialog then in the sizing section... Can't get it to run... Where should it Put in the code to work correctly... and does anything need to come out...

Thanks

#target illustrator

#targetengine session

// script.name = PROOF Template.jsx;

// script.description = Opens Image and Places on Proof Template;

// File Open Command for Template

var theFile = File('~/Desktop/Proof Sample.jpg');

app.open(theFile);

//Command to Set Artboard size to File

var docRef = app.activeDocument;

var theImg = doc.pageItems[0];

theImg.left = 0;

theImg.top = 0;

var docSize = [theImg.width,theImg.height];

artboards[0].artboardRect = [0,0,docSize[0],-(docSize[1])];

//Place New Image

doc = app.activeDocument;

var image = File('~/Desktop/shutterstock_319903532.eps');

var doc = app.activeDocument; 

var newimage = doc.placedItems.add(); 

newimage.file = image; 

newimage.position = [0,-792]; 

//Command to Center on Artboard

var aDoc = app.activeDocument; 

app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM; 

var abIdx = aDoc.artboards.getActiveArtboardIndex(); 

var actAbBds = aDoc.artboards[abIdx].artboardRect; 

var obj2move = aDoc.selection[0]; 

obj2move.position = new Array ((actAbBds[2]-actAbBds[0])/2 - obj2move.width/2, (actAbBds[3]-actAbBds[1])/2  + obj2move.height/2);

Votes

Translate

Translate

Report

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 ,
Dec 01, 2016 Dec 01, 2016

Copy link to clipboard

Copied

Guys I really do appreciate your help... I'm trying the best I can on a limited budget of time and knowledge... I'm trying to figure this thing out... but still struggling to get this command to go... At this point can you just verify If I have the code placed in the correct place and  it's set to perform the basic task of opening and sizing the artboard to the size of the file it opened...

Thanks

// File Open Command for Template

var theFile = File('~/Desktop/Proof Sample.jpg');

app.open(theFile);

//Command to Set Artboard size to File

app.open(theFile);

var theImg = docRef.pageItems[0];

theImg.left = 0;

theImg.top = 0;

var docSize = [theImg.width,theImg.height];

artboards[0].artboardRect = [0,0,docSize[0],-(docSize[1])];

Votes

Translate

Translate

Report

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