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

Edit a text field - script update

Explorer ,
Mar 30, 2011 Mar 30, 2011

I have a script that we use to approve artwork.  Each AI file has a text frame called "Approvals".  When we run the script, we put in the PO# that the art is approved for and it pastes a name/date/approval info stamp on the artboard.

Question is, how can I set an entry point to go to the last character of the text frame, force a carriage return, and start on the next line for each time the script is ran?  That way, it doesn't delete previous approvals each time we add one.

Please help if you can - here is the script:

#target illustrator

function main() {
     if (app.documents.length == 0) {
          alert("Please have an 'Illustrator' document before running this script.");
          return;
     }
     var docRef = app.activeDocument;
     with (docRef) {
     
var ponumber = prompt("What PO's are you approving?", "Type PO here");

     
     
var thisDate = getTodaysDate();

var docName = name;


var userName = 'Tim Johnson'; // Change each users name here


          // if (saved == false) save();
          var filePath = path;
         
          try {
               var frameA = textFrames.getByName('Approvals');
               frameA.contents = thisDate + ' - '  + userName  + ' approved for production for the following orders: ' + ponumber;
          } catch (e) {
               alert('Cannot find the Approvals text box')
          }
     
               }
     }


main();

function getTodaysDate() {

var today = new Date();

var dd = today.getDate();

if (dd < 10) {dd ='0' + dd};

var mm = today.getMonth() + 1;

if (mm < 10) {mm ='0' + mm};

var yyyy = today.getFullYear();

var thisDate = mm + '.' + dd + '.' + yyyy;

return thisDate;

}

TOPICS
Scripting
1.8K
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
Adobe
Guide ,
Mar 30, 2011 Mar 30, 2011

Changing your try catch part to…

try {      var frameA = textFrames.getByName('Approvals');      var preApp = frameA.contents;      frameA.contents = preApp + thisDate + ' - '  + userName       + ' approved for production for the following orders: '      + ponumber + '\r'; } catch (e) {      alert('Cannot find the Approvals text box') }

Store the previous contents into a variable then concat the lot back… The '\r' should give you a new line after each run to add to…

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 ,
Mar 30, 2011 Mar 30, 2011
LATEST

This is perfect.  Thank you very much!!

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