• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Colour sampler in CS2

Engaged ,
Oct 11, 2013 Oct 11, 2013

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

TOPICS
Actions and scripting

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Oct 11, 2013 Oct 11, 2013

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 11, 2013 Oct 11, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 11, 2013 Oct 11, 2013

Copy link to clipboard

Copied

Yes, that snippet of Action Descriptor code has the unit value included also.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 14, 2013 Oct 14, 2013

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 14, 2013 Oct 14, 2013

Copy link to clipboard

Copied

Not sure what you are asking. How is customOptions related to creating a colorSampler function?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 15, 2013 Oct 15, 2013

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2013 Oct 15, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 15, 2013 Oct 15, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 15, 2013 Oct 15, 2013

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 16, 2013 Oct 16, 2013

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 11, 2013 Oct 11, 2013

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 14, 2013 Oct 14, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines