Copy link to clipboard
Copied
Can anyone tell me if .colorSamplers is supported in good ol' CS2?
When i runn the following code I get: Undefined is not an object
var sampler = app.activeDocument.colorSamplers.add([0,0]);
Thank you
Copy link to clipboard
Copied
I'm not sure about CS2, as I no longer have it, but you might need to define the point array with a pixel value such as:
var pt = ['0 px','0 px']
I think the need for the pixel value was dropped in later versions.
Copy link to clipboard
Copied
I'm also not sure about CS2.
But this code (to add a ColorSampler) works definitly in CS2:
var posX = 10;
var posY = 20;
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( charIDToTypeID( "ClSm" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
var desc1 = new ActionDescriptor();
desc1.putUnitDouble( charIDToTypeID( "Hrzn" ), charIDToTypeID( "#Pxl" ), posX );
desc1.putUnitDouble( charIDToTypeID( "Vrtc" ), charIDToTypeID( "#Pxl" ), posY );
desc.putObject( charIDToTypeID( "Pstn" ), charIDToTypeID( "Pnt " ), desc1 );
executeAction( charIDToTypeID( "Mk " ), desc, DialogModes.NO );
Have fun
Copy link to clipboard
Copied
Yes, that snippet of Action Descriptor code has the unit value included also.
Copy link to clipboard
Copied
How do I return a value from an ActionDescriptor?
I've tried turning the above code into a function and tried to return Application.getCustomOptions & ActionDescriptor.getObjectValue but no to avail.
Copy link to clipboard
Copied
Not sure what you are asking. How is customOptions related to creating a colorSampler function?
Copy link to clipboard
Copied
I was wondering that too. Err grasping at straws really. Blame questionable documentation (not from adobe)
The action descripter runs the code but I don't know how to assign a varible to it. I just wanted to put the colour sampler in a function and return the sampler value.
Copy link to clipboard
Copied
I seem to recall that you have to define the unit value in CS2. You don't now. Try this:
var docRef = activedocument
var ptX = 10 //your point varible locations
var ptY =20
var pt = [UnitValue(ptX,'px'),UnitValue(ptY,'px')];// assign values to a point
docRef.colorSamplers.removeAll()
var sampler = docRef.colorSamplers.add(pt);
var redValue = sampler.color.rgb.red //do the same for other colors
var cyanValue = sampler.color.cymk.cyan //sample any color space
Copy link to clipboard
Copied
No, that just kicks up error 21
Undefined is not an object
on lines
srcDoc.colorSamplers.removeAll()
var sampler = srcDoc.colorSamplers.add(pt);
Minor point
var docRef = activeDocument
Copy link to clipboard
Copied
I don't have CS2 installed but the CS2 javascript guide does not list colorSamplers. The CS3 guide does and says it is a new feature. So I don't think you will be able to use colorSamplers to get colors.
Yes you can use action manager to make a colorSampler but there isn't a way to access it via a script once it is created.
Without colorSamplers you need to create a 1x1 px selection and read the histogram of the selection to get the color.
Copy link to clipboard
Copied
Well I'm glad you mentioned that I can't access the coloursampler information; I thought something was going a bit awry.
I thought that might be the case to get around this problem. I have dug up an old script that does just that.
Copy link to clipboard
Copied
With a document open in CS2 run this line in ESKT with Photoshop as the target app.
app.activeDocument.reflect.properties
If colorSamples are part of the CS2 Object Model it should be listed in the doc properties.
For most methods that use UnitValue object you can supply a number as the value and Photoshop uses the rulerUnit as the unit so I don't think the arguments are the problem. Even if they were I would expect a different error message.
Note that even with CC if you run that line in ESTK with the target app set to ESTK you will get the same error message. ESTK doesn't have an app.activeDocument. Did you run your code in ESTK with the wrong target app?
Copy link to clipboard
Copied
Running that I get:
backgroundLayer
bitsPerChannel
colorProfileType
colorProfileName
mode
componentChannels
activeHistoryState
activeHistoryBrushSource
activeLayer
activeChannels
info
fullName
height
managed
saved
name
path
quickMaskMode
resolution
selection
width
histogram
pixelAspectRatio
xmpMetadata
layers
layerSets
artLayers
channels
historyStates
layerComps
pathItems
typename
parent
__proto__
So I'm guessing no, then