<commit_before>﻿/**
 * @@@BUILDINFO@@@ ExportDXF2PNG24.jsx !Version! Wed Jul 06 2016 13:32:12 GMT+0200
 *
 * Script for converting DXF to PNG with Illustrator
 *
 * @author <NAME>
 */

#target illustrator

// if $.level is set to 0 or 1, breakpoints are disabled
$.level = 2;

// The Document used for exporting must be outside the function for
// avoiding page setup every time.
var sourceDoc;

// Select the source folder.
var sourceFolder = Folder.selectDialog('Select the folder with Illustrator files you want to convert to PNG', '~');

// Select files to convert.
var fileType = prompt('Select type of Illustrator files to you want to process. (es: *.dxf)', '*.dxf');

// Select stroke for lines
var strokePercent = prompt("Choose your stroke line increase in percent: >= 0 (very CPU intensive! enter 0 if your PC is not fast enough)", "200", "Change width stroke");

// Get the destination to save the files
var destFolder = Folder.selectDialog('Select the folder where you want to save the converted PNG files.', '~');

// File process logger
var logger = new File(Folder.desktop + "/illustrator-log.txt");

// If a valid folder is selected RUN
if (sourceFolder != null) {
	// Get all files matching the pattern
	var files = sourceFolder.getFiles(fileType);
	if (files.length > 0) {
		main(files);
	} else {
		alert('No matching files found');
	}
}

/**
 * Main processing function.
 *
 * @param {Array} files Array of Files to process.
 */
function main(files) {
	
	for (var i = 0; i < files.length; i++) {
		var dxfFile = files[i],
		pngFile = createPngFile(destFolder, dxfFile);

		// don't overwrite existing files, skip as soon as possible
		if (pngFile.exists == true) {
			continue;
		}

		//Write the info to the file
		log(dxfFile.name);
		
		// uncomment to suppress Illustrator warning dialogsOpenOptionsAutoCAD
		app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

		// options for autocad documents
		with (app.preferences) {
			centerArtwork = true;
			globalScaleOption = AutoCADGlobalScaleOption.FitArtboard;
			//globalScaleOption = AutoCADGlobalScaleOption.ScaleByValue;
			//globalScaleOption = AutoCADGlobalScaleOption.OriginalSize;
			globalScalePercent = "100.0";
			// mergeLayers = true;
			scaleLineweights = false;
			unit = AutoCADUnit.Millimeters;
			// unit = AutoCADUnit.Pixels;
			unitScaleRatio = "1.0";
		}

		sourceDoc = app.open(dxfFile, DocumentColorSpace.RGB);
		// alert(countPathItems());
		
		// very CPU intensive!
		if (strokePercent > 0) {
			applyStroke(strokePercent);
		}

		// convert to png and save
		exportDocToPng(pngFile, 750);

		// close the original without saving
		sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
	}
	alert('Files are saved as PNG in ' + destFolder);
}

/**
 * Save a message to logfile.
 *
 * @param {string} message
 */
function log(message) {
	var hasLogger = false;
	if (logger !== '') {
		//Open the file for writing.
		hasLogger = logger.open('a', undefined, undefined);
		logger.encoding = "UTF-8";
		logger.lineFeed = "Windows";
	}
	// got an output?<commit_msg>Option to skip stroke for the next file been proc<commit_after>﻿/**
 * @@@BUILDINFO@@@ ExportDXF2PNG24.jsx !Version! Wed Jul 06 2016 13:32:12 GMT+0200
 *
 * Script for converting DXF to PNG with Illustrator
 *
 * @author <NAME>
 */

#target illustrator

// if $.level is set to 0 or 1, breakpoints are disabled
$.level = 2;

// The Document used for exporting must be outside the function for
// avoiding page setup every time.
var sourceDoc,
	skipFileStroke = 'N'; // set stroke for all files

// Select the source folder.
var sourceFolder = Folder.selectDialog('Select the folder with Illustrator files you want to convert to PNG', '~');

// Select files to convert.
var fileType = prompt('Select type of Illustrator files to you want to process. (es: *.dxf)', '*.dxf');

// Select stroke for lines
var strokePercent = prompt("Choose your stroke line increase in percent: >= 0 (very CPU intensive! enter 0 if your PC is not fast enough)", "200", "Change width stroke");

// Select stroke for lines
if (strokePercent > 0) {
	// ask if stroke has to be skipped for the first file processed
	skipFileStroke = prompt("Skip stroke for the first file in directory: Y/N", "N");
}

// Get the destination to save the files
var destFolder = Folder.selectDialog('Select the folder where you want to save the converted PNG files.', '~');

// File process logger
var logger = new File(Folder.desktop + "/illustrator-log.txt");

// If a valid folder is selected RUN
if (sourceFolder != null) {
	// Get all files matching the pattern
	var files = sourceFolder.getFiles(fileType);
	if (files.length > 0) {
		main(files);
	} else {
		alert('No matching files found');
	}
}

/**
 * Main processing function.
 *
 * @param {Array} files Array of Files to process.
 */
function main(files) {
	
	for (var i = 0; i < files.length; i++) {
		var dxfFile = files[i],
		pngFile = createPngFile(destFolder, dxfFile);

		// don't overwrite existing files, skip as soon as possible
		if (pngFile.exists == true) {
			continue;
		}

		//Write the info to the file
		log(dxfFile.name);
		
		// uncomment to suppress Illustrator warning dialogsOpenOptionsAutoCAD
		app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

		// options for autocad documents
		with (app.preferences) {
			centerArtwork = true;
			globalScaleOption = AutoCADGlobalScaleOption.FitArtboard;
			//globalScaleOption = AutoCADGlobalScaleOption.ScaleByValue;
			//globalScaleOption = AutoCADGlobalScaleOption.OriginalSize;
			globalScalePercent = "100.0";
			// mergeLayers = true;
			scaleLineweights = false;
			unit = AutoCADUnit.Millimeters;
			// unit = AutoCADUnit.Pixels;
			unitScaleRatio = "1.0";
		}

		sourceDoc = app.open(dxfFile, DocumentColorSpace.RGB);
		// alert(countPathItems());
		
		// in the first loop skipFileStroke allow to skip stroking
		if (strokePercent > 0 && skipFileStroke == 'N') {
			// very CPU intensive!
			applyStroke(strokePercent);
		}
		// for next loop stroking is setted again, as far as strokePercent > 0
		skipFileStroke = 'N';

		// convert to png and save
		exportDocToPng(pngFile, 750);

		// close the original without saving
		sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
	}
	alert('Files are saved as PNG in ' + destFolder);
}

/**
 * Save a message to logfile.
 *
 * @param {string} message
 */
function log(message) {
	var hasLogger = false;
	if (logger !== '') {
		//Open the file for writing.
		hasLogger = logger.open('a', undefined, undefined);
		logger.encoding = "UTF-8";
		logger.lineFeed = "Windows";
	}
	// got an output?
{'fraction_non_alphanumeric': 0.11534968210717529, 'fraction_numerical': 0.01241295791704511, 'mean_word_length': 3.692471590909091, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1831500', 'n_tokens_mistral': 2247, 'n_tokens_neox': 1985, 'n_words': 708}