0

I tried this on svg first, but the come didnt well, anyone know? So I want the name is Layer and group visible only

case

Layer Bono (O)

  • grup A (.)
  • grup B (.)
  • grup C (O)

Layer Delta (O)

  • grup D (.)
  • grup E (O)
  • grup F (.)

note___ // (O)= visible, (.)= hidden

I want the PNG filemnames is name is "Layer Bono - group C -Layer Delta - group F. png"

this is script for js


// uncomment to suppress Illustrator warning dialogs
// app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

try {
    if (app.documents.length > 0 ) {

        // Get the folder to save the files into
        var destFolder ="/d/design/nft/print/5";
        //destFolder = Folder.selectDialog( 'Select folder for SVG files.', '~' );

        if (destFolder != null) {
            var options, i, sourceDoc, targetFile;  
            
            // Get the SVG options to be used.
            options = this.getOptions();
            // You can tune these by changing the code in the getOptions() function.
                    
            for ( i = 0; i < app.documents.length; i++ ) {
                sourceDoc = app.documents[i]; // returns the document object
                                        
                // Get the file to save the document as svg into
                targetFile = this.getTargetFile(sourceDoc.name, '.png', destFolder);
                
                // Save as SVG
                sourceDoc.exportFile(targetFile, ExportType.PNG24, options);
                // Note: the doc.exportFile function for SVG is actually a Save As
                // operation rather than an Export, that is, the document's name
                // in Illustrator will change to the result of this call.               
            }
            alert( 'Documents saved' );
        }
    }
    else{
        throw new Error('There are no document open!');
    }
}
catch(e) {
    alert( e.message, "Script Alert", true);
}


/** Returns the options to be used for the generated files.
    @return ExportOptionsSVG object
*/
function getOptions()
{
    // Create the required options object
    var opts = new ExportOptionsPNG24();
    opts.antiAliasing = false;
    opts.transparency = false;
    opts.artBoardClipping = true;
    opts.horizontalScale = 75;
    opts.verticalScale = 75;
    // See ExportOptionsSVG in the JavaScript Reference for available options
        
    // Set the options you want below:
    
    // For example, uncomment to set the compatibility of the generated svg to SVG Tiny 1.1 
    // options.DTD = SVGDTDVersion.SVGTINY1_1;
    
    // For example, uncomment to embed raster images
    // options.embedRasterImages = true;
    
    return opts;
}

/** Returns the file to save or export the document into.
    @param docName the name of the document
    @param ext the extension the file extension to be applied
    @param destFolder the output folder
    @return File object
*/
function getTargetFile(docName, ext, destFolder) {
    var docRef = app.activeDocument; 
    docRef.selection = null;
    var newName="";
        for (i=0; i<docRef.groupItems.length;i++){
        var groupName= docRef.groupItems[i];
            if (groupName.hidden == false){
            for(k=0;k<docRef.layers.length;k++){
            if(groupName.parent.visible == true && groupName.parent.name === docRef.layers[k].name && groupName.parent.name != "i"){
            newName+=groupName.parent.name+'-';
            newName+=groupName.name+'-';}
            }
        }
    }




    // if name has no dot (and hence no extension),
    // just append the extension
        newName += ext;

    
    // Create the file object to save to
    var myFile = new File( destFolder + '/' + newName );
    
    // Preflight access rights
    if (myFile.open("w")) {
        myFile.close();
    }
    else {
        throw new Error('Access is denied');
    }
    return myFile;
}

Already done thanks

2
  • An error or some reason for it failing might help us, but there is a syntax error on line 70: for (j=; j<11;j++){ you have not initialized the variable j. Try j=0;
    – Yorik
    Oct 19, 2021 at 14:33
  • Already done thanks bro, see updated script
    – Bapak
    Oct 22, 2021 at 19:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.