Scriptlistener code duplicate lines and duplicate variable

Participant ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

I noticed that switching from art layers to established layer mask that ScriptListner duplicates a variable

 

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc63 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref18 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idMsk = charIDToTypeID( "Msk " );
        ref18.putEnumerated( idChnl, idChnl, idMsk );
    desc63.putReference( idnull, ref18 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc63.putBoolean( idMkVs, false );
executeAction( idslct, desc63, DialogModes.NO );

 

The line   "var idChnl = charIDToTypeID( "Chnl" );" is created twice. 

Just sayin'.

TOPICS
Actions and scripting

Views

71

Likes

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
Enthusiast ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

I've noticed that a few days ago too. I wouldn't bet money it's necessarily wrong though, but it looks that way.

Maybe this is why actions and scripts are always getting slower... 😉

Likes

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 ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

LATEST

This is just result of interpreting the 'select' event by ScriptListner plugin. It receives the event object and parses its arguments sequentially, without thinking whether the resulting code is optimal or not.

In that case .putEnumerated() function takes three arguments - the class of the object, the type of the enumeration, and the value. That is, despite the fact that the object class and the enumeration type in this case have the same name, they actually describe different things. It seems logical to me that ScriptListner chose to represent them as separate variables.

 

We can optimize this code manually or use the script from the link given by @c.pfaffenbichler

 

The time spent on creating variables and getting a type value by name (using charIDToTypeID or stringIDToTypeID) is incomparably small in time with the executeAction function, so no, this does not affect the speed of scripts or actions in any way.

Likes

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 ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

Likes

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