Delete lines of certain length

Is there a way to make a macro that would go through a bunch of lines and delete lines of a certain length say 1.823" and leave the others?

Here is a Python script I just threw together: (517 Bytes)

***Disclaimer: I know virtually nothing about Python, but this seems to work.


That seems to work great if the lines are of an exact length say 1". Seems like my problem is some of my line segments are longer than 8 decimal places so it wont delete them even putting the target length that long. Is there any way to force the tolerance in that script? I am trying to delete unnecessary lines from a single line CNC font and the segments are weird lengths.

I told you I didn’t know what I was doing! :slight_smile:

Let me take another look. I need to use something other than GetReal I think.

You know more than I do though lol
Thanks for your time

Would it be preferable to have a range of sizes to delete? For example, find and delete all lines between 1.8" and 1.9".

Try this and see how it works: (648 Bytes)

Let me know. This is good practice for me to learn this new language.


1 Like

That is perfect! Thanks, that will save me a ton of time.

No problem. Us CNC guys need to stick together! :smiley:

I modified it a little to delete the lines I want. Very nice as it get 95% of the lines.
Delete Lines Machine Tool (5.7 KB)
It brought back memories of high school programming :smile:

My high school programming involved punch cards and a computer that filled the whole room.

1 Like

Rather late to the party here…

Attached are two scripts that allow you to select all curves that correspond to specified length criteria - greater than, less than, equal to, between… I prefer just selecting the curves rather than auto-deleting them, as that way you see what’s going on and the script can be used for other purposes than deleting. It’s easy enough to hit the Delete button once they are selected.

The first works on all forms of curves, not just lines, the second is a tiny mod of the first which should just work on line objects. Both report results on the command line.


SelCrvsByLength.rvb (3.0 KB)

SelLinesByLength.rvb (2.9 KB)

This is typical floating point fuzz stuff… Checking if x == somevalue where somevalue is the result of a calculation will often return False because floating point calculations are not exact. So, you always need to allow for a certain tolerance. I usually use the file tolerance or some specific fraction/multiple of that…

import scriptcontext as sc

if abs(x-somevalue)<tol:
    #do something