/* Time Stamp Creates timestamp layer Timestamp creates a Text Layer with the current Date and Time applied. The script works with a single selected comp. The timestamp is created as the top layer in the selected comp. Due to limitations in accessibility of formatting options for Text Layers via scripting the first version of this script only uses a left side orientation. Copyright 2006 - Dale Bradshaw, dale@creative-workflow-hacks.com http://creative-workflow-hacks.com Free To Distribute, but you must maintain this header if used without alteration, please also include a link to http://creative-workflow-hacks.com if posted on the web If you use parts of this script please include my contact info as attribution (suggested but not required...thanks) v1.0 May 28, 2006 */ //global variables var selectedItemInfo = {name: "", type:"", source:""}; var items = app.project.items; var win = new Window('palette', 'Create TimeStamp',[100,100,352,345]); var w = buildUI(); checkPrerequisites(); function usage(){ var usage = "Creates timestamp layer\nTimestamp creates a Text Layer with the current Date and Time applied.\n\nThe script works with a single selected comp.\nThe text layer is created as the top layer in the selected comp.\n\nUse the \"include date\", \"include time\" and \"include GMT\" checkboxes to control the component parts of the Timestamp.\nUse \"Time Stamp Position\" and \"Time Stamp Size\" to select the location and size of the timeStamp.\n\nDue to limitations in accessibility of formatting options for Text Layers via scripting the first version of this script only uses a left side orientation.\n"; alert(usage); } function checkPrerequisites(){ var selectedCount = 0; for (var i = 1; i <= items.length; i++){ if(items[i].selected){ if (items[i] instanceof CompItem){ selectedItemInfo.type = 'CompItem'; selectedItemInfo.name = items[i].name; selectedItemInfo.source = items[i]; }else{ selectedItemInfo.type = ''; selectedItemInfo.name = ''; selectedItemInfo.source = ''; alert('Please select a single comp before running Time Stamp'); } selectedCount++; } } if(selectedCount > 1 || selectedCount == 0){ selectedItemInfo.type = ''; selectedItemInfo.name = ''; selectedItemInfo.source = ''; var selectAlert = "Please select a single comp before running Time Stamp"; alert(selectAlert); }else{ if(w != null){ w.show(); }else{ alert("Couldn't build UI"); } } } function buildUI(){ if (win != null) { win.timeStampPositionPnl = win.add('panel', [20,25,230,120], 'Time Stamp Position:'); win.timeStampPositionPnl.alignUpperLeftRb = win.timeStampPositionPnl.add('radiobutton', [30,30,105,40], 'Upper Left'); //win.timeStampPositionPnl.alignUpperRightRb = win.timeStampPositionPnl.add('radiobutton', [105,30,205,40], 'Upper Right'); win.timeStampPositionPnl.alignLowerLeftRb = win.timeStampPositionPnl.add('radiobutton',[30,60,105,70], 'Lower Left'); // win.timeStampPositionPnl.alignLowerRightRb = win.timeStampPositionPnl.add('radiobutton',[105,60,205,70], 'Lower Right'); win.timeStampPositionPnl.alignLowerLeftRb.value = true; win.timeStampSizePnl = win.add('panel', [20,125,230,160], 'Time Stamp Size:'); win.textSize = win.timeStampSizePnl.add ("slider",[05,18,205,28],33, 10, 100); win.useDateCb = win.add('checkbox', [10,175, 90,190], 'Include Date'); win.useDateCb.value = true; win.useTimeCb = win.add('checkbox', [90,175, 170,190], 'Include Time'); win.useTimeCb.value = true; win.useGMTCb = win.add('checkbox', [170,175, 260,190], 'Include GMT'); win.useGMTCb.value = true; win.helpBtn = win.add('button', [20,205,50,225], '?', {name:'help'}); win.helpBtn.onClick = usage; win.cancBtn = win.add('button', [105,205,165,225], 'Cancel', {name:'cancel'}); win.cancBtn.onClick = function () {this.parent.close(0)}; win.okBtn = win.add('button', [172,205,230,225], 'OK', {name:'ok'}); win.okBtn.onClick = function () {applyTimeStamp(this.parent); }; } return win } function applyTimeStamp(dialog){ checkPrerequisites(); app.beginUndoGroup("Apply Time Stamp"); if(selectedItemInfo.type == 'CompItem'){ //nice catch on the Date(0) at http://www.aenhancers.com/viewtopic.php?t=442 var date = Date(0); //build substring based on panel var dateData = date.split(" "); var dateString = ''; dateString += w.useDateCb.value ? dateData[0] + " " + dateData[1] + " " + dateData[2] + " " + dateData[3] + " ": ""; dateString += w.useTimeCb.value ? dateData[4] + " " : ""; dateString += w.useGMTCb.value ? dateData[5] : ""; //also grab component value for width calculation var datePart = 0; datePart += w.useDateCb.value ? 1 : 0; datePart += w.useTimeCb.value ? 1 : 0; datePart += w.useGMTCb.value ? 1 : 0; if(dateString){ var timeStampLayer = selectedItemInfo.source.layers.addText(dateString); //check size var timeStampScale = timeStampLayer.scale; timeStampScale.setValue([w.textSize.value, w.textSize.value]); //here is where we check which corner to place var timeStampPosition = timeStampLayer.position; var compHeight = selectedItemInfo.source.height; var compWidth = selectedItemInfo.source.width; //adjust for title safe var xInset = compWidth * .10; var yInset = compHeight * .10; if(w.timeStampPositionPnl.alignLowerLeftRb.value){ var layerXPosition = xInset ; var layerYPositon = compHeight - (yInset + (w.textSize.value * .001)); timeStampPosition.setValue([layerXPosition,layerYPositon , 0.0]); }else if(w.timeStampPositionPnl.alignUpperLeftRb.value){ var layerXPosition = xInset ; //different font metrics? if(system.osName == 'MacOS'){ var layerYPositon = compHeight - (compHeight - (yInset + (w.textSize.value * .25))); }else{ var layerYPositon = compHeight - (compHeight - (yInset + (w.textSize.value * .125))); } timeStampPosition.setValue([layerXPosition,layerYPositon , 0.0]); } } }else{ } app.endUndoGroup(); }