Problem with custom Incremental Save script

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
swink85
Posts: 13
Joined: January 5th, 2010, 1:37 am

Hello!

I recently wrote a new script for the place I am currently working. Their naming convention does not allow me to use AE's incremental save button, because they use the artists initials AFTER version number (i.e. "boyrunning_v04_sw.aep").

So I wrote a script posted below that will incrementally save while accounting for the initials. I also tried to add a function allowing the user's initials to be switched, but it is not working for some reason. The EditText box I am using gets this weird "NaN" not a number error for some reason and it also does not update the initials into the new file name. Any advice?

Code: Select all


 //Version Up!  

 
 {
 function VersionUp(thisObj)
    {
        function onTextInputChange()
            {
                var newInitials = this.text;
                }
        
        function  onVersionUpButtonClick()
            {
                var projName=app.project.file.name;
 
                var projString = projName.toString();

                var curInitials = projString.substring ((projString.length - 6), (projString.length - 4));
    
                var curVersion = projString.substring ((projString.length - 9), (projString.length - 7));
    
                var newVersion = parseInt(curVersion) + 1;
    
                    function pad2(newVersion) {
   
                        return (newVersion < 10 ? '0' : '') + newVersion
   
                            }
    
                newVersion = pad2 (newVersion);
                
               if ( typeof(newInitals) == "undefined" ) {
                    var newInitials = curInitials;
                    } else {
                     
                    }
                        
                
                var projPath = app.project.file.fsName.toString();
                
                var newProjPath = projPath.substring (0, ( projPath.length - 9)) + newVersion + "_" + newInitials + ".aep";
                
                var newFile = File(newProjPath);
                
                app.project.save(newFile);

               }
 

		function BuildAndShowUI(thisObj)
		{
			// Create and show a floating palette.
			var my_palette = (thisObj instanceof Panel) ? thisObj : new Window("palette", "", undefined, {resizeable:true});
			if (my_palette != null)
			{
				var res = 
					"group { \
						orientation:'column', alignment:['fill','top'], alignChildren:['left','top'], spacing:5, margins:[0,0,0,0], \
                           versionUpButton: Button { text:'Version Up!', maximumSize:[100,20], alignment:['center','top'] }, \
                           optsRow: Group { \
							orientation:'row', \
                                s: StaticText { text:’Initials:’ }, \
                                text_input: EditText { text: ’’, alignment:['center','top'], characters: 2,}, \
						}, \
					}";
				
				my_palette.margins = [10,10,10,10];
				my_palette.grp = my_palette.add(res);
				
				// Workaround to ensure the edittext text color is black, even at darker UI brightness levels.
				var winGfx = my_palette.graphics;
				var darkColorBrush = winGfx.newPen(winGfx.BrushType.SOLID_COLOR, [0,0,0], 1);
				my_palette.grp.optsRow.text_input.graphics.foregroundColor = darkColorBrush;
				
				my_palette.grp.versionUpButton.onClick  = onVersionUpButtonClick;
                  my_palette.grp.optsRow.text_input.onChange = onTextInputChange;
				
				// Set the callback. When the user enters text, this will be called.

				my_palette.layout.layout(true);
				my_palette.layout.resize();
				my_palette.onResizing = my_palette.onResize = function () {this.layout.resize();}
			}
			
			return my_palette;
		}
    
    // 
		// The main script.
		//
		if (parseFloat(app.version) < 8) {
			alert("This script requires After Effects CS3 or later.", scriptName);
			return;
		}
		
		var my_palette = BuildAndShowUI(thisObj);
		if (my_palette != null) {
			if (my_palette instanceof Window) {
				my_palette.center();
				my_palette.show();
			} else {
				my_palette.layout.layout(true);
			}
		} else {
			alert("Could not open the user interface.", scriptName);
		}
	}
	
	VersionUp(this);
}

swink85
Posts: 13
Joined: January 5th, 2010, 1:37 am

So I figured out my issue with the EditText box.... I forgot to add ".text" at the end when referencing it. Now I am having trouble getting the new initials update function to work. Here is my latest code. Any ideas?

I think the problem is somewhere in my if/else statement towards the top

Code: Select all


 //Version Up!  
 
 
 {
 function VersionUp(thisObj)
    {
        //function onTextInputChange()
            //{
               //  var initialsInput = my_palette.grp.optsRow.text_input.text;
                  //   var newInitials = initialsInput.substring(0, 2);
            //  }
        
        function  onVersionUpButtonClick()
            {
                var projName=app.project.file.name;
 
                var projString = projName.toString();

                var curInitials = projString.substring ((projString.length - 6), (projString.length - 4));
    
                var curVersion = projString.substring ((projString.length - 9), (projString.length - 7));
    
                var newVersion = parseInt(curVersion) + 1;
    
                    function pad2(newVersion) {
   
                        return (newVersion < 10 ? '0' : '') + newVersion
   
                            }
    
                newVersion = pad2 (newVersion);
                
               if (  my_palette.grp.optsRow.text_input.text = "" ) {
                    var newInitials = curInitials;
                    } else {
                            var initialsInput = my_palette.grp.optsRow.text_input.text;
                           var newInitials = initialsInput.substring(0, 2);
                    }
                        
                
                var projPath = app.project.file.fsName.toString();
                
                var newProjPath = projPath.substring (0, ( projPath.length - 9)) + newVersion + "_" + newInitials + ".aep";
                
                var newFile = File(newProjPath);
                
                app.project.save(newFile);

               }
    
		// 
		// This function puts up a modal dialog asking for a scale_factor.
		// Once the user enters a value, the dialog closes, and the script scales the comp.
		// 
		function BuildAndShowUI(thisObj)
		{
			// Create and show a floating palette.
			var my_palette = (thisObj instanceof Panel) ? thisObj : new Window("palette", "", undefined, {resizeable:true});
			if (my_palette != null)
			{
				var res = 
					"group { \
						orientation:'column', alignment:['fill','top'], alignChildren:['left','top'], spacing:5, margins:[0,0,0,0], \
                           versionUpButton: Button { text:'Version Up!', maximumSize:[100,20], alignment:['center','top'] }, \
                           optsRow: Group { \
							orientation:'row', \
                                s: StaticText { text:’Initials:’ }, \
                                text_input: EditText {alignment:['center','top'], characters: 4,}, \
						}, \
					}";
				
				my_palette.margins = [10,10,10,10];
				my_palette.grp = my_palette.add(res);
				
				// Workaround to ensure the edittext text color is black, even at darker UI brightness levels.
				var winGfx = my_palette.graphics;
				var darkColorBrush = winGfx.newPen(winGfx.BrushType.SOLID_COLOR, [0,0,0], 1);
				my_palette.grp.optsRow.text_input.graphics.foregroundColor = darkColorBrush;
				
				my_palette.grp.versionUpButton.onClick  = onVersionUpButtonClick;
                  //my_palette.grp.optsRow.text_input.onChange = onTextInputChange;
                  my_palette.grp.optsRow.text_input.text = "";
                  my_palette.grp.optsRow.s.text = "New Initials";
				
				// Set the callback. When the user enters text, this will be called.

				my_palette.layout.layout(true);
				my_palette.layout.resize();
				my_palette.onResizing = my_palette.onResize = function () {this.layout.resize();}
			}
			
			return my_palette;
		}
    
    // 
		// The main script.
		//
		if (parseFloat(app.version) < 8) {
			alert("This script requires After Effects CS3 or later.", scriptName);
			return;
		}
		
		var my_palette = BuildAndShowUI(thisObj);
		if (my_palette != null) {
			if (my_palette instanceof Window) {
				my_palette.center();
				my_palette.show();
			} else {
				my_palette.layout.layout(true);
			}
		} else {
			alert("Could not open the user interface.", scriptName);
		}
	}
	
	VersionUp(this);
}

Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

On approx line 33 you have this line:
if ( my_palette.grp.optsRow.text_input.text = "" ) {

but it should be:
if ( my_palette.grp.optsRow.text_input.text == "" ) {
swink85
Posts: 13
Joined: January 5th, 2010, 1:37 am

aw man, rookie mistake! thanks for the help!
Post Reply