script error 1302

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

STE'86
Posts: 2
Joined: Wed Oct 13, 2021 2:13 am

script error 1302

Post by STE'86 »

Hi, i'm asking on behalf of someone else about the script below that has been working for me in cs2,3 and 5 for years with no problem, but is generating the error below in v21.2.0 apparently. anyone know if something has changed in later versions? The script performs allowable number of colours check in an 8x8 pixel square for drawing C64 retro pixel graphics :)

1302 no such element in line 8
var docRef = activeDocument;

full script is as follows:


// Koala Checker by Pete Dabbs 13/10/2010
//
// Use colour picker to choose background colour (D021)
// Don't click on the PS window while it's running else it'll crash (won't cause any real harm)


var docRef = activeDocument;
var layerRef = docRef.activeLayer;
var myCol = new SolidColor();
var x,y,mycount;
var foreCol = new SolidColor();

var newDoc = docRef.duplicate();
newDoc.changeMode(ChangeMode.RGB);
var squareSize,myWidth;
newDoc.flatten();

foreCol = app.foregroundColor;

if (newDoc.pixelAspectRatio == 1)
{
squareSize=8;
myWidth=320;
}
else
{
squareSize=4;
myWidth=160;
}
// establish how much of the bar is filled
i = 0;
// build dialog window
var win = new Window("palette{text:'progress bar',bounds:[100,100,240,180],\
progress:Progressbar{bounds:[20,10,121,20] , minvalue:0,maxvalue:100,value:" + i + "}\
};"
);
win.progress.value = 0
win.center();
win.show();
var prog;
var pColourRED = new SolidColor();
var pColourYELLOW = new SolidColor();
var pColourAMBER = new SolidColor();

pColourRED.rgb.red=255;
pColourRED.rgb.green=0;
pColourRED.rgb.blue=0;
pColourAMBER.rgb.red=255;
pColourAMBER.rgb.green=128;
pColourAMBER.rgb.blue=0;
pColourYELLOW.rgb.red=255;
pColourYELLOW.rgb.green=255;
pColourYELLOW.rgb.blue=0;


prog = 0;
for (y=0;y<200;y+=8)
{
for (x=0;x<myWidth;x+=squareSize)
{
// app.activeDocument = newDoc;
mycount = histo8(newDoc,x,y,foreCol);
prog++;

if (mycount==4)
{
fillsquare(newDoc,x,y,pColourYELLOW);
}
if (mycount==5)
{
fillsquare(newDoc,x,y,pColourAMBER);
}
if (mycount>=6)
{
fillsquare(newDoc,x,y,pColourRED);
}

win.progress.value = (100/(1000/prog));
}
}


function histo8(doc,x,y,forecol)
{
var count;

Stdlib = function() {};
Stdlib.selectBounds = function(doc, b, type, feather, antialias) {
doc.selection.select([[ b[0], b[1] ],
[ b[2], b[1] ],
[ b[2], b[3] ],
[ b[0], b[3] ]],
type, feather, antialias);
};

// getColorAt
// based on:
// fazstp@adobeforums.com wrote:
// news://adobeforums.com:119/3bb84060.0@webx.la2eafNXanI
//


x = Math.floor(x);
y = Math.floor(y);

Stdlib.selectBounds(doc, [x, y, x+squareSize, y+8]);
count=0;
try {
function findPV(h,fcol)
{
var grr=Math.round(fcol.rgb.red);
// alert ("fuck " + grr);
for (var i = 0; i < 256; i++ )
{
if (h!=0 && i!=grr)

{ count++; }
}
// alert ("fuck " + count);
return count;
}

var pColour = new SolidColor();



pColour.rgb.red = findPV(doc.channels["Red"].histogram,forecol);


} finally {
// doc.selection.deselect();
}

return count;
};

function fillsquare(doc,x,y,pColour){
Stdlib.selectBounds = function(doc, b, type, feather, antialias) {
doc.selection.select([[ b[0], b[1] ],
[ b[2], b[1] ],
[ b[2], b[3] ],
[ b[0], b[3] ]],
);
};
Stdlib.selectBounds(doc,[x, y, x+squareSize, y+8]);
var fillColor = pColour;
doc.selection.fill(pColour);
doc.selection.deselect();


}
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: script error 1302

Post by Kukurykus »

It seems you don't have open document when starting script.
STE'86
Posts: 2
Joined: Wed Oct 13, 2021 2:13 am

Re: script error 1302

Post by STE'86 »

and...you were absolutely correct. the guy was trying to run the script with no document open.

something that was so ridiculous to me that i never even thought to ask.

cheers. :)

Steve