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

Script to count brush strokes

Community Beginner ,
Jan 06, 2020 Jan 06, 2020

I was wondering if someone could point me to some scripting that counted something on a layer.  I have layers where I put colored dots on an item. Each layer gets it's own dot color.  I haven't been able to find any previous thread showing anything similar.

 

thanks!

TOPICS
Actions and scripting
1.9K
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

correct answers 1 Correct answer

Community Expert , Jan 06, 2020 Jan 06, 2020

If you want to draw a path and have a dot drawn on each anchor point, you can try this script. You can change the color by editing the colors at the top of the script, and you can edit the size of the dots also - make sure you're working in pixels units.

#target photoshop
var red = 255;
var green = 0;
var blue = 0;
var size = 20;
var doc = activeDocument;
var ptArray = [];
var thePath = doc.pathItems[0].subPathItems[0];
var nodeNum = doc.pathItems[0].subPathItems[0].pathPoints.length;
for(var i=
...
Translate
Adobe
Mentor ,
Jan 06, 2020 Jan 06, 2020

Photoshop does not give scripts access to image pixels.

That is you can calculate the number of points either by indirect methods (they can be selected by color, but I don’t know the way how to divide the selection into separate objects), or save each layer as an image and give it to scripts / programs for processing outside of Photoshop.

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 ,
Jan 06, 2020 Jan 06, 2020
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 ,
Jan 06, 2020 Jan 06, 2020

I saw Count Tool but never used and never checked how to use it. It's adding number of clicks indeed 🙂

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 ,
Jan 06, 2020 Jan 06, 2020

If I understand correctly: each dot is on a separate layer, then you can count how many layers there are. To determine if a dot is on the layer, you could check the layer bounds size, and if it is over the dot size, you could exclude that layer.

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 Beginner ,
Jan 06, 2020 Jan 06, 2020

I think I found a workaround, and maybe someone can help me.  

I found this: 

 

 

var doc=activeDocument;
var firstpath=doc.pathItems[0]; // Assing Path 
firstpath.select(); // Select Path
var pathpointcount = firstpath.subPathItems[0].pathPoints.length;
alert (pathpointcount);

 

 

 

This allows me to count the number of anchor points on a path. If I turn off spacing on the brush tool it will only stroke the anchor points and not the path, which actually gives me what I want. A way to both add dots and then count them.  I'd need a brush script that just allows me to select a color (say red) a pixel size and then turn off spacing.

 

I'm a bit confused however, as all the code examples I've seen for path stroking, the example draws the path, and I just want to draw the path myself and stroke it using a brush with no spacing. 

 

Can someone help?

 

Also, this site is extremely useful!

 

http://creativetuts.com/photoshop-script-code-snippet-archive/

 

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 ,
Jan 06, 2020 Jan 06, 2020

If you want to draw a path and have a dot drawn on each anchor point, you can try this script. You can change the color by editing the colors at the top of the script, and you can edit the size of the dots also - make sure you're working in pixels units.

#target photoshop
var red = 255;
var green = 0;
var blue = 0;
var size = 20;
var doc = activeDocument;
var ptArray = [];
var thePath = doc.pathItems[0].subPathItems[0];
var nodeNum = doc.pathItems[0].subPathItems[0].pathPoints.length;
for(var i=0;i<nodeNum;i++){
    ptArray.push(thePath.pathPoints[i].anchor)
    makeDot (ptArray[i][0], ptArray[i][1])
    }
alert('There are '+nodeNum+' dots.')

function makeDot(dotX,dotY){
    var idMk = charIDToTypeID( "Mk  " );
        var desc12 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref2 = new ActionReference();
            var idcontentLayer = stringIDToTypeID( "contentLayer" );
            ref2.putClass( idcontentLayer );
        desc12.putReference( idnull, ref2 );
        var idUsng = charIDToTypeID( "Usng" );
            var desc13 = new ActionDescriptor();
            var idType = charIDToTypeID( "Type" );
                var desc14 = new ActionDescriptor();
                var idClr = charIDToTypeID( "Clr " );
                    var desc15 = new ActionDescriptor();
                    var idRd = charIDToTypeID( "Rd  " );
                    desc15.putDouble( idRd, red );
                    var idGrn = charIDToTypeID( "Grn " );
                    desc15.putDouble( idGrn, green );
                    var idBl = charIDToTypeID( "Bl  " );
                    desc15.putDouble( idBl, blue );
                var idRGBC = charIDToTypeID( "RGBC" );
                desc14.putObject( idClr, idRGBC, desc15 );
            var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
            desc13.putObject( idType, idsolidColorLayer, desc14 );
            var idShp = charIDToTypeID( "Shp " );
                var desc16 = new ActionDescriptor();
                var idunitValueQuadVersion = stringIDToTypeID( "unitValueQuadVersion" );
                desc16.putInteger( idunitValueQuadVersion, 1 );
                var idTop = charIDToTypeID( "Top " );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc16.putUnitDouble( idTop, idPxl, dotY-size/2 );
                var idLeft = charIDToTypeID( "Left" );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc16.putUnitDouble( idLeft, idPxl, dotX-size/2 );
                var idBtom = charIDToTypeID( "Btom" );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc16.putUnitDouble( idBtom, idPxl, dotY+size/2 );
                var idRght = charIDToTypeID( "Rght" );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc16.putUnitDouble( idRght, idPxl, dotX+size/2 );
            var idElps = charIDToTypeID( "Elps" );
            desc13.putObject( idShp, idElps, desc16 );
            var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
                var desc17 = new ActionDescriptor();
                var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
                desc17.putInteger( idstrokeStyleVersion, 2 );
                var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );
                desc17.putBoolean( idstrokeEnabled, false );
                var idfillEnabled = stringIDToTypeID( "fillEnabled" );
                desc17.putBoolean( idfillEnabled, true );
                var idstrokeStyleLineWidth = stringIDToTypeID( "strokeStyleLineWidth" );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc17.putUnitDouble( idstrokeStyleLineWidth, idPxl, 1.000000 );
                var idstrokeStyleLineDashOffset = stringIDToTypeID( "strokeStyleLineDashOffset" );
                var idPnt = charIDToTypeID( "#Pnt" );
                desc17.putUnitDouble( idstrokeStyleLineDashOffset, idPnt, 0.000000 );
                var idstrokeStyleMiterLimit = stringIDToTypeID( "strokeStyleMiterLimit" );
                desc17.putDouble( idstrokeStyleMiterLimit, 100.000000 );
                var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
                var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
                var idstrokeStyleButtCap = stringIDToTypeID( "strokeStyleButtCap" );
                desc17.putEnumerated( idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleButtCap );
                var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
                var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
                var idstrokeStyleMiterJoin = stringIDToTypeID( "strokeStyleMiterJoin" );
                desc17.putEnumerated( idstrokeStyleLineJoinType, idstrokeStyleLineJoinType, idstrokeStyleMiterJoin );
                var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
                var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
                var idstrokeStyleAlignInside = stringIDToTypeID( "strokeStyleAlignInside" );
                desc17.putEnumerated( idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignInside );
                var idstrokeStyleScaleLock = stringIDToTypeID( "strokeStyleScaleLock" );
                desc17.putBoolean( idstrokeStyleScaleLock, false );
                var idstrokeStyleStrokeAdjust = stringIDToTypeID( "strokeStyleStrokeAdjust" );
                desc17.putBoolean( idstrokeStyleStrokeAdjust, false );
                var idstrokeStyleLineDashSet = stringIDToTypeID( "strokeStyleLineDashSet" );
                    var list2 = new ActionList();
                desc17.putList( idstrokeStyleLineDashSet, list2 );
                var idstrokeStyleBlendMode = stringIDToTypeID( "strokeStyleBlendMode" );
                var idBlnM = charIDToTypeID( "BlnM" );
                var idNrml = charIDToTypeID( "Nrml" );
                desc17.putEnumerated( idstrokeStyleBlendMode, idBlnM, idNrml );
                var idstrokeStyleOpacity = stringIDToTypeID( "strokeStyleOpacity" );
                var idPrc = charIDToTypeID( "#Prc" );
                desc17.putUnitDouble( idstrokeStyleOpacity, idPrc, 100.000000 );
                var idstrokeStyleContent = stringIDToTypeID( "strokeStyleContent" );
                    var desc18 = new ActionDescriptor();
                    var idClr = charIDToTypeID( "Clr " );
                        var desc19 = new ActionDescriptor();
                        var idRd = charIDToTypeID( "Rd  " );
                        desc19.putDouble( idRd, 255.000000 );
                        var idGrn = charIDToTypeID( "Grn " );
                        desc19.putDouble( idGrn, 0.000000 );
                        var idBl = charIDToTypeID( "Bl  " );
                        desc19.putDouble( idBl, 0.000000 );
                    var idRGBC = charIDToTypeID( "RGBC" );
                    desc18.putObject( idClr, idRGBC, desc19 );
                var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
                desc17.putObject( idstrokeStyleContent, idsolidColorLayer, desc18 );
                var idstrokeStyleResolution = stringIDToTypeID( "strokeStyleResolution" );
                desc17.putDouble( idstrokeStyleResolution, 72.000000 );
            var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
            desc13.putObject( idstrokeStyle, idstrokeStyle, desc17 );
        var idcontentLayer = stringIDToTypeID( "contentLayer" );
        desc12.putObject( idUsng, idcontentLayer, desc13 );
        var idLyrI = charIDToTypeID( "LyrI" );
        desc12.putInteger( idLyrI, 7 );
    executeAction( idMk, desc12, DialogModes.NO );    
    }
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 ,
Jan 07, 2020 Jan 07, 2020

Too bad forum developers still didn't give more space for codes 😞

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 Beginner ,
Jan 07, 2020 Jan 07, 2020

thank you! One last question. Is there any way to keep those shapes all on one layer?

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 ,
Jan 07, 2020 Jan 07, 2020
LATEST

Try this. Just make sure you're on your path layer, when you run the script.

#target photoshop
var red = 255;
var green = 0;
var blue = 0;
var size = 20;

var origC = new SolidColor();
origC=foregroundColor;
  
var doc = activeDocument;
var pathLayer = doc.activeLayer;
doc.artLayers.add();
var pixelLayer = doc.activeLayer;

var foregroundC = new SolidColor();
    foregroundC.rgb.red = red;
	foregroundC.rgb.green = green;
	foregroundC.rgb.blue = blue;
	foregroundColor = foregroundC;
    
doc.activeLayer = pathLayer;
var ptArray = [];
var thePath = doc.pathItems[0].subPathItems[0];
var nodeNum = doc.pathItems[0].subPathItems[0].pathPoints.length;

for(var i=0;i<nodeNum;i++){
    ptArray.push(thePath.pathPoints[i].anchor)
    }
doc.activeLayer = pixelLayer;
for(var i=0;i<nodeNum;i++){
    makePixelDot (ptArray[i][0], ptArray[i][1])
    }

alert('There are '+nodeNum+' dots.')

foregroundColor = origC;

function makeLayer(){
    var idMk = charIDToTypeID( "Mk  " );
        var desc10 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref4 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            ref4.putClass( idLyr );
        desc10.putReference( idnull, ref4 );
        var idLyrI = charIDToTypeID( "LyrI" );
        desc10.putInteger( idLyrI, 9 );
    executeAction( idMk, desc10, DialogModes.NO );   
    }

function makePixelDot(dotX,dotY){
    var idDraw = charIDToTypeID( "Draw" );
        var desc6 = new ActionDescriptor();
        var idShp = charIDToTypeID( "Shp " );
            var desc7 = new ActionDescriptor();
            var idunitValueQuadVersion = stringIDToTypeID( "unitValueQuadVersion" );
            desc7.putInteger( idunitValueQuadVersion, 1 );
            var idTop = charIDToTypeID( "Top " );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc7.putUnitDouble( idTop, idPxl, dotY-size/2 );
            var idLeft = charIDToTypeID( "Left" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc7.putUnitDouble( idLeft, idPxl, dotX-size/2 );
            var idBtom = charIDToTypeID( "Btom" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc7.putUnitDouble( idBtom, idPxl, dotY+size/2 );
            var idRght = charIDToTypeID( "Rght" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc7.putUnitDouble( idRght, idPxl, dotX+size/2 );
        var idElps = charIDToTypeID( "Elps" );
        desc6.putObject( idShp, idElps, desc7 );
        var idAntA = charIDToTypeID( "AntA" );
        desc6.putBoolean( idAntA, true );
    executeAction( idDraw, desc6, DialogModes.NO );    
    }
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