Magic Wand, Contiguous toggle button?

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

Mcquiff

Magic Wand, Contiguous toggle button?

Post by Mcquiff »

When using the magic wand tool, I would like to be able to switch between contiguous and non contiguous using a keyboard shortcut. Now as it appears to be not to set a keyboard shortcut I need to be able turn off when its on and on when its off, so that once that script is made I can select a hot key to switch it on and off.

Any Suggestions

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

pfaffenbichler

Magic Wand, Contiguous toggle button?

Post by pfaffenbichler »

Interesting problem.
With some code by Mike and Paul it is no problem to get the currentToolOptions but I have so far failed to feed them back (in unedited and edited form) to the tool.
txuku

Magic Wand, Contiguous toggle button?

Post by txuku »

Bonjour

I create a tool preset - Outil Baguette magique 1 :




And I call it in the script :

Code: Select all//Outil "Baguette magique" ou bien "Selection rapide"
// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc29 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref25 = new ActionReference();
        var idmagicWandTool = stringIDToTypeID( "magicWandTool" );
        ref25.putClass( idmagicWandTool );
    desc29.putReference( idnull, ref25 );
    var iddontRecord = stringIDToTypeID( "dontRecord" );
    desc29.putBoolean( iddontRecord, true );
    var idforceNotify = stringIDToTypeID( "forceNotify" );
    desc29.putBoolean( idforceNotify, true );
executeAction( idslct, desc29, DialogModes.NO );

//L outil predefini que j ai cree avec "Baguette magique"
// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc30 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref26 = new ActionReference();
        var idtoolPreset = stringIDToTypeID( "toolPreset" );
        ref26.putName( idtoolPreset, "Outil Baguette magique 1" );//appel de mon outil
    desc30.putReference( idnull, ref26 );
executeAction( idslct, desc30, DialogModes.NO );
Paul MR

Magic Wand, Contiguous toggle button?

Post by Paul MR »

To toggle you could create two presets, one for contiguous and one for noncontiguous and then put the preset names in the switch statement so it can then toggle.

Code: Select allswitch(isMagicWandContiguous()){
    case true : selectToolPreset('Your preset name here'); break;
    case false : selectToolPreset('Your preset name here'); break;
    case undefined : selectTool('magicWandTool'); break;
};
function isMagicWandContiguous(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
var desc = executeActionGet(ref);
var cTool = typeIDToStringID(desc.getEnumerationType(stringIDToTypeID('tool')));
if(cTool == 'magicWandTool'){
var contiguous = desc.getObjectValue(stringIDToTypeID('currentToolOptions')).getBoolean (stringIDToTypeID('contiguous'));
return contiguous;
}else{
    return undefined;
    }
};
function selectTool(tool) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( app.stringIDToTypeID(tool) );
desc.putReference( app.charIDToTypeID('null'), ref );
executeAction( app.charIDToTypeID('slct'), desc, DialogModes.NO );
};
function selectToolPreset(TOOL) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( stringIDToTypeID('toolPreset'),TOOL );
desc.putReference( charIDToTypeID('null'), ref );
executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
};

pfaffenbichler

Magic Wand, Contiguous toggle button?

Post by pfaffenbichler »

But will presets honor the current Tolerance-setting?

Do you have an idea how to set the currentToolOptions with Action Manager code? I’m stumped so far.

Edit: Did some searching and in an older thread Mike voiced the suspicion that currentToolOptions might be read only, so that would mean that approach is not feasible anyway.
Paul MR

Magic Wand, Contiguous toggle button?

Post by Paul MR »

It should be posible to just toggle the feature.. see
bb/viewtopic.php?f=9&t=4903&p=23208#p23208
This didn't work om my windows system though.

I think Mike has been doing some work on this type of code as well.
Mike Hale

Magic Wand, Contiguous toggle button?

Post by Mike Hale »

Paul MR wrote:I think Mike has been doing some work on this type of code as well.
Yes, I have spent a lot of time trying to find a way to set tool options without using presets. Nothing I have tried or seen posted anywhere works.

I had hoped that when John Nack suggested task based panels a few years ago that Photoshop would add support for working with tool options. They have added being able to get the current tool options( at least I don't remember that key in the app descriptor in earlier versions ). Perhaps some day we will also be able to set those options.

But until that day comes I really think that presets are the only work-around we have.
pfaffenbichler

Magic Wand, Contiguous toggle button?

Post by pfaffenbichler »

Thanks for the feedback on this.
Mcquiff

Magic Wand, Contiguous toggle button?

Post by Mcquiff »

Thanks for all the input below, I gave the code below a go but that didn't seam to work for me.

Looks like I might have to stick to using the tick box.

Many Thanks

Matt
Paul MR wrote:To toggle you could create two presets, one for contiguous and one for noncontiguous and then put the preset names in the switch statement so it can then toggle.

Code: Select allswitch(isMagicWandContiguous()){
    case true : selectToolPreset('Your preset name here'); break;
    case false : selectToolPreset('Your preset name here'); break;
    case undefined : selectTool('magicWandTool'); break;
};
function isMagicWandContiguous(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
var desc = executeActionGet(ref);
var cTool = typeIDToStringID(desc.getEnumerationType(stringIDToTypeID('tool')));
if(cTool == 'magicWandTool'){
var contiguous = desc.getObjectValue(stringIDToTypeID('currentToolOptions')).getBoolean (stringIDToTypeID('contiguous'));
return contiguous;
}else{
    return undefined;
    }
};
function selectTool(tool) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( app.stringIDToTypeID(tool) );
desc.putReference( app.charIDToTypeID('null'), ref );
executeAction( app.charIDToTypeID('slct'), desc, DialogModes.NO );
};
function selectToolPreset(TOOL) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( stringIDToTypeID('toolPreset'),TOOL );
desc.putReference( charIDToTypeID('null'), ref );
executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
};