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

Delete unnecessary points

Contributor ,
Nov 24, 2009 Nov 24, 2009

Copy link to clipboard

Copied

Please see this post in the main forum. I am looking for a script (if one exists) that will delete unnecessary/redundant points.

My OP:

Let's say I have a rectangle, and in addition to the corner points, there are extra points along the paths. I want to get rid of these, as they have no purpose. Object> Path> Simplify doesn't do it, nor does Object> Path> Cleanup. I can use Remove Anchor points, but I have to select them all first.

Thanks.

TOPICS
Scripting

Views

5.5K

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
Adobe
Contributor ,
Nov 28, 2009 Nov 28, 2009

Copy link to clipboard

Copied

if you`re looking for rectangle "simplify" here's a snipper that might help ... covering a wider range of shapes may take a few hours which i dun have atm ... anyway this should work with rectangle shapes ...:

(script runs over the whole pathitems collection in a document)

var Geometry2DHelper = {
    isCorner: function(pt, pt1, pt2) {
        var prnt = pt.parent;
        if((this.isVertical(pt, pt1) && this.isHorizontal(pt,pt2)) || (this.isVertical(pt, pt2) && this.isHorizontal(pt, pt1))) return true;
        var slope1 = (pt.anchor[1] - pt1.anchor[1]).toFixed(2) / (pt.anchor[0] - pt1.anchor[0]).toFixed(2);
        var slope2 = (pt.anchor[1] - pt2.anchor[1]).toFixed(2) / (pt.anchor[0] - pt2.anchor[0]).toFixed(2);
        if(slope1*slope2 == -1) return true;
        else return false;
    },
    isVertical: function(pt1, pt2) {
        if(pt1.anchor[0].toFixed(2) == pt2.anchor[0].toFixed(2)) return true;
        return false;
    },
    isHorizontal: function(pt1, pt2) {
        if(pt1.anchor[1].toFixed(2) == pt2.anchor[1].toFixed(2)) return true;
        return false;
    }
}

for(j = app.activeDocument.pathItems.length - 1; j >= 0; j--) {
    var sides = 0;
    var sel = app.activeDocument.pathItems;
    var removeArr = [];

    for(i = sel.pathPoints.length - 1; i >= 0 ; i--) {
        var pt1 = (i == sel.pathPoints.length-1) ? sel.pathPoints[0] : sel.pathPoints[i + 1];
        var pt2 = (i == 0) ? sel.pathPoints[sel.pathPoints.length-1] : sel.pathPoints[i - 1];       
        if(!Geometry2DHelper.isCorner(sel.pathPoints, pt1, pt2)) {
            removeArr.push(sel.pathPoints);           
        } else sides++;
    }
    if(sides == 4 && removeArr.length > 0) {
        for(m = removeArr.length - 1; m >= 0; m--) {
            removeArr.remove();
             app.activeDocument.pageItems.closed = true;
        }
    }
}

hope it somehow helps;

cheers;

*later edit* fixed the fact that the script was deleting paths other than rectangle ... well ... no shapes no problems or was it the other way

Votes

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
Contributor ,
Nov 29, 2009 Nov 29, 2009

Copy link to clipboard

Copied

this may work simplyfing the straight lines in a document regardless of the shape ... since my coffee is not ready yet i didn't test it, but should work:

var Geometry2DHelper = {
    getSlope: function(pt1, pt2){
        var i1 = pt1.anchor[1] - pt2.anchor[1];
        var i2 = pt1.anchor[0] - pt2.anchor[0];
        var slope = (i2 == 0) ? null : i1/i2;
        return (slope == 0) ? 0 : slope;
    },
    getConstructionPoints: function(path) {
        var pts = path.pathPoints;
        var ctspts = "";
        var x = 0;
        if(pts.length < 3) return [];
        for(i = pts.length - 1; i>=0;i--) {
            var pt1 = (i == pts.length - 1) ? pts[0] : pts[i + 1];
            var pt2 = (i == 0) ? pts[pts.length - 1] : pts[i - 1];
            var slope = (this.getSlope(pts, pt1)!=null) ? this.getSlope(pts, pt1).toFixed(2) : null;
            var slope2 = (this.getSlope(pts, pt2)!=null) ? this.getSlope(pts, pt2).toFixed(2) : null;
            if(slope != slope2) ctspts += "|" + i + "|";
        }
        return ctspts;
    },
    remove: function(path, whitelist) {
        var pts = path.pathPoints;
        if(whitelist=="") {
            for(i = pts.length - 1; i>= 0; i--) {
                if(i != pts.length - 1 && i!= 0) {pts.remove(); continue;}
            }
            return;
        }       
        for(i = pts.length - 1; i>= 0; i--) {
            if(whitelist.indexOf("|" + i + "|") < 0) {pts.remove(); }
        }
    },
    isVertical: function(pt1, pt2) {
        if(pt1.anchor[0].toFixed(1) == pt2.anchor[0].toFixed(1)) return true;
        return false;
    },
    isHorizontal: function(pt1, pt2) {
        if(pt1.anchor[1].toFixed(1) == pt2.anchor[1].toFixed(1)) return true;
        return false;
    }
}
for(j = app.activeDocument.pathItems.length - 1; j >= 0; j--) {
    var x = Geometry2DHelper.getConstructionPoints(app.activeDocument.pathItems);
    Geometry2DHelper.remove(app.activeDocument.pageItems, x); 
}

hope it helps;

cheers;

Votes

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 Beginner ,
Aug 26, 2010 Aug 26, 2010

Copy link to clipboard

Copied

Wow, thanks for the effort !

However, when I run the script on the object, it returns this error :

Screen shot 2010-08-26 at 11.39.54 PM.png

This to me is greek, so can you figure it out ?

Thanks

Votes

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
Engaged ,
Sep 05, 2011 Sep 05, 2011

Copy link to clipboard

Copied

My God, I've dreamed of it for years.
Unfortunally, it doesn't work with paths that include smooth points, only sharp with no handles; otherwise it gives same error João Faraco encountered.
Oh mighty sonicDream, hear my call from far-far russian city on the south-east shore: finish this script! Just make it ignore and skip bezier parts, or let it work only with selected points. Anyway, it is awesome. You have no idea how useful it is in my work. Bless you. Please.

Votes

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 ,
Sep 07, 2011 Sep 07, 2011

Copy link to clipboard

Copied

Actually is works with paths that include smooth points. The problem maybe relative to "Undo" operation. So I wrap it into a anonymous function and seems it's ok now.

(function (){      var Geometry2DHelper = {           getSlope: function(pt1, pt2){                var i1 = pt1.anchor[1] - pt2.anchor[1];                var i2 = pt1.anchor[0] - pt2.anchor[0];                var slope = (i2 == 0) ? null : i1/i2;                return (slope == 0) ? 0 : slope;           },           getConstructionPoints: function(path) {                var pts = path.pathPoints;                var ctspts = "";                var x = 0;                if(pts.length < 3) return [];                for(i = pts.length - 1; i>=0;i--) {                     var pt1 = (i == pts.length - 1) ? pts[0] : pts[i + 1];                     var pt2 = (i == 0) ? pts[pts.length - 1] : pts[i - 1];                     var slope = (this.getSlope(pts, pt1)!=null) ? this.getSlope(pts, pt1).toFixed(2) : null;                     var slope2 = (this.getSlope(pts, pt2)!=null) ? this.getSlope(pts, pt2).toFixed(2) : null;                     if(slope != slope2) ctspts += "|" + i + "|";                }                return ctspts;           },           remove: function(path, whitelist) {                var pts = path.pathPoints;                if(whitelist=="") {                     for(i = pts.length - 1; i>= 0; i--) {                          if(i != pts.length - 1 && i!= 0) {pts.remove(); continue;}                     }                     return;                }                       for(i = pts.length - 1; i>= 0; i--) {                     if(whitelist.indexOf("|" + i + "|") < 0) {pts.remove(); }                }           },           isVertical: function(pt1, pt2) {                if(pt1.anchor[0].toFixed(1) == pt2.anchor[0].toFixed(1)) return true;                return false;           },           isHorizontal: function(pt1, pt2) {                if(pt1.anchor[1].toFixed(1) == pt2.anchor[1].toFixed(1)) return true;                return false;           }      }      for(j = app.activeDocument.pathItems.length - 1; j >= 0; j--) {           var x = Geometry2DHelper.getConstructionPoints(app.activeDocument.pathItems[j ]);           Geometry2DHelper.remove(app.activeDocument.pageItems, x);       } })();

And I have writed a Scriptographer script to do the same thing.


document.getItems({ 
    type: Path, 
    hidden: false 
}).each(function (path){
    var curves = path.curves, i = curves.length - 1, curve, curvePre;
    for (; i > 0; i--){
        curve = curves[i];
        curvePre = curve.previous;
        curve.isLinear() && curvePre.isLinear() &&
        (curve.point2 - curve.point1).angle.toFixed(0) == 
        (curvePre.point2 - curvePre.point1).angle.toFixed(0) &&
        path.remove(i);
    }
});

Votes

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
Engaged ,
Sep 07, 2011 Sep 07, 2011

Copy link to clipboard

Copied

Cool! It really helped! It can't handle compound paths, right? Shapes go to hell, but compounds.. I can uncompound them, apply subj and then hotkey stuff back (it gives almost the same result), but can it be done with a script also?

And Scriptographer script, yes. It's still not very handy for me to use this tool (i can't change it's Enter hotkey for launching scripts and it freaks me out), but i will test it also.

Again, many thanks for this very simple but handy script. I have only one script of my dreams left

Votes

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 ,
Sep 07, 2011 Sep 07, 2011

Copy link to clipboard

Copied

The Scriptographer script can also handle compound paths, check it.

For the hotkey issue, make sure didn't select any script in the panel, then the "Enter" key come back to Illustrator.

Votes

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
New Here ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

I just used the "Simplify…" tool in Illustrator with decent results on a "pixellated" path (it's a QR code). I set it to 90º and "Straight lines"

Ridiculously, I found that Fireworks' "Simplify…" tool (amount:10) worked better than Illustrator's, it left no unnecessary points at all while the latter left a few points here and there. It was a simple path, so I just copied/pasted it, simplified it, and exported it in .ai (the clipboard doesn't work the other way around)

Votes

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 Beginner ,
Aug 08, 2014 Aug 08, 2014

Copy link to clipboard

Copied

Here you can download a script for deleting redundant points:

nvkelso/jim-heck-pinball-scripts · GitHub

Votes

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
Contributor ,
Sep 24, 2015 Sep 24, 2015

Copy link to clipboard

Copied

LATEST

Hello everyone!
I believe that the best option is: http://astutegraphics.com/software/inkscribe/

Hug.

Votes

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