Skip to main content
Mohamed Hameed21513110
Inspiring
May 8, 2024
Answered

modify this code to (addtoselection)

  • May 8, 2024
  • 4 replies
  • 504 views
Hello everyone and greetings to you
I found this code, which is for creating a selection for the selected layer
I want to modify the code to add another selection to the current selection
Meaning that I already have a layer selected and I want to select another layer next to the current selection
How can we help with this?
Thank you


selectActivePixels
()
function cID (inVal) { return charIDToTypeID(inVal);}
function sID (inVal) { return stringIDToTypeID(inVal);}

function selectActivePixels(){
    var desc15 = new ActionDescriptor();
    var ref8 = new ActionReference();
    ref8.putProperty( cID( "Chnl" ), cID( "fsel" ) );
    desc15.putReference( cID( "null" ), ref8 );
    var ref9 = new ActionReference();
    ref9.putEnumerated( cID( "Chnl" ), cID( "Chnl" ), cID( "Trsp" ) );
    desc15.putReference( cID( "T   " ), ref9 );
    executeAction( cID( "setd" ), desc15, DialogModes.NO );
}
This topic has been closed for replies.
Correct answer Stephen Marsh

I'm sure that @r-bin has set you right, this is what I would have done using cleaned ScriptingListener code for the new selected/active layer:

 

addLayerSelToSel();

function addLayerSelToSel() {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	var reference2 = new ActionReference();
	reference.putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "transparencyEnum" ));
	descriptor.putReference( s2t( "null" ), reference );
	reference2.putProperty( s2t( "channel" ), s2t( "selection" ));
	descriptor.putReference( s2t( "to" ), reference2 );
	executeAction( s2t( "add" ), descriptor, DialogModes.NO );
}

 

 

4 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
May 9, 2024

I'm sure that @r-bin has set you right, this is what I would have done using cleaned ScriptingListener code for the new selected/active layer:

 

addLayerSelToSel();

function addLayerSelToSel() {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	var reference2 = new ActionReference();
	reference.putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "transparencyEnum" ));
	descriptor.putReference( s2t( "null" ), reference );
	reference2.putProperty( s2t( "channel" ), s2t( "selection" ));
	descriptor.putReference( s2t( "to" ), reference2 );
	executeAction( s2t( "add" ), descriptor, DialogModes.NO );
}

 

 

Mohamed Hameed21513110
Inspiring
May 8, 2024
Well, I discovered where the problem was and solved it
Thank you for your interest in the matter

function
cID (inVal) { return charIDToTypeID(inVal);}
function sID (inVal) { return stringIDToTypeID(inVal);}

function intersectActivePixels()
{
    var desc18 = new ActionDescriptor();
    var ref13 = new ActionReference();
    ref13.putEnumerated( cID( "Chnl" ), cID( "Chnl" ), cID( "Trsp" ) );
    desc18.putReference( cID( "null" ), ref13 );
    var ref14 = new ActionReference();
    ref14.putProperty( cID( "Chnl" ), cID( "fsel" ) );
    desc18.putReference( cID( "With" ), ref14 );
    executeAction( cID( "Add " ), desc18, DialogModes.NO );
}

intersectActivePixels()
Legend
May 8, 2024

Where you found it is the intersectActivePixels() function.

Replace cID("Intr") with cID("Add ").

Stephen Marsh
Community Expert
Community Expert
May 8, 2024

Please post before and after screenshots of the layers panel to clearly illustrate the layer kinds, visibility and positions.

Mohamed Hameed21513110
Inspiring
May 8, 2024


In the first image, a layer selection was created using code
I want to modify the code to add another selection next to the current selection that exists when selecting another layer