Skip to content

Instantly share code, notes, and snippets.

@hilukasz
Created May 24, 2012 22:14
Show Gist options
  • Save hilukasz/2784513 to your computer and use it in GitHub Desktop.
Save hilukasz/2784513 to your computer and use it in GitHub Desktop.
first javascript
unction MySymbol(input){
this.doc = app.activeDocument;
this.mySymbolIndex = input || 0;
}
MySymbol.prototype.hasSymbolIndex = function() {
return this.mySymbolIndex <= this.doc.symbolItems.length - 1;
};
MySymbol.prototype.width = function() {
if (!this.hasSymbolIndex()) { return 0; }
return Math.round(this.doc.symbolItems[this.mySymbolIndex].width);
};
MySymbol.prototype.height = function() {
if (!this.hasSymbolIndex()) { return 0; }
return Math.round(this.doc.symbolItems[this.mySymbolIndex].height);
};
var firstSymbol = new MySymbol(1);
firstSymbol.width();
firstSymbol.height();
function mySymbol(input){
var idoc = app.activeDocument;
if (input <= idoc.symbolItems.length-1) {
alert(idoc.symbolItems.length);
if (input) {
this.mySymbolIndex = input;
} else { this.mySymbolIndex = 0; }; //set up default symbol to first one if none is defined
this.width = function () {
var symbolWidth = Math.round(idoc.symbolItems[this.mySymbolIndex].width); //convert float to int
return symbolWidth;
}
this.height = function () {
var symbolHeight = Math.round(idoc.symbolItems[this.mySymbolIndex].height); //convert float to int
return symbolHeight;
}
}
else {
alert('There are only '+idoc.symbolItems.length+'symbols in your library, you selected '+input+'try a lower number');
this.height = 0;
this.width = 0;
}
}
var firstSymbol = new mySymbol(1);
firstSymbol.width();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment