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

Overriding the UI for a position marker solution in Document / Layer

Engaged ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

I need to create a system that will allow a user to position something on a layer and use that as a marker for containing a position for me to get a position with code. My current solution is adding a "Marker" layer to the document and using that as a reference to the position (x, y) where I want the point to be added.

In the perfect World I would like to right click and use a 'Set Marker here' drop down and have them drag around a marker sprite to the position they need, from there I could reference some sort of data object in the scene to get that marker position. That's the perfect example.

Could I accomplish anything like this? Or any other design like piggy backing off another class that can be positioned in a layer like a Anchor to return the position of the class.

I will be extending this to the C++ API, I just need to know what exactly PS can do in terms of what I am looking for.

Thank you in advance!

TOPICS
Actions and scripting

Views

1.3K

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

correct answers 1 Correct answer

Community Expert , Apr 17, 2018 Apr 17, 2018

Color samplers are easier in scripting than counter tool

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Hi

How about  across hair of two guides? IMHO a better aligning possible than a pixel "marker"

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 ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Thatnks Pixxxel,

Yes, the Marker should be anything (sprite), that would just overlay the position the user needs.

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 ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

You can't get the cursor position through scripting. But it is possible to get the position of a pixel (but a pixel has a dimension!) or the position of a guide or (as a possible woraround) perhaps the user could set a color sampler and the script reads it's position and set your sprite and will remove the color sampler after 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
Engaged ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

For me, the pixel idea is a little Hacky, and it won't be able to be seen by the user on a 2k image, and it's not something that a user can move around after it's set so it won't work for me.

Looking at the current tools, thinking I could find some sort of anchor tool. I was messing around with the 'Count tool' :

Screenshot_153.png

You can see I added the numbers to the scene, this could serve it's purpose with what exactly I need, do you know if there is something else (That would work better) like this that I could access the data like that?

Or can I access the numbers positions in the scene + their value?

If I have access to that I will go with this solution.

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 ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Color samplers are easier in scripting than counter tool

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 ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Ah, did not know about that, thanks if I have any further questions I'll ask

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
Guide ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Here is some code for the counter tool...

#target photoshop;

var ref = new ActionReference();

ref.putProperty(charIDToTypeID("Prpr"),stringIDToTypeID("countClass"));

ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var desc = executeActionGet(ref);

if(desc.hasKey(stringIDToTypeID("countClass")))

var Count =desc.getList(stringIDToTypeID("countClass")).count

for(var z =0; z < Count; z++){

var X = executeActionGet(ref).getList(stringIDToTypeID("countClass")).getObjectValue(z).getUnitDoubleValue(stringIDToTypeID( "x" ));

var Y = executeActionGet(ref).getList(stringIDToTypeID("countClass")).getObjectValue(z).getUnitDoubleValue(stringIDToTypeID( "y" ));

$.writeln( "X= " + X + " Y= " +Y);

}

countClear();

function countClear(){

executeAction(stringIDToTypeID("countClear"), undefined, DialogModes.NO);

};

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 ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Thanks Merlin!

One question am I correct with saying that 'classColorSampler' will be for accessing the color sampler?

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 ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

i73  schrieb

Thanks Merlin!

One question am I correct with saying that 'classColorSampler' will be for accessing the color sampler?

No.

That's AM-code for count class.

Here is a equivalent for color samplers

// https://forums.adobe.com/thread/2307227

var orig_ruler_units = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS

message="Canvas Width=" + app.activeDocument.width.value + " ,Height=" + app.activeDocument.height.value;

for (var s=0 ,len=app.activeDocument.colorSamplers.length; s<len; s++) {

    var colorSamplerRef = app.activeDocument.colorSamplers;

    message = message + "\nColorSampler=" + s + " ,x=" + colorSamplerRef.position[0].value + " ,y=" + colorSamplerRef.position[1].value;

}

alert(message);

app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings

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
People's Champ ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

doc.countItems

Not?

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
Guide ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

This gets the position of the first colorsampler.

var mySampler = app.activeDocument.colorSamplers[0];

var xy =mySampler.position;

alert("X = " + xy[0] + " Y = " + xy[1]);

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 ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Hmmm, I don't have access to the `app.activeDocument` This is in C++ so, off the top of your head would you know if I have access to the class with the 'classColorSampler'?

My code will basically look something like this:

error = sPSActionControl->StringIDToTypeID(classColorSampler, &typeID);

error = sPSActionDescriptor->GetList(result.get(), typeID, &piActionsList);

//Iterate through the piActionsList

Just need to check if the class I am looking for is 'classColorSample`

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
People's Champ ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

As far as I can remember ColorSamples have a maximum of 4 pieces )

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 ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

10

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
People's Champ ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

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 ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

written by r-bin:

Please prove it

Yes, I did (in CC)

colorSamplers_PS_CC.png

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 ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Oh, I don't think this solution would work then, I need access to more than 10. Can I override it more than 10?

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 ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

LATEST

Unfortunately no. But with the hints of @r-bin and @SuperMerlin you can do the same with the Count Tool (DOM version)

var orig_ruler_units = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS

message="Canvas Width=" + app.activeDocument.width.value + " ,Height=" + app.activeDocument.height.value;

for (var s=0 ,len=app.activeDocument.countItems.length; s<len; s++) {

    var countItemRef = app.activeDocument.countItems;

    message = message + "\ncountItem=" + s + " ,x=" + countItemRef.position[0].value + " ,y=" + countItemRef.position[1].value;

}

alert(message);

app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings

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
Guide ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

hope this helps

var ref = new ActionReference();

ref.putProperty(charIDToTypeID("Prpr"),stringIDToTypeID("colorSamplerList"));

ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var desc = executeActionGet(ref);

if(desc.hasKey(stringIDToTypeID("colorSamplerList"))) {

var Count =desc.getList(stringIDToTypeID("colorSamplerList")).count

for(var z =0; z < Count; z++){

var X = executeActionGet(ref).getList(stringIDToTypeID("colorSamplerList")).getObjectValue(z).getObjectValue(stringIDToTypeID( "position" )).getUnitDoubleValue(stringIDToTypeID( "horizontal" ));

var Y = executeActionGet(ref).getList(stringIDToTypeID("colorSamplerList")).getObjectValue(z).getObjectValue(stringIDToTypeID( "position" )).getUnitDoubleValue(stringIDToTypeID( "vertical" ));

$.writeln( "X= " + X + " Y= " +Y);

    }

}

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