Performing a Patch Sweep in the API

Anonymous

Performing a Patch Sweep in the API

Anonymous
Not applicable

I'm trying to recreate a helical sweep operation in the API, I want to use a sketch line as the sweep profile to create a helical path on which I can then do a solid sweep along but am having trouble finding out how to perform this patch sweep using the API. 

Trying to sweep the sketch line at the top of the construction line through the path to create an offset patch I can twist around the shaft.Trying to sweep the sketch line at the top of the construction line through the path to create an offset patch I can twist around the shaft.

Currently working in python, I've attempted to create the sweep but I'm unclear on how to use the patch feature in relation to the sweep feature. The current script is as follows:

 

        # Assign variables - units are in cm
        pitch_ratio = 0.2456    # use a dictionary for future use, this is a test value
        
        screw_radius = 100
        shaft_radius = 50
        screw_angle_deg = 22
        screw_angle = math.degrees(screw_angle_deg)
        head = 200
        
        screw_length = (head + screw_radius) / math.sin(screw_angle)
        pitch = ((2*math.pi*pitch_ratio) / math.tan(screw_angle)) * screw_radius
revolutions = screw_length / pitch twist_angle = revolutions * 360 print('Variables Assigned:\nScrew Radius = %s m\nShaft Radius = %s m\nScrew Length = %s m\nTwist Angle = %s°\n' % (screw_radius/100, shaft_radius/100, screw_length/100, twist_angle)) # Document setup        
app = adsk.core.Application.get() ui = app.userInterface design = app.activeProduct # Get the root component of the design and create a sub component rootComp = design.rootComponent newOcc = rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create()) screwComp = newOcc.component screwComp.name = 'Archimedean Hydroscrew' shaftOcc = screwComp.occurrences.addNewComponent(adsk.core.Matrix3D.create()) shaftComp = shaftOcc.component shaftComp.name = 'Shaft' bladeOcc = screwComp.occurrences.addNewComponent(adsk.core.Matrix3D.create()) bladeComp = bladeOcc.component bladeComp.name = 'Blades'  
# Create a sketch on xy (Front) and yz (Right) planes of the screw sub component sketches = screwComp.sketches shaft_sketches = shaftComp.sketches blade_sketches = bladeComp.sketches xyPlane = screwComp.xYConstructionPlane yzPlane = screwComp.yZConstructionPlane shaft_profile_sketch = shaft_sketches.add(xyPlane) shaft_profile_sketch.name = 'Shaft Profile' screw_path_sketch = sketches.add(xyPlane) screw_path_sketch.name = 'Screw_Path' # Draw the shaft profile and the screw path shaft_profile_circles = shaft_profile_sketch.sketchCurves.sketchCircles shaft_profile = shaft_profile_circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), shaft_radius) screw_path_line = screw_path_sketch.sketchCurves.sketchLines screw_path = screw_path_line.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(0, 0, screw_length)) # Get the profile defined by the circle shaft_profile_prof = shaft_profile_sketch.profiles.item(0) # Create a path form the screw_path screw_path_path = shaftComp.features.createPath(screw_path) # Create a sweep input shaft_sweeps = shaftComp.features.sweepFeatures shaft_sweep_input = shaft_sweeps.createInput(shaft_profile_prof, screw_path_path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation) shaft_sweep_input.taperAngle = adsk.core.ValueInput.createByString('0 deg') shaft_sweep_input.twistAngle = adsk.core.ValueInput.createByString('0 deg') # Create the sweep shaft_sweep = shaft_sweeps.add(shaft_sweep_input) # Create a construction plane at the start of the path path_plane = screwComp.constructionPlanes path_plane_input = path_plane.createInput() distance = adsk.core.ValueInput.createByReal(0.0) path_plane_input.setByDistanceOnPath(screw_path, distance) path_plane.add(path_plane_input) # Create a 1D profile for a patch blade_patch_sketch = blade_sketches.add(xyPlane) blade_patch_sketch.name = 'Blade Patch Profile' blade_patch_line = blade_patch_sketch.sketchCurves.sketchLines blade_patch_offset = blade_patch_line.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(0, screw_radius, 0)) blade_patch_offset.isConstruction = True blade_patch_profile = blade_patch_line.addByTwoPoints(adsk.core.Point3D.create(0, screw_radius, 0), adsk.core.Point3D.create(0, screw_radius + 0.01, 0)) # Sweep a blade in the patch workspace - this part is not working patch_sweeps = bladeComp.features.sweepFeatures patch_prof = blade_patch_sketch.profilecurve.item(0) patch_input = patch_sweeps.createInput(patch_prof, screw_path_path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation) patch_input.taperAngle = adsk.core.ValueInput.createByString('0 deg') patch_input.twistAngle = adsk.core.ValueInput.createByReal(twist_angle) patch_input.isSolid = False patch_sweep = patch_sweeps.add(patch_input)

 

At the moment, the script produces this error:

 

Currently getting this error.Currently getting this error.

Can anyone help with this?

 

Cheers,

Jack

0 Likes
Reply
Accepted solutions (1)
1,055 Views
5 Replies
Replies (5)

goyals
Autodesk
Autodesk

This error means there is no property like 'profileCurve' on sketch. To get the profile, you need to use 'profiles' property on sketch. It will return all the profiles of a sketch and then you can iterate over it to get a particular profile. I think your sketch contains just a line and no profile there.



Shyam Goyal
Sr. Software Dev. Manager
1 Like

Anonymous
Not applicable

Yeah I'm trying to sweep in the patch environment as opposed to the model environment, in the patch environment I can sweep using sketch lines I'm trying to figure out how to replicate this in the API.

 

This should be the end result, a patch sweep of the sketch line that revolves around the shaft.This should be the end result, a patch sweep of the sketch line that revolves around the shaft.

0 Likes

goyals
Autodesk
Autodesk

I am afraid to mention commands of patch environment are not exposed through API unless some one contradicts me.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes

BrianEkins
Mentor
Mentor
Accepted solution

Most of the features in the Patch workspace are supported by the API.  In most cases, it's the same feature objects in the API just you just set the isSolid property to False to indicate that a surface should be created.  Here's a sample that creates the geometry you're trying to create.

 

def sweepTest():
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        # Create a document.
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
 
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        # Get the root component of the active design.
        rootComp = design.rootComponent
        
        # Create the line that will be the profile.
        profSketch = rootComp.sketches.add(rootComp.xZConstructionPlane)
        sketchLines = profSketch.sketchCurves.sketchLines
        profLine = sketchLines.addByTwoPoints(adsk.core.Point3D.create(0,0,0), 
                                              adsk.core.Point3D.create(0,5,0))
        
        # Create an open profile using the line.
        prof = rootComp.createOpenProfile(profLine, False)
        
        # Create a sketch to draw the path line.
        pathSketch = rootComp.sketches.add(rootComp.yZConstructionPlane)
        sketchLines = pathSketch.sketchCurves.sketchLines
        
        pathLine = sketchLines.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0),
                                              adsk.core.Point3D.create(0, 30, 0))                                 
        
        # Create a path using the line.
        path = rootComp.features.createPath(pathLine)

        # Create a sweep input
        sweeps = rootComp.features.sweepFeatures
        sweepInput = sweeps.createInput(prof, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        sweepInput.twistAngle = adsk.core.ValueInput.createByReal(math.pi * 5)
        sweepInput.isSolid = False

        # Create the sweep.
        sweep = 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
3 Likes

Anonymous
Not applicable

Yep this works perfectly, thanks!

0 Likes