Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error when creating a sweep

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
jphalip
242 Views, 5 Replies

Error when creating a sweep

Hi,

 

I'm trying to create a sweep using a profile and a path to cut into a body:

 

sweeps:adsk.fusion.SweepFeatures = profile.parentSketch.parentComponent.features.sweepFeatures
sweepInput:adsk.fusion.SweepFeatureInput = sweeps.createInput(profile, path, adsk.fusion.FeatureOperations.CutFeatureOperation)
sweepInput.twistAngle = adsk.core.ValueInput.createByString('90 deg')
sweepInput.taperAngle = adsk.core.ValueInput.createByString('0 deg')
sweepInput.orientation = adsk.fusion.SweepOrientationTypes.PerpendicularOrientationType
sweepInput.participantBodies = [body]
sweepFeature:adsk.fusion.SweepFeature = sweeps.add(sweepInput)

 

However, I'm getting this error:

 

 

 

adsk/fusion.py", line 40914, in add
return _fusion.SweepFeatures_add(self, input)
RuntimeError: 2 : InternalValidationError : got && chainCurves.size() > 0

 

 

 

Can you tell what I might be missing?

 

Thanks,

 

Julien

5 REPLIES 5
Message 2 of 6
kandennti
in reply to: jphalip

Hi @jphalip .

 

This alone may not be enough to determine the cause of the problem.
Can you attach the f3d file you are running?

Or, if the same process is performed in the GUI, does it produce an error?

Message 3 of 6
BrianEkins
in reply to: jphalip

Here's a variation of your code that I can get working. I've attached the model that I ran it with.

def run(context):
    app = adsk.core.Application.get()
    ui = app.userInterface
    try:
        des: adsk.fusion.Design = app.activeProduct
        root = des.rootComponent

        profSketch = root.sketches.itemByName('ProfileSketch')
        pathSketch = root.sketches.itemByName('PathSketch')
        profile = profSketch.profiles[0]

        path = adsk.fusion.Path.create(pathSketch.sketchCurves[0], adsk.fusion.ChainedCurveOptions.tangentChainedCurves)
        sweeps:adsk.fusion.SweepFeatures = profile.parentSketch.parentComponent.features.sweepFeatures
        sweepInput:adsk.fusion.SweepFeatureInput = sweeps.createInput(profile, path, adsk.fusion.FeatureOperations.CutFeatureOperation)
        sweepInput.twistAngle = adsk.core.ValueInput.createByString('90 deg')
        sweepInput.taperAngle = adsk.core.ValueInput.createByString('0 deg')
        sweepInput.orientation = adsk.fusion.SweepOrientationTypes.PerpendicularOrientationType
        sweepInput.participantBodies = [root.bRepBodies[0]]
        sweepFeature:adsk.fusion.SweepFeature = sweeps.add(sweepInput)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

  

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 4 of 6
jphalip
in reply to: jphalip

@BrianEkins @kandennti Thank you both for your response. Below is the full code that's yielding the error for me.

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        root:adsk.fusion.Component = design.rootComponent

        # Create a cylinder
        sketch: adsk.fusion.Sketch = root.sketches.add(root.xYConstructionPlane)
        sketch.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 2)
        profile:adsk.fusion.Profile = sketch.profiles.item(0)
        extrudes:adsk.fusion.ExtendFeatures = root.features.extrudeFeatures
        extrudeInput = extrudes.createInput(profile, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        extrudeInput.setOneSideExtent(
            adsk.fusion.DistanceExtentDefinition.create(adsk.core.ValueInput.createByString("100 mm")),
            adsk.fusion.ExtentDirections.PositiveExtentDirection)
        extrudes.add(extrudeInput)
        cylinder:adsk.fusion.BRepBody = root.bRepBodies.item(0)

        # Create another sketch on one of the cylinder's faces
        planar_faces = [cylinder.faces.item(i) for i in range(cylinder.faces.count) if cylinder.faces.item(i).geometry.surfaceType == adsk.core.SurfaceTypes.PlaneSurfaceType]
        face = planar_faces[0]
        other_sketch: adsk.fusion.Sketch = root.sketches.add(face)

        # Create a profile
        circle:adsk.fusion.SketchCircle = other_sketch.project(cylinder).item(0)
        point_A:adsk.fusion.SketchPoint = other_sketch.sketchPoints.add(
            adsk.core.Point3D.create(
                1, 0, 0
            ))
        point_B:adsk.fusion.SketchPoint = other_sketch.sketchPoints.add(
            adsk.core.Point3D.create(
                0, 1, 0
            ))
        other_sketch.geometricConstraints.addCoincident(point_A, circle)
        other_sketch.geometricConstraints.addCoincident(point_B, circle)
        other_sketch.sketchCurves.sketchLines.addByTwoPoints(
            circle.centerSketchPoint.geometry, point_A.geometry
        )
        other_sketch.sketchCurves.sketchLines.addByTwoPoints(
            circle.centerSketchPoint.geometry, point_B.geometry
        )
        profile:adsk.fusion.Profile = min(other_sketch.profiles, key=lambda x: x.areaProperties().area)

        # Create a path
        vector: adsk.core.Vector3D = adsk.core.Vector3D.create(0, 0, -3)
        path_vector:adsk.core.Vector3D = vector.copy()
        path_end_point:adsk.core.Point3D = adsk.core.Point3D.create(
                circle.centerSketchPoint.geometry.x + path_vector.x,
                circle.centerSketchPoint.geometry.y + path_vector.y,
                circle.centerSketchPoint.geometry.z + path_vector.z,
            )
        path_line:adsk.fusion.SketchLine = other_sketch.sketchCurves.sketchLines.addByTwoPoints(
            circle.centerSketchPoint.geometry, path_end_point
        )
        path:adsk.fusion.Path = adsk.fusion.Path.create(path_line, adsk.fusion.ChainedCurveOptions.tangentChainedCurves)

        # Create the sweep
        sweeps:adsk.fusion.SweepFeatures = profile.parentSketch.parentComponent.features.sweepFeatures
        sweepInput:adsk.fusion.SweepFeatureInput = sweeps.createInput(
            profile, path, adsk.fusion.FeatureOperations.CutFeatureOperation)
        sweepInput.twistAngle = adsk.core.ValueInput.createByString('90 deg')
        sweepInput.taperAngle = adsk.core.ValueInput.createByString('0 deg')
        sweepInput.orientation = adsk.fusion.SweepOrientationTypes.PerpendicularOrientationType
        sweepInput.participantBodies = [cylinder]
        sweepFeature:adsk.fusion.SweepFeature = sweeps.add(sweepInput)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

I'm not sure why the sweep fails. It does work if I do it manually in the UI -- This is what I would expect to get:

2023-02-07_10-50-26.png

Please let me know if you can spot any mistakes. Thanks!

Message 5 of 6
BrianEkins
in reply to: jphalip

This was a strange one. I thought I saw the problem but then edited your code to fix that, but it still failed. My original thought is that when you create a sketch on a face, it automatically projects the edges of the face into the sketch, so in this case, the sketch will have a circle in it. You were creating a second circle, and I thought this might be causing the problem, but it still failed. I tried a few other things, and it still failed. Then a few more, and it worked, but it wasn't obvious what change fixed it. Finally, I found that moving the line that gets the profile later in the code fixed the problem. I think what's happening is that you get the profile from the sketch and then draw the line for the path in the same sketch. I think making a change to the sketch invalidates the profile. Getting the profile after drawing the line works. Here's my code that does this, plus a few other changes that clean it up a bit.

 

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        root:adsk.fusion.Component = design.rootComponent

        # Create a cylinder
        sketch: adsk.fusion.Sketch = root.sketches.add(root.xYConstructionPlane)
        sketch.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 2)
        profile:adsk.fusion.Profile = sketch.profiles.item(0)
        extrudes:adsk.fusion.ExtrudeFeatures = root.features.extrudeFeatures
        extrudeInput = extrudes.createInput(profile, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        extrudeInput.setOneSideExtent(
            adsk.fusion.DistanceExtentDefinition.create(adsk.core.ValueInput.createByString("100 mm")),
            adsk.fusion.ExtentDirections.NegativeExtentDirection)
        extrude = extrudes.add(extrudeInput)
        cylinder:adsk.fusion.BRepBody = root.bRepBodies.item(0)

        # Create another sketch on one of the cylinder's faces
        face = extrude.startFaces[0]
        other_sketch: adsk.fusion.Sketch = root.sketches.add(face)

        # Get the circle that was automatically projected from the face.
        circle = other_sketch.sketchCurves.sketchCircles[0]

        # Draw lines from the center of the circle to the edge.
        constraints = other_sketch.geometricConstraints
        lines = other_sketch.sketchCurves.sketchLines
        line1 = lines.addByTwoPoints(circle.centerSketchPoint, adsk.core.Point3D.create(2, 0, 0))
        constraints.addHorizontal(line1)        
        constraints.addCoincident(line1.endSketchPoint, circle)

        line2 = lines.addByTwoPoints(circle.centerSketchPoint, adsk.core.Point3D.create(0, 2, 0))
        constraints.addVertical(line2)        
        constraints.addCoincident(line2.endSketchPoint, circle)

        # Create a path
        vector: adsk.core.Vector3D = adsk.core.Vector3D.create(0, 0, -3)
        path_vector:adsk.core.Vector3D = vector.copy()
        path_end_point:adsk.core.Point3D = adsk.core.Point3D.create(
                circle.centerSketchPoint.geometry.x + path_vector.x,
                circle.centerSketchPoint.geometry.y + path_vector.y,
                circle.centerSketchPoint.geometry.z + path_vector.z,
            )
        path_line:adsk.fusion.SketchLine = other_sketch.sketchCurves.sketchLines.addByTwoPoints(
            circle.centerSketchPoint.geometry, path_end_point
        )

        path:adsk.fusion.Path = adsk.fusion.Path.create(path_line, adsk.fusion.ChainedCurveOptions.noChainedCurves)

        # Get the minimum area profile, since there are two.
        profile:adsk.fusion.Profile = min(other_sketch.profiles, key=lambda x: x.areaProperties().area)

        # Create the sweep
        sweeps:adsk.fusion.SweepFeatures = profile.parentSketch.parentComponent.features.sweepFeatures
        sweepInput:adsk.fusion.SweepFeatureInput = sweeps.createInput(
            profile, path, adsk.fusion.FeatureOperations.CutFeatureOperation)
        sweepInput.twistAngle = adsk.core.ValueInput.createByString('90 deg')
        sweepInput.taperAngle = adsk.core.ValueInput.createByString('0 deg')
        sweepInput.orientation = adsk.fusion.SweepOrientationTypes.PerpendicularOrientationType
        sweepInput.participantBodies = [cylinder]
        sweepFeature:adsk.fusion.SweepFeature = sweeps.add(sweepInput)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 6 of 6
jphalip
in reply to: jphalip

Wow, good catch! That's an odd one indeed. In hindsight it kind of makes sense, but it's definitely not very obvious. I wish somehow the error message would have been more clear.

 

But anyways, thanks so much for taking the time to troubleshoot and fix this!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report