How to select paths by size of area or length of perimeter?

I am simplifying a design in Illustrator and already ran Path > Simplify and Path > Clean Up. I have many paths with small areas or small perimeters that I would like to select and delete. I can do it programmatically with an SVG version of the design and Inkscape; but I would rather use Illustrator and see the result as I delete those areas.

Can Illustrator select paths by area or perimeter?

Answer

Install the following script with these directions, then run it and adjust the parameter 100 as needed:


#target illustrator


var doc = app.activeDocument;
var objs = doc.pageItems;
traverseSceneObjects(objs, selectByCurveLengthFactory(100));
redraw();

function selectByCurveLengthFactory( length){
    return function(item) {
        if ( item.length <=  length)
        {
           item.selected = true;
        }
    }
}


function traverseSceneObjects(pageItems, func){

    for (var iter=0 ; iter<pageItems.length; iter++ ){
        var item = pageItems[iter];
        var typename = item.typename;

        // apply action or get the subitems of object
        if (typename === "PathItem"){
            func(item);

        } else if (typename === "GroupItem") {
            traverseSceneObjects( item.pageItems, func );

        } else if (typename === "CompoundPathItem" ) {
            traverseSceneObjects( item.pathItems, func );
        }
    }
}

Attribution
Source : Link , Question Author : miguelmorin , Answer Author : miguelmorin

Leave a Comment