Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Fillet and Draft in ADD-INS on Python

nikita.panasiuk.knm.2020
Contributor

Fillet and Draft in ADD-INS on Python

nikita.panasiuk.knm.2020
Contributor
Contributor
Good day to all. I have a task to program this model, and I did the main part, but there was a problem. 
I don't know how to write Fillet and Draft tools.
I already looked at the documentation examples but they did not help me.
Maybe something will help with the code or throw off an easier example? Here is my code:

 

#Author-
#Description-
from asyncio import constants
import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    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 sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        Lines = sketch.sketchCurves.sketchLines
        startPoint = adsk.core.Point3D.create(0, 0, 0)
        endPoint = adsk.core.Point3D.create(6, 11, 0)



        Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
        prof = sketch.profiles.item(0)
        # Create an extrusion input.
        features = rootComp.features
        extrudes = features.extrudeFeatures
        extInput = extrudes.createInput(
            prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        # Define that the extent is a distance extent of 5 cm.
        distance = adsk.core.ValueInput.createByReal(3)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)


        # CUT CYLINDER 
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        circles1 = sketch.sketchCurves.sketchCircles
        CentPoint = adsk.core.Point3D.create(1.5, 1.5, 0)
        oCirc = circles1.addByCenterRadius(CentPoint, 0.5)
        # Get the profile defined by the rectangle.
        prof1 = sketch.profiles.item(0)
        extInput = extrudes.createInput(prof1, adsk.fusion.FeatureOperations.CutFeatureOperation)


        distance = adsk.core.ValueInput.createByReal(3)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)


##
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        circles1 = sketch.sketchCurves.sketchCircles
        CentPoint = adsk.core.Point3D.create(4.5, 1.5, 0)
        oCirc = circles1.addByCenterRadius(CentPoint, 0.5)
        # Get the profile defined by the rectangle.
        prof1 = sketch.profiles.item(0)
        extInput = extrudes.createInput(prof1, adsk.fusion.FeatureOperations.CutFeatureOperation)


        distance = adsk.core.ValueInput.createByReal(3)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)
   

        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        circles1 = sketch.sketchCurves.sketchCircles
        CentPoint = adsk.core.Point3D.create(1.5, 9.5, 0)
        oCirc = circles1.addByCenterRadius(CentPoint, 0.5)
        # Get the profile defined by the rectangle.
        prof1 = sketch.profiles.item(0)
        extInput = extrudes.createInput(prof1, adsk.fusion.FeatureOperations.CutFeatureOperation)


        distance = adsk.core.ValueInput.createByReal(3)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)



        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        circles1 = sketch.sketchCurves.sketchCircles
        CentPoint = adsk.core.Point3D.create(4.5, 9.5, 0)
        oCirc = circles1.addByCenterRadius(CentPoint, 0.5)
        # Get the profile defined by the rectangle.
        prof1 = sketch.profiles.item(0)
        extInput = extrudes.createInput(prof1, adsk.fusion.FeatureOperations.CutFeatureOperation)


        distance = adsk.core.ValueInput.createByReal(3)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput) 



        # ADD CYLINDER

        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        circles1 = sketch.sketchCurves.sketchCircles
        CentPoint = adsk.core.Point3D.create(3, 4, 0)
        oCirc = circles1.addByCenterRadius(CentPoint, 1.25)
        # Get the profile defined by the rectangle.
        prof1 = sketch.profiles.item(0)
        extInput = extrudes.createInput(prof1, adsk.fusion.FeatureOperations.JoinFeatureOperation)

        distance = adsk.core.ValueInput.createByReal(6)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)
        
        #AND CUT CENTER
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        circles1 = sketch.sketchCurves.sketchCircles
        CentPoint = adsk.core.Point3D.create(3, 4, 0)
        oCirc = circles1.addByCenterRadius(CentPoint, 0.75)
        # Get the profile defined by the rectangle.
        prof1 = sketch.profiles.item(0)
        extInput = extrudes.createInput(prof1, adsk.fusion.FeatureOperations.CutFeatureOperation)


        distance = adsk.core.ValueInput.createByReal(6)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput) 


        # CUT Diagonal
        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        Lines = sketch.sketchCurves.sketchLines
        startPoint = adsk.core.Point3D.create(0.4, 2.5, 0)
        endPoint = adsk.core.Point3D.create(5.6, 8.5, 0)

        Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
        prof2 = sketch.profiles.item(0)

        # Create an extrusion input.
        features = rootComp.features
        extrudes = features.extrudeFeatures
        extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
        # Define that the extent is a distance extent of 5 cm.
        distance = adsk.core.ValueInput.createByReal(0.8)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)


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

 

 
0 Likes
Reply
238 Views
1 Reply
Reply (1)

BrianEkins
Mentor
Mentor

Attached is a modified version of your program. I simplified some of the existing code a bit and added code to create the fillets. It should also be possible to add the draft feature, but I've run into a bug in the API. For some reason, it's having a problem adding a draft to a cylinder. You can do it in the UI, so Fusion supports it. I'll make sure a bug gets files.

The thing that makes adding the fillets and draft difficult is finding the geometry to input. There are several different approaches that can be taken. In this program, I find them based on their position in space, but there are others that are just as good. Here's a link to a paper I presented at AU a few years ago that discusses this.

 

https://ekinssolutions.com/wp-content/uploads/2018/11/GeometryAndBRep-AU2018.pdf

 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes