Skip to main content
MiaKai
Inspiring
December 15, 2017
Answered

Script to Make Brush Preset from PNG File

  • December 15, 2017
  • 1 reply
  • 3540 views

Is there a script or action to make abr brush presets from single or layered png files?

    This topic has been closed for replies.
    Correct answer Chuck Uebele

    Try this script:

    #target photoshop

    var bName = prompt ('Enter a name for the brush', 'brush 1', 'Create Brush')

    if(bName != null){

        var idMk = charIDToTypeID( "Mk  " );

            var desc5 = new ActionDescriptor();

            var idnull = charIDToTypeID( "null" );

                var ref1 = new ActionReference();

                var idBrsh = charIDToTypeID( "Brsh" );

                ref1.putClass( idBrsh );

            desc5.putReference( idnull, ref1 );

            var idUsng = charIDToTypeID( "Usng" );

                var ref2 = new ActionReference();

                var idPrpr = charIDToTypeID( "Prpr" );

                var idfsel = charIDToTypeID( "fsel" );

                ref2.putProperty( idPrpr, idfsel );

                var idDcmn = charIDToTypeID( "Dcmn" );

                var idOrdn = charIDToTypeID( "Ordn" );

                var idTrgt = charIDToTypeID( "Trgt" );

                ref2.putEnumerated( idDcmn, idOrdn, idTrgt );

            desc5.putReference( idUsng, ref2 );

            var idNm = charIDToTypeID( "Nm  " );

            desc5.putString( idNm, bName );

        executeAction( idMk, desc5, DialogModes.NO );

        }

    1 reply

    Chuck Uebele
    Community Expert
    Chuck UebeleCommunity ExpertCorrect answer
    Community Expert
    December 15, 2017

    Try this script:

    #target photoshop

    var bName = prompt ('Enter a name for the brush', 'brush 1', 'Create Brush')

    if(bName != null){

        var idMk = charIDToTypeID( "Mk  " );

            var desc5 = new ActionDescriptor();

            var idnull = charIDToTypeID( "null" );

                var ref1 = new ActionReference();

                var idBrsh = charIDToTypeID( "Brsh" );

                ref1.putClass( idBrsh );

            desc5.putReference( idnull, ref1 );

            var idUsng = charIDToTypeID( "Usng" );

                var ref2 = new ActionReference();

                var idPrpr = charIDToTypeID( "Prpr" );

                var idfsel = charIDToTypeID( "fsel" );

                ref2.putProperty( idPrpr, idfsel );

                var idDcmn = charIDToTypeID( "Dcmn" );

                var idOrdn = charIDToTypeID( "Ordn" );

                var idTrgt = charIDToTypeID( "Trgt" );

                ref2.putEnumerated( idDcmn, idOrdn, idTrgt );

            desc5.putReference( idUsng, ref2 );

            var idNm = charIDToTypeID( "Nm  " );

            desc5.putString( idNm, bName );

        executeAction( idMk, desc5, DialogModes.NO );

        }

    MiaKai
    MiaKaiAuthor
    Inspiring
    December 15, 2017

    What you wrote works perfectly if I have one PNG file open, thank-you!  If I have a file open with multiple layers, the script will make a brush out of all the layers combined.  Is there a way around that, or would that require too many complicated changes to the script?

    Chuck Uebele
    Community Expert
    Community Expert
    December 15, 2017

    So you want only the selected layer to be made into a brush? Also you want all open documents to be made into brushes?