Creating a color swatch legend in Illustrator
I've been looking for scripts online that would create a color swatch legend to list the colors used in my illustrator file. I found this (see below) and tweaked it to place properly on my particular page, but it adds everything in my swatches panel to the legend. Ideally, I'm looking for a piece of script to add that would only add used swatches to the legend, or a script that would only add spot colors to the legend. I'm a scripting novice, so any help is much appreciated...
var docRef=app.activeDocument;
var SwatchBoxSize=24;
var swatchBoxSize=parseFloat(SwatchBoxSize);
var swatchBoxTop=swatchBoxSize+314;
//Loop through the members of the document's inkList.
for(i=docRef.swatches.length-1;i>=0;i--){
var swatchRef=docRef.swatches;
var swatchRefName=docRef.swatches.name;
var swatchBox=docRef.pathItems.rectangle(swatchBoxTop, 24, 43, 14);
swatchBox.fillColor=swatchRef.color;
swatchBox.stroked=true;
var swatchLabelX= swatchBox.left+swatchBox.width+6;
var swatchLabelY = swatchBoxTop-(swatchBox.height/2);
var swatchLabel = docRef.textFrames.pointText([swatchLabelX,swatchLabelY]);
swatchLabel.contents = swatchRefName;
swatchLabel.textRange.characterAttributes.size=swatchBoxSize/3;
swatchLabel.textRange.characterAttributes.leading=swatchBoxSize/ 3;
swatchLabel.textRange.characterAttributes.fillColor=docRef.swatches["[Registration]"].color;
swatchBoxTop+=(swatchBoxSize*.7);
}//end for