Skip to main content
Kreatifart
Known Participant
September 7, 2023
Answered

Selecting a Single Point of a Script

  • September 7, 2023
  • 3 replies
  • 781 views

There are single points in the drawings from Autocad. Is there a script to select only these single points?

 

Thank you!

This topic has been closed for replies.
Correct answer femkeblanco

Not tested. Save before trying.

var paths = app.activeDocument.pathItems;
for (var i = paths.length - 1; i > - 1; i--) {
    if (paths[i].pathPoints.length <= 2) {
        var ps = paths[i].pathPoints;
        if (ps[0].anchor.toString() == ps[1].anchor.toString() && 
            ps[0].rightDirection.toString() == ps[1].rightDirection.toString() && 
            ps[0].leftDirection.toString() == ps[1].leftDirection.toString()) {
                paths[i].remove();
        }
    }
}

3 replies

femkeblanco
femkeblancoCorrect answer
Legend
September 7, 2023

Not tested. Save before trying.

var paths = app.activeDocument.pathItems;
for (var i = paths.length - 1; i > - 1; i--) {
    if (paths[i].pathPoints.length <= 2) {
        var ps = paths[i].pathPoints;
        if (ps[0].anchor.toString() == ps[1].anchor.toString() && 
            ps[0].rightDirection.toString() == ps[1].rightDirection.toString() && 
            ps[0].leftDirection.toString() == ps[1].leftDirection.toString()) {
                paths[i].remove();
        }
    }
}
Kreatifart
Known Participant
September 7, 2023

This script perfect working cleared all single points. Thank You... 

Brad @ Roaring Mouse
Community Expert
Community Expert
September 7, 2023

I don't think they are single points; especially the one on the right since Illustrator will not display a stroke on a single point like that. Try drag one with the direct select tool and see what happens. There may be two connected points on top of each other, so in essence a line segment (which makes sense for Autocad). In which case the Clean Up tool will not find them.

Kreatifart
Known Participant
September 7, 2023

I checked, single point.

Monika Gause
Community Expert
Community Expert
September 7, 2023

How did you check? In the Document info panel?

Monika Gause
Community Expert
Community Expert
September 7, 2023

THis is even built into Illustrator. You could check out Select > Object > Single anchor points. 

Or use the Object > Path > Clean up function.

Kreatifart
Known Participant
September 7, 2023

Thank but "Object > Path > Clean up function" I tried but it didn't work. I couldn't find "Select > Object > Single anchor points". Is there a different method?