-
Notifications
You must be signed in to change notification settings - Fork 30
Classes
fabiantheblind edited this page Nov 19, 2015
·
3 revisions
Here is an Example of a Debugger Class
Achtung! Classes work in Javascript but the File object used is a Extendscript thing that does not work Javascript.
/**
* This is a debugger class for creating files with infos about stuff
* @param {Boolean} dbg if true the debugger will be initialized
* @param {String} title the title in the debug info file
* @param {Stirng} message An alert message can be set via DEebugger.message = "something"
*
*
* // make a new Debugger
* var deeBug = new Debugger(true,"MyScript.jsx version 0.1.2","This is a debug version");
*
* // alert the message
* deeBug.message();
*
* // add a line to the file
* deeBug.addLineToInfo("This is a line in the file" + something);
*
* // create the file always on the desktop right now always with the name
* // "debuginfo" can be set via deeBug.filename = "myfile" no extension will be .txt
* // he will try to execute the file in the std editor
*
* deeBug.writeInfos();
*
*
*/
function Debugger(dbg,title,message){
this.DEBUG = dbg;
this.filename ="debuginfo";
this.filepath = "~/Desktop/"+ this.filename +".txt";
this.debugstrings = [title,message];
this.messageString = message;
this.addLineToInfo = function (line){
if(this.DEBUG == true){
this.debugstrings.push(line);
};
};
this.message = function(){
if(this.DEBUG == true){
alert(this.messageString);
}
};
this.writeInfos = function (){
if(this.DEBUG == true){
// get the textfile
var write_file = File(this.filepath);
if(!write_file.exists){
// if the file does not exist create one
write_file = new File(this.filepath);
}else{
// if it exsists ask the user if it should be overwritten
var res = confirm ("The file already exists. Should I overwrite it", true, "titleWINonly");
// if the user hits no stop the script
if(res != true){
return;
};
};
var out;// our output
// we know already that the file exist
// but to be shure
if( write_file!='' ){
//Open the file for writing.
out = write_file.open( 'w', undefined, undefined );
write_file.encoding = "UTF-8";
write_file.lineFeed = "Unix"; //convert to UNIX lineFeed
// txtFile.lineFeed = "Windows";
// txtFile.lineFeed = "Macintosh";
};
// got an output?
if( out != false ){
// loop the list and write each item to the file
write_file.writeln(this.debugstrings.join('\n'));
// allways close files!
write_file.close();
write_file.execute();
}
}
}
}
##Usage:
#include 'Debugger.jsx';// include the file. needs to be next to this script
var deeBug = new Debugger(true,"MyScript.jsx version 0.1.2","This is a debug version");// Debugger init global
main();
function main(){
deeBug.message();// this is just an alert that only pops up if the debugger is true
var something = 5;
something++;// do something
deeBug.addLineToInfo("This is a line in the file" + something); // add some content
deeBug.writeInfos();// writes and opens a file
}
This wiki is maintained by:
fabiantheblind
Thanks to:
- JohnDarnell for fixing lots of typos.
- jsp for fixing lots of typos.
- ltfschoen for fixing typos.
- wridgers for adding more links.
Thanks to the students from the seminar for asking all those questions and making me start this wiki.
- adinaradke
- AnitaMei
- ce0311
- coerv
- felixharle
- FerdinandP
- Flave
- marche
- monkian
- natael
- OliverMatelowski
- PDXIII
- praktischend
- schlompf
- skaim
You are awesome.
- Arrays
- Classes
- Comments
- Conditionals
- Functions
- Inspect Properties
- Loops
- Objects
- Output And Interaction
- Recursive Functions
- Inspect Properties
- Variables And Operations
- Extended JavaScript Guide
- Bridge Talk
- Create And Read Files
- ExtendScript Toolkit
- File
- Folder
- Includes JSX
- Object Watch
- Read In JSON From File And DONT Eval
- Storing Data In A Target Engine
- Target an application
- XML
- app
- Colorbrewer
- Colors And Swatches
- Delay And View
- Dialogs
- Documents
- Duplicate And Transform
- Event AfterSave
- Export IDML
- ExtendScript in InDesign Scripting DOM
- Fonts
- GeometricBounds and Coordinates
- Get named pageItems
- Graphic Lines
- Groups
- HSL Color Wheel
- Images
- Includes
- InsertionPoints
- Layers
- Line Feeds And Carrige Returns
- Masterspreads
- Matrix
- Objectstyles
- Outlines Groups Alignment
- Pages And Margins
- Pathfinder
- Placeholder Text
- Rectangles Ovals Polygons
- RulerOrigin
- Select words at insertionPoint
- Simple Find And Change Grep with FC Query
- Simple Find And Change Grep
- Simple Find And Change Text
- Spiro
- Styles
- Text Analysis ID FC
- Text Analysis
- Text Find Locations
- Text
- Transformation Matricies
- TransparencySettings
- XML creation and import