Fit-point splines sharing a sketch point
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a network of interconnected 3D curves. The data is stored in two CSV files: one containing the 3D points and another containing sequences of indices into the set of points specifying curves. I'm able to load this data into Fusion and build spline curves (SketchFittedSpline curves). However, I want a user to be able to move these points interactively, and the splines to react to the user input. Therefore, I try to merge the logically duplicate points obtained via SketchFittedSpline.firPoints. This works sometimes, but fails with a runtime error at other times:
"RuntimeError: 5: Failed to solve. Please try revising dimensions or constraints."
Here's a small reproducible example:
#Author-Rahul Arora #Description- import adsk.core, adsk.fusion, adsk.cam, traceback def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface product = app.activeProduct points = adsk.core.ObjectCollection.create() points.add(adsk.core.Point3D.create(-1, 0, 0)) points.add(adsk.core.Point3D.create( 0, 0, 0)) points.add(adsk.core.Point3D.create( 1, 0, 0)) points.add(adsk.core.Point3D.create( 0, 1, 0)) design = product root = design.activeComponent sketch = root.sketches.add(root.xYConstructionPlane); idx1 = [0, 1, 2] idx2 = [1, 3] pts1 = adsk.core.ObjectCollection.create() for i in idx1 : pts1.add(points[i]) pts2 = adsk.core.ObjectCollection.create() for i in idx2 : pts2.add(points[i]) sketch.sketchCurves.sketchFittedSplines.add(pts1) spline1 = sketch.sketchCurves.sketchFittedSplines.item(sketch.sketchCurves.sketchFittedSplines.count - 1) sketch.sketchCurves.sketchFittedSplines.add(pts2) spline2 = sketch.sketchCurves.sketchFittedSplines.item(sketch.sketchCurves.sketchFittedSplines.count - 1) pts1 = spline1.fitPoints pts2 = spline2.fitPoints assert pts1.count == len(idx1) assert pts2.count == len(idx2) if pts1.item(1) != pts2.item(0) and pts1.item(1).geometry.distanceTo(pts2.item(0).geometry) < 1e-6: pts1.item(1).merge(pts2.item(0)) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Lines 44-47 are just sanity checks and you can ignore them. Line 48 (the last line before the except statement) is where the error occurs.
What am I doing wrong?