This is my very first attempt at a script:
all tips are greatfully recieved
* this script will prompt the user for a file name and location and then
save the current file as a .pdf with secure save options*/
var curDoc = app.activeDocument;
var destName = prompt ("Enter a Filename Daniel", "", "Save With Security");
var destFolder = Folder.selectDialog('Select which folder to save to :');
saveFileToPDF(destFolder+ '/' + destName); // not sure if i need this here ?
/* this will annotate the document with a breadcrumb trail
then resave the file with the same security settings*/
// i need to find a method of placing this central to the artboard, but as the text has random dimensions its proving difficult also there are multiple artboards
var pointTextRef = curDoc.textFrames.add();
pointTextRef.contents = curDoc.name + ' ' + curDoc.fullName;
pointTextRef.top = 735;
pointTextRef.left = 20;
saveFileToPDF(destFolder+ '/' + destName); // i need this here
//
function saveFileToPDF (dest) {
var doc = app.activeDocument;
if ( app.documents.length > 0 ) {
var saveName = new File ( dest );
saveOpts = new PDFSaveOptions();
saveOpts.requirePermissionPassword = true;
saveOpts.permissionPassword = "test";
doc.saveAs( saveName, saveOpts );
}
}
i can do the math of (artboard width)-(text width) / 2 is start point of text but how do i find out the text width and the artboard width?
Message was edited by: tonyxamax
For your artboards which one do you intend to place the text on first, last all?
As for your text… It is by default point text therefore you could position the point and centre align the contents ( thats what I would do )
There are several scripts already knocking about that add such fluff like name & path to a file…
I'ts always on the first artboard.
Centre align the contents is the "magic button" im searching for!
My background is Illustrator, not scripting, and I have used other scripts and find them fantastic but i really wanted to have a go myself,
this script is my "baby steps" script.
I know once i get my head round all the syntax that scripting will make my life so much easier but its very tempting to give in when you try to do something so simple and you just simply dont know the correct syntax.
This should help you along…
#target illustrator
app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
var doc = app.activeDocument;
doc.artboards.setActiveArtboardIndex( 0 );
var abRect = doc.artboards[0].artboardRect;
var txt = doc.textFrames.add();
txt.position = [ abRect[2]/2, abRect[3]/2 ];
txt.textRange.paragraphAttributes.justification = Justification.CENTER;
txt.contents = 'Some strings…';
Works perfectly Mark !
Thank you
I didnt explain fully what i wanted so i have tweaked it a little ( sound like a pro ! but i am SO not !)
I am still struggling with the numbers in the [ ] parenthesis but I will get there,
Slow drips wear away stones.
I was a little reluctant to post here asking for help in case i either sounded like a noddy or offended someone by mistake or bad grammar!
You have been very helpful thank you
Only the people who demand a script or solution ( like it's there right ) are frowned upon… Those wanting help almost never… You will find in all the scripting forums here people are willing to help those who want to learn… ( the teach a man to fish approach ). Im muppet cos thats what I was when I was a noob asking here… still am… ![]()
The numbers in the square brackets indicate an item of an array ( list ) the rectangular bounds of an artboard are a 4 item Array [ '0', '0', '200', '100' ] javascript is zero based so first item is [0] and so on…
I am in the middle of reading the relevant documentation honest!!, but it is a slow process ( or maybe I am a slow process!!).
It is almost like giving a man a Spanish dictionary and expecting him to be able to write a piece of classic literature in perfect Spanish.
So in the eternal hope of a quick fix could you guide me in the intricacies of how to display a filename with out all the "%20" gubbings? ( "gubbings" = A yorkshire word that roughly translates into "stuff i don't understand"
This is not essential but i just dont like the way it looks.
I am currently fumbling blindly with .name and .fullName
I have seen some scripts on here that run a filter through the string looking for the odd characters and replacing them with spaces i wanted to ask the question, "am I missing the obvious?"
Can i return the filename without the URL formatting?
// CODE BEGIN
var docRef = app.activeDocument
var pointTextRef = docRef.textFrames.add();
pointTextRef.contents = docRef.name + ' ' + docRef.fullName;
pointTextRef.top = 635;
pointTextRef.left = 20;
// CODE END
.name returns my document name with normal spacing, but .fullName returns the document name and file location in a URL format. Is this purely the nature of the beast? or is it because the file is stored on a network drive?
Thanks
.fullName is the entire file path to the file. It will return the same form with a few less parts if it is located on your local hard drive. Try making a file and saving it to your desktop and then run your script. If you only want the name of the file and not the path to the file then just use .name.
The "%20" is just computerese for a space character.
North America
Europe, Middle East and Africa
Asia Pacific