//Created by Daryl R. Smith //This is the tab for Totes #target illustrator var thisDoc = app.activeDocument; if (thisDoc.selection.length > 0) { var w = new Window ("dialog", "Choose Totes Template", undefined, {closeButton: false}); w.alignChildren = "right"; w.onShow = function() { for(var i=0; i<totes1.children.length; i++) { var thisPanel2 = totes1.children[i]; thisPanel2.originalLocation = [thisPanel2.location[0], thisPanel2.location[1]]; }//end for }//end on show function var tpanel = w.add ("tabbedpanel"); tpanel.size = [400, 520]; //********************************************************************************************************************************************************** //******************************************************Section to setup the Totes Tab****************************************************************** //********************************************************************************************************************************************************** //creates the Totes Tab var totesTab = tpanel.add ("tab", undefined, "Available Totes"); totesTab.orientation = "column"; //Creates first Row Group for Totes, contains panels 1,2 and 3 var TotesGroup = totesTab.add("group",undefined); TotesGroup.orientation = "row"; TotesGroup.alignChildren = "left"; //first Totes Panel var totes1 = TotesGroup.add ("panel", undefined, ""); totes1.alignChildren = "left"; totes1.size = [300,480]; var docSelection = app.activeDocument.selection; var newGroup = app.activeDocument.groupItems.add(); for ( i = 0; i < docSelection.length; i++ ) { var newItem = docSelection[i] (); newItem.moveToEnd( newGroup ); } alert (thisDoc.selection.length) GetToteTempNames() function GetToteTempNames() { //Replace this address for the "toteTempPath" to the folder that has all the templates it in it, then the for loop will place them all //into a radio button array for the user to choose which one they want. This updates everytime that this script is ran so if //one if removed or added it will show up reducing the amount of required time needed to update the script. //when replaced make sure to change the \ marks to / marks or it will not work. var toteTempPath = Folder ("Z:/ Vitronic Master Templates/STE2 Templates/TOTES & BAGS"); var toteTempFiles = toteTempPath.getFiles(); var TotenamesArr = []; for(var i=0; i<toteTempFiles.length; i++){ var thisToteFile = toteTempFiles[i]; TotenamesArr.push(thisToteFile.displayName); } return TotenamesArr; } var totesarr1 = GetToteTempNames(); for(var i=0; i<totesarr1.length; i++){ var lbl = totes1.add("radiobutton", undefined, totesarr1[i]); } var scrl = TotesGroup.add('scrollbar'); scrl.size = [20, 480]; scrl.onChange = scrl.onChanging = function() { //start function for(var i=0; i<totes1.children.length; i++) { //start for var thisPanel2 = totes1.children[i]; var xLoc = thisPanel2.originalLocation[0]; var yLoc = thisPanel2.originalLocation[1]; thisPanel2.location=[xLoc, yLoc-((this.value/100) * ((totes1.children.length*27.5) - (scrl.size[1]+5)))]; // These numbers are my arbitrary way of setting the y location }//end for loop }//end function totes1.children[0].value = true; var bottombuttons = w.add ("group"); bottombuttons.orientation = "row" var rsize = bottombuttons.add ("panel", undefined, "Resize Artwork?"); rsize.alignChildren = "left" rsize.orientation = "column" rsizeyes = rsize.add ("radiobutton", undefined, "Yes"); rsizeno = rsize.add ("radiobutton", undefined, "No"); rsize.children[1].value = true; var kbottombuttons = bottombuttons.add ("group", undefined, "") kbottombuttons.orientation = "column" kbottombuttons.add ("button", undefined, "Ok"); //********************************************************************************************************************************************************** //********************This section is for the functions to output your choice then run the function depending on the choice you made**************** //********************************************************************************************************************************************************** if (w.show () == 1) { var templateselected = selected_rbutton var requestedtemplate = selected_rbutton (totalgroups) var confirmed = confirm ("You picked [ " + selected_rbutton (totalgroups) +" ]"+ "\nYou picked [ " + questionResize (rsizechoice) + " ] to resize" + "\n" +"\nContinue?"); confirm.noAsDflt == false; if (confirmed == true) { copy(); openTemp (); paste(); centerArt (); resizeart (); savefile () //need to wait for the save script to finish before it does the put name so that if the user changes the file name from the save pallet it will be reflected //in the putname function. wait = savefile(); while(!wait) { //wait = false; // this is just killing time // so is this a++; if (a>1000) break; // guard against infinite loop } //end wait putname (); } /*end if */ else { alert ("You chose not to continue, script stopped") }//end else }//end if OK //********************************************************************************************************************************************************** //*********This section is for the function to check which option for resize gets pressed and returns the text to a variable for output****************** //********************************************************************************************************************************************************** var rsizechoice = [rsize] function questionResize (rsizechoice) {//start function //when choice is pressed return choice text for variable output for (var i = 0; i < rsize.children.length; i++) { if (rsize.children[i].value == true) return rsize.children[i].text; }//end for }//end function QuestionResize //********************************************************************************************************************************************************** //***************************************************************This is the section that will center the artwork ****************************************** //********************************************************************************************************************************************************** var thisDoc = app.activeDocument; thisDoc.rulerOrigin = [0,0]; // Sets the coordinates of the artboard to the lower left hand corner of the document. thisDoc.pageOrigin = [0,0]; // This makes sure a valid reference point is used for different sized documents. function centerArt() { var thisdoc = app.activeDocument; var selecteditem = app.activeDocument.selection; var hasDocCoords = app.coordinateSystem == CoordinateSystem.ARTBOARDCOORDINATESYSTEM; var p = thisdoc.pageItems; for (var i = 0, l = p.length; i < l; i++) { var pID = p[i]; if (pID.guides == true) { var guideBox = pID } } var wNum = guideBox.width; var hNum = guideBox.height; var swNum = selecteditem.width; var shNum = selecteditem.height; var sxOffset = (swNum/2); var syOffset = (shNum/2); var xOffset = (wNum/2); var yOffset = (hNum/2); var xNum = guideBox.position[0]+xOffset; var yNum = guideBox.position[1]-yOffset; var guideXCenter = xNum-sxOffset; var guideYCenter = yNum+syOffset; var sxNum = selecteditem.position[0]+sxOffset; var syNum = selecteditem.position[1]-syOffset; //to test your script for position un annotate the two alerts below alert("GuideBox Data:\nWidth: "+wNum+"\nHeight: "+hNum+"\nX Position: "+xNum+"\nY Position: "+yNum); alert ("Selected object Data:\nWidth: "+swNum+"\nHeight: "+shNum+"\nX Position: "+sxNum+"\nY Position: "+syNum); //changes the position of the selected artwork to the center of the guide box. app.activeDocument.selection[0].position = [guideXCenter, guideYCenter] }//end centerart function resizeart() { if (questionResize (rsizechoice) == "Yes") { for (var i = 0; i < app.activeDocument.pageItems.length; i++) { if (app.activeDocument.pageItems[i].guides == true) { var guideBoxSize = app.activeDocument.pageItems[i]; } //end if } //end for var guideW = guideBoxSize.width; var guideH = guideBoxSize.height; var itemW = app.activeDocument.selection.width; var itemH = app.activeDocument.selection.height; //to test your script for resize un annotate the two alerts below alert ("guide is this tall " + guideH + "\nguide is this wide " + guideW); alert ("item is this tall " + itemH + "\nitem is this wide " + itemW); var artWidth = itemW; var artHeight =itemH; if (artWidth > artHeight) { var a = (guideW/artWidth)*100; app.activeDocument.selection[0].resize(a,a); } if (artHeight > artWidth) { var b = (guideH/artHeight)*100; app.activeDocument.selection[0].resize(b,b); } var artWidth2 = itemW; var artHeight2 =itemH; if (artHeight2 > guideH) { var c = (guideH/artHeight2)*100; app.activeDocument.selection[0].resize(c,c); } }//end if doresize }//end function resizeart function putname () { var thisDoc = app.activeDocument; thisDoc.rulerOrigin = [0,0]; thisDoc.pageOrigin = [0,0]; var filename = app.activeDocument.name.replace(/\.[^\.]+$/, ''); var createdate = app.activeDocument.modified; var theDate = new Date(); var day = theDate.getDate(); var month = theDate.getMonth() + 1; var year = theDate.getFullYear(); var hours = theDate.getHours(); var min = theDate.getMinutes(); if (min < 10) min = ("0" + min); var morn; if (hours >= 12) { hours = hours-12; morn = " PM"; } else morn = " AM" var saveDate = (month + "-" + day + "-" + year + " " + hours + ":" + min + morn ); var nameTextFrame = thisDoc.textFrames.add(); nameTextFrame.contents = globalartistname + "\n" + filename + "\n" + saveDate; nameTextFrame.top = 1000; nameTextFrame.left = 100; nameTextFrame.filled = true; nameTextFrame.alignment = "center"; }//end put name function savefile () { //change this folder location for the "savescript" variable to the one where the location of the save script is located on the server, //This save script is for the pallet that will pop up and list the different save options, not the individual save scripts themselves. var savescript = new File("S:/Art/ArtDept/Illustrator JS Palette/Scripts/Art Share Server/Save/Save Option Pallet"); savescript.open("r"); var bt = new BridgeTalk; bt.target = "illustrator"; var script = savescript.read(); savescript.close(); bt.body = script; bt.send(); if (saved = true) { alert("File saved") } if (saved == false) { alert ("File not saved") } return true; } //********************************************************************************************************************************************************** //********************This section is for the functions to check which button gets pressed and returns the text to a variable for output **************** //********************************************************************************************************************************************************** //all radiobutton groups must be pressent in this array var totalgroups = [totes1] //this function checks each group for the 1 radio button is clicked then returns its text function selected_rbutton (totalgroups) {//start function to check buttons /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Totes tab buttons //when totes1 is pressed return text for output for (var i = 0; i < totes1.children.length; i++) { if (totes1.children[i].value == true) { return totes1.children[i].text; }//end if }//end if }//end for //////////////////////////////////////////////////////////////////////////open template function openTemp() { //change the folder location of the templates here but leave the last section that is black, this will allow the script to open which //ever template they chose from the radiobuttons. This location should be the same as the toteTempPath above but reduces the //chance for something to break by pulling the address here again instead of from the variable near the begining of the script. var gettotetemp = new File("Z:/ Vitronic Master Templates/STE2 Templates/TOTES & BAGS/" + selected_rbutton (totalgroups)); open(gettotetemp); }//end open temp function }//end if selection check else { alert("Please select the artwork."); } // end else selection check
That is my entire script with notes to help, my script will not run it keeps saying there is an error on a different line everytime I run it and the line that it says the error is on is something simple like .alignChildren = "left"; I'm at a loss as to why it stopped working.
My question is this, after I get it going again I made a mistake when I wrote this because I was testing it with a single path item to make sure that it moved to the template, resized and saved but when I try it with a bunch of different objects it breaks even if try and group them all together first. It won't copy() the entire selection so I added in a section to the script near line 50 that takes all the path items of the selection and puts them into a group. I've been going over this and over this and running it and testing it since I got this done and I can't get it to work, I'm at my wits end and looking for help.
All I need it to do is the following in the correct order;
copy();
openTemp ();
paste();
centerArt ();
resizeart ();
savefile ()
putname ();
separately each function works correctly but when I try and put them all together something breaks. I'll post the script that I'm using for the savefile() in the next post.