SweepFeature path access errors

SweepFeature path access errors

codereclaimers
Enthusiast Enthusiast
352 Views
2 Replies
Message 1 of 3

SweepFeature path access errors

codereclaimers
Enthusiast
Enthusiast

When a SweepFeature's path has been deleted, I get an error when attempting to set the path member of the SweepFeature object (note that spline is a SketchFittedSpline that was created to replace the original path):

 

 

 

if obj.objectType == adsk.fusion.SweepFeature.classType():                        
    path = adsk.fusion.Path.create(spline, adsk.fusion.ChainedCurveOptions.noChainedCurves)
    obj.timelineObject.rollTo(True)
    obj.path = path

 

 

 

 

Traceback (most recent call last):

File "C:/Users/alan/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/SplineModificationTest/SplineModificationTest.py", line 35, in run

obj.path = path

File "C:\Users/alan/AppData/Local/Autodesk/webdeploy/production/19107935ce2ad08720646cb4a31efe37d8a5f41b/Api/Python/packages\adsk\fusion.py", line 66391, in _set_path

return _fusion.SweepFeature__set_path(self, value)

RuntimeError: 2 : InternalValidationError : curPath

 

If I want to update a SweepFeature that's been invalidated by other operations, am I just out of luck?

 

(I also get a similar error if I instead attempt to get the current path from the invalidated SweepFeature; I would expect it to return None.)

 

Thanks in advance!

0 Likes
353 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor

Hi @codereclaimers .

 

I tried it and was able to replace the path without any problems.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

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

        app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        # create sweep
        initSweep()

        vp: adsk.core.Viewport = app.activeViewport
        vp.fit()
        ui.messageBox('Before replacement')

        # get SweepFeature
        tl: adsk.fusion.Timeline = des.timeline
        sweepFeat: adsk.fusion.SweepFeature = adsk.fusion.SweepFeature.cast(
            tl.item(tl.markerPosition - 1).entity
        )
        if not sweepFeat:
            return

        # create new path
        newPathSkt: adsk.fusion.Sketch = root.sketches.add(
            root.xYConstructionPlane
        )
        pnts: adsk.core.ObjectCollection = adsk.core.ObjectCollection.create()
        pnts.add(adsk.core.Point3D.create(0, 0, 0))
        pnts.add(adsk.core.Point3D.create(2, 1, 0))
        pnts.add(adsk.core.Point3D.create(2, 4, 3))
        pnts.add(adsk.core.Point3D.create(-2, 6, 6))
        newPathSkt.sketchCurves.sketchFittedSplines.add(pnts)

        path: adsk.fusion.Path = adsk.fusion.Path.create(
            newPathSkt.sketchCurves.sketchFittedSplines[0],
            adsk.fusion.ChainedCurveOptions.noChainedCurves
        )

        # replace path
        sweepFeat.timelineObject.rollTo(True)
        sweepFeat.path = path

        tl.moveToEnd()

        vp.fit()
        ui.messageBox('After replacement')


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


def initSweep():
    app: adsk.core.Application = adsk.core.Application.get()
    des: adsk.fusion.Design = app.activeProduct
    root: adsk.fusion.Component = des.rootComponent

    profSkt: adsk.fusion.Sketch = root.sketches.add(
        root.yZConstructionPlane
    )
    profSkt.sketchCurves.sketchCircles.addByCenterRadius(
        adsk.core.Point3D.create(0, 0, 0),
        1.0
    )

    pathSkt: adsk.fusion.Sketch = root.sketches.add(
        root.xYConstructionPlane
    )
    pnts: adsk.core.ObjectCollection = adsk.core.ObjectCollection.create()
    pnts.add(adsk.core.Point3D.create(0, 0, 0))
    pnts.add(adsk.core.Point3D.create(5, 1, 0))
    pnts.add(adsk.core.Point3D.create(6, 4, 3))
    pnts.add(adsk.core.Point3D.create(7, 6, 6))
    pathSkt.sketchCurves.sketchFittedSplines.add(pnts)

    path: adsk.fusion.Path = root.features.createPath(
        pathSkt.sketchCurves.sketchFittedSplines[0]
    )
    
    sweeps: adsk.fusion.SweepFeatures = root.features.sweepFeatures
    sweepIpt: adsk.fusion.SweepFeatureInput = sweeps.createInput(
        profSkt.profiles[0],
        path,
        adsk.fusion.FeatureOperations.NewBodyFeatureOperation
    )
    sweeps.add(sweepIpt)

 

It may be a good idea to check if the shape of the path can be replaced in the GUI.

0 Likes
Message 3 of 3

kandennti
Mentor
Mentor

@codereclaimers .

 

I made a mistake.
Indeed, in the case of Sweep, where the Path is an error that has been deleted, changing the Path was an error.

0 Likes