Need a script looked at

I’ve got a script I’m wondering if someone can take a look at to figure out why it might be acting odd. I know it’s a pain trying to figure out someone else’s code but I’ve been banging my head against the wall on this for quite a while.

I’m working on a tool for “rationalizing” freeform curves for pipe bending. Vaguely like “Convert” except that I feed it a library of curve specs from an Excel file since with pipe bending you want to use as few different bends as possible. I have the basic fitting working and am now dealing with persistence and tweaking the result. Anyway, that’s the background.

So the Rhino file has a magenta freeform ‘source’ curve and a set of curves that were the result of a run of the rationalization script. If you run the file “”, it sets up the event handling so that I can edit the source curve and have the output readjusted to fit. It doesn’t totally regenerate it since that can take hours to evaluate all the possibilities, it just moves the arcs to follow the new curve as best it can.

If you try to run it and get an error about Office something, just comment out that import it’s not needed.

The specific issue I need help with is, after running the load script I can move the source curve around and the output follows, great…the weird thing is you will notice if you nudge it around the
output will wiggle and move. Of course the event handling should be smarter to know if the curve was simply moved and not ‘regenerate’ from scratch, but nonetheless it shouldn’t do that. I suppose it’s possible the problem is the result of quantum-scale rounding differences adding
up to sending the curve sections shooting off into space, but it doesn’t really look like it. It seems to act wonkiest when the curve is moved around the origin and seems to ‘settle down’ in one state as it’s moved further away, which might imply I’m doing something dumb not accounting
for coordinates being positive vs negative, but the math is all vectors and transforms(which frankly I’m not so great at.) It appears to give the same (correct or not) result if I drag the curve to a location vs nudging, so that would maybe argue against the problem being that it’s
using data from the previous state of the curve. If there’s anything anyone can see to help me zero in on the issue that would be great. (212 Bytes) (32.8 KB)

curve fitting test.3dm (218.7 KB)


Hi Jim,

I took a (very quick) look, I haven’t pinpointed the problem but I think your intuition is correct that the issue is in “all the vectors and transforms.” Regardless of the specifics of your optimization process, it should give the same output for a given input, whatever the position.

I’ll try to look closer when I have time - the interface looks very slick.



Well, it appears I found the issue…I used rs.coercecurve to get a reference to the ‘target’ curve object from the GUID, and I thought that reference would update as the curve was edited, but no it kept pointing back to the original curve location, which only affected certian things so it was hard to track down.

Is that somethng to always expect, is there another way of getting a reference to an object that is I guess not a copy?