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

Test if guides visible?

Contributor ,
Jul 18, 2018 Jul 18, 2018

Hello,

Is there a way to test in Javascript if document's guides are visible or not (shown or hidden by user)?

Thank you.

TOPICS
Actions and scripting
1.3K
Translate
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 ,
Jul 18, 2018 Jul 18, 2018

#target photoshop

if (app.documents.length > 0) {

var ref = new ActionReference();

ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("guidesVisibility"));

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

var docDesc = executeActionGet(ref);

alert (docDesc.getBoolean(stringIDToTypeID("guidesVisibility")));

};

Translate
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
Contributor ,
Jul 18, 2018 Jul 18, 2018

Thank you for your reply.

Unfortunately, line var docDesc = executeActionGet(ref); throws an error, telling this action isn't available.

Photoshop 13.0 (CS6) on Mac.

Translate
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 ,
Jul 18, 2018 Jul 18, 2018

Quite frankly I am not going to install an obsolete Photoshop version to test this, but in 19.1.5 it works fine.

Does removing the line

ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("guidesVisibility"));

make a difference?

Could you post a screenshot of the Script in ESTK?

Translate
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
LEGEND ,
Jul 18, 2018 Jul 18, 2018

By the way it won't do job on CS6 EXTENDED too and with a case mentioned but is simplified to get submenus items, however prototype looks more complex now. Before you had to type .get(8).get(18).get(0) while now .get(8, 18, 0). It wouldn't work in CS6 EXTENDED too, but with generator in CC 2018 there is chance to use .getString(sTT('checked')). I hacked 'File / Generate / Image Assets' and I was able to use 'checked' with that item, but not with other submenus.

function sTT(v) {return stringIDToTypeID(v)}

(ref = new ActionReference()).putProperty(sTT('property'), sTT('menuBarInfo'))

ref.putEnumerated(sTT('application'), sTT('ordinal'), sTT('tergetEnum'))

Object.prototype.get = function() {

    for(str = '', i = 0; i < arguments.length; i++) {

          str += ".getList(sTT('submenu')).getObjectValue(arguments[" + i + "])"

    }

    return eval('this' + str)

}

executeActionGet(ref).getObjectValue(sTT('menuBarInfo')).get(8, 18, 0).getString(sTT('enabled'))

Translate
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 ,
Jul 18, 2018 Jul 18, 2018

Does not work if the user turned off the guides through View-> Show-> Guides

P.S.. And Kukurykus, too

Translate
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 ,
Jul 18, 2018 Jul 18, 2018

You’re right.

I had only tested with hiding them using cmd-H, apparently that did not do the issue justice.

Translate
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
LEGEND ,
Jul 18, 2018 Jul 18, 2018

True, I wrote originally 'in some specific case though', but then deleted it and went for more tests but forgot to repost that

Translate
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
Contributor ,
Jul 18, 2018 Jul 18, 2018

Thanks all.

Maybe my Photoshop is too old, none of the posted scripts works

Capture d’écran 2018-07-18 à 15.47.43.jpg

Capture d’écran 2018-07-18 à 15.47.15.jpg

Translate
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 ,
Jul 18, 2018 Jul 18, 2018

Can you run the below code and does it list »guidesVisibility« at all?

#target photoshop

var ref = new ActionReference();

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

var docDesc = executeActionGet(ref);

checkDesc2(docDesc);

////// based on code by michael l hale //////

function checkDesc2 (theDesc) {

var c = theDesc.count;

var str = '';

for(var i=0;i<c;i++){ //enumerate descriptor's keys

  str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';

  };

alert("desc\n\n"+str);

};

////// check //////

function getValues (theDesc, theNumber) {

switch (theDesc.getType(theDesc.getKey(theNumber))) {

case DescValueType.ALIASTYPE:

return theDesc.getPath(theDesc.getKey(theNumber));

break;

case DescValueType.BOOLEANTYPE:

return theDesc.getBoolean(theDesc.getKey(theNumber));

break;

case DescValueType.CLASSTYPE:

return theDesc.getClass(theDesc.getKey(theNumber));

break;

case DescValueType.DOUBLETYPE:

return theDesc.getDouble(theDesc.getKey(theNumber));

break;

case DescValueType.ENUMERATEDTYPE:

return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));

break;

case DescValueType.INTEGERTYPE:

return theDesc.getInteger(theDesc.getKey(theNumber));

break;

case DescValueType.LISTTYPE:

return theDesc.getList(theDesc.getKey(theNumber));

break;

case DescValueType.OBJECTTYPE:

return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));

break;

case DescValueType.RAWTYPE:

return theDesc.getReference(theDesc.getData(theNumber));

break;

case DescValueType.REFERENCETYPE:

return theDesc.getReference(theDesc.getKey(theNumber));

break;

case DescValueType.STRINGTYPE:

return theDesc.getString(theDesc.getKey(theNumber));

break;

case DescValueType.UNITDOUBLE:

return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));

break;

default:

break;

};

};

Translate
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
LEGEND ,
Jul 18, 2018 Jul 18, 2018

I tried your previous code that works in CC 2018. In CS6 EXTENDED that does't work indeed. Current one works of course

Translate
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
LEGEND ,
Jul 18, 2018 Jul 18, 2018

Another version for CC 2018:

function sTT(v) {return stringIDToTypeID(v)}

(ref = new ActionReference()).putProperty(sTT('property'), sTT('menuBarInfo'))

ref.putEnumerated(sTT('application'), sTT('ordinal'), sTT('tergetEnum'))

Object.prototype.get = function(v) {return this.getList(sTT('submenu')).getObjectValue(v)}

executeActionGet(ref).getObjectValue(sTT('menuBarInfo')).get(8).get(18).get(0).getString(sTT('enabled'))

Translate
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 ,
Jul 18, 2018 Jul 18, 2018

And why do you need to know the guides are visible or not?

On CS6 it's impossible to know.

You can use the function to force the visibility of the guides.

Works in CS6 and CC2018.

show_guides()

function show_guides()

    {

    try {

        var d1 = new ActionDescriptor();

        var d2 = new ActionDescriptor();

        d2.putUnitDouble( charIDToTypeID( "Pstn" ), charIDToTypeID( "#Prc" ), 200 );

        d2.putEnumerated( charIDToTypeID( "Ornt" ), charIDToTypeID( "Ornt" ), charIDToTypeID( "Hrzn" ) );

        d1.putObject( charIDToTypeID( "Nw  " ), charIDToTypeID( "Gd  " ), d2 );

        executeAction( charIDToTypeID( "Mk  " ), d1, DialogModes.NO );

        app.activeDocument.guides[app.activeDocument.guides.length-1].remove();

        }

    catch (e) { alert(e); throw(e); }

    }

Translate
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
Contributor ,
Jul 18, 2018 Jul 18, 2018
LATEST

, your function show_guides() works fine.

Translate
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