Results 1 to 8 of 8

Thread: Export all layers as individual files.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2017
    Posts
    1

    Script to export separate layers

    I'm trying to export separate layers too. So far, I have the script below, and it's working OK. It exports only named layers. The script is so simple, I'm amazed this function is not built in!

    If anyone knows how to get the current painting's filename and path as the baseName, or some other way I can replace the InputBox with something more elegant, help would be much appreciated.

    Code:
    <Events>
    
    int i;
    string baseName;
    string layerName;
    string fileName;
    flag overwriteExisting = false;
    
    InputBox( "Base name: $$baseName" );
    
    for ( i = 0; i < LayerCount(); i++ ) {
    
    	layerName = LayerName( i );
    
    	if ( layerName != "" ) {
    	
    		fileName = baseName + "_" + layerName + ".png";
    		
    		if ( FileExists( fileName ) ) {
    		
    			if ( !overwriteExisting ) {
    				overwriteExisting = YesNoBox( fileName + " already exists. Overwrite layer files?" );
    				
    				if ( !overwriteExisting ) {
    					MessageBox( "Cancelling export" );
    					exit;
    				}
    				
    			}
    			
    			if ( overwriteExisting ) {
    				FileDelete( fileName ); // overwrites existing files
    			}
    			
    		}
    		
    		Wait: 0.000s	EvType: Command	CommandID: ExportLayer	Idx: i	Channels: NO	Path: fileName	
    		
    	}
    	
    }

  2. #2

    how to get file name & path

    Quote Originally Posted by relaxedromance View Post
    I'm trying to export separate layers too. So far, I have the script below, and it's working OK. It exports only named layers. The script is so simple, I'm amazed this function is not built in!

    If anyone knows how to get the current painting's filename and path as the baseName, or some other way I can replace the InputBox with something more elegant, help would be much appreciated.
    Function Name
    Function declaration
    Description
    Example
    =======================

    Name

    string Name()

    Return the filename of the file. This is set when the file is opened (either with Open() or with the file dialogs)

    s = filDoc.Name()
    filDoc.LoadDialog();
    if (filDoc.Name() == “fish.txt”)...

    -----------------------------------------------------

    FullPath

    string FullPath()

    Returns the full path including the name of the file. This is set when the file is opened (either with Open() or with the file dialogs)

    s = filDoc.FullPath();
    filDoc.SaveDialog(“Scores.txt”);
    if (filDoc.FullPath() == sOld) ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •