Delete lines of certain length


#1

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?


#2

Here is a Python script I just threw together:

DeleteSpecificLength.py (517 Bytes)

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

Dan


#3

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.


#4

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.


#5

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


#6

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:

DeleteSpecificLength.py (648 Bytes)

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

Dan


#7

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


#8

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


#9

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


#10

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


#11

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.

–Mitch

SelCrvsByLength.rvb (3.0 KB)

SelLinesByLength.rvb (2.9 KB)


#12

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
tol=sc.doc.ModelAbsoluteTolerance

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

–Mitch