Close Curve issue?

Is there something screwy with rs.CloseCurve? and rs.IsCurveClosable?
I am not getting any luck trying to close crvs using python. Even the example code under those commands is not doing anything.
When I just run CloseCrv command in rhino the curve actually closes.
I tried it on all kinds of different types of curves.
I’ve even long-form wrote something that checks start and end point and checks for the gap between vs the overall lengths of the curve and tries to close it then. No dice. :no_mouth:
Tolerance also is not doing anything, even if you make it a super tiny number.

Seems to be working here with a quick test - can you post some code and a curve where it is not working for you?

–Mitch

import rhinoscriptsyntax as rs 

#ids = rs.ObjectsByGroup()
ids = rs.GetObjects('Select objects', filter = 0, group=True, preselect = True) # 512 annotation | 4 Crv
# Check if we got anything selected
if not ids: 
    print 'Nothing was selected. Exiting Command'


# Clean up duplicate data in the list, make it set them back to the list
removeDup = list(set(ids))
for crv in removeDup:
    if not rs.IsCurveClosed(crv) and rs.IsCurveClosable(crv):
        print 'I should close this'
        rs.CloseCurve(crv)
        for s in range(3):
            print 'I am trying to simplify this'
            rs.SimplifyCurve(crv)

@Helvetosaur
This is a spinet of code I have as part of a larger script. That’s why I have removeDup I actually have list flattening before it goes to remove dup as well in the bigger script.
I pulled it out of the script to just run on simple object selection.
And when I run it on anything, it does nothing at all…
Attaching a clean rhino file with just a couple of random crvs in it as well.
RandomLines.3dm (25.5 KB)

I need to close the crvs and I’ll probably throw an object color change in there just so the user knows what did get closed, and I do need SimplifyCurve to follow. As the final crvs will be used to cut on a plasma machine. And sometimes the importer throws the crvs out when they are not simplified properly. On some objects, we have to do the simplification several times. That’s why there is a range for 3 tries.

Help is much appreciated!

Edit: I am on version (6.9.18271.20591, 09/28/2018) if that is important for this conversation

You are expecting rs.CloseCurve() to act like Rhino’s native CloseCrv command. It doesn’t do the same thing.

Here’s what Rhino’s CloseCrv command does:
image

rs.CloseCurve() only will move the curve’s endpoints to close the curve if they are within tolerance - it does not add a straight line to close like CloseCrv does if they are not within tolerance.

image

As the curves you posted are much further apart than the file absolute tolerance and you did not supply an optional tolerance argument in CloseCrv() that is larger than the opening distance, the curves will not be closed.

If you are looking for a function that exactly mimics native CloseCrv, you will need to write your own with a few more lines of code… or just script rs.Command("CloseCrv")

1 Like

Looks like I miss understood the tolerance. I thought it meant that the 2 points cannot be further then X value, and if they are go ahead and close it.
So when I was adding the tolerance to my script I was using numbers like 0.0001. Thinking that, if any 2 points are further then that distance then it will close.
Looks like it might be the search distance around start/end points.
I think I am going to just write something that checks the gap, if it’s so small that moving the point would work. I’ll run the CloseCurve with tolerance value, and if the gap is too big then I could make a straight segment and join everything up after, just like the regular command does.
Thanks for the suggestion. :slight_smile: I’ll give it another stab.

Hi Mitch @Helvetosaur

Re-opening the thread b/c while I did learn from your response (thank you!) it seems like adding a larger tolerance should clean up an issue like mine:

formatted script below

import rhinoscriptsyntax as rs

origCrv = rs.GetObject("Select curve", preselect=True)
print (origCrv)
closedCrv = rs.CloseCurve(origCrv, 3) #Won't work beyond 1-1/4" gap in open crv
rs.SelectObject(closedCrv)
print (closedCrv)
rs.ObjectLayer(closedCrv, "closedCrvs")
rs.DeleteObject(origCrv)

No matter what tolerance I give it, I can’t get this crv to close – and I made it so no additional segment needs to be created by the script.

Thx
Alan

Ah, figured it out by reading this comment:

from this thread: