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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to intersect a new extrusion to a specific body through api?

Message 1 of 5
192 Views, 4 Replies

how to intersect a new extrusion to a specific body through api?

hello,i want to build a csg tree model,but when i try to create a new intersection, it intersect with all existing models.


here is my code:

def generate_primitive(rootComp, control_points, point_weights, height, three_points, flag):
    sketches = rootComp.sketches
    xyPlane = rootComp.xYConstructionPlane
    planes = rootComp.constructionPlanes
    extrudes = rootComp.features.extrudeFeatures
    firstSketch = sketches.add(xyPlane)
    pos_1 = adsk.core.Point3D.create(three_points[0][0], three_points[0][1], three_points[0][2])
    pos_2 = adsk.core.Point3D.create(three_points[1][0], three_points[1][1], three_points[1][2])
    pos_3 = adsk.core.Point3D.create(three_points[2][0], three_points[2][1], three_points[2][2])
    p_1 = firstSketch.sketchPoints.add(pos_1)
    p_2 = firstSketch.sketchPoints.add(pos_2)
    p_3 = firstSketch.sketchPoints.add(pos_3)
    planeInput = planes.createInput()
    planeInput.setByThreePoints(p_1, p_2, p_3)
    threePointsPlane = planes.add(planeInput) = 'Three-points plane'
    sketch = sketches.add(threePointsPlane)
    degree = 3
    knots = [0, 0, 0, 0, 1, 1, 1, 1]
    splines = sketch.sketchCurves.sketchFixedSplines
    splines.isFixed = False
    for index, p in enumerate(control_points):
        weights = [1, 1, 1, 1]
        weights[1], weights[2] = point_weights[index][0], point_weights[index][1]
        point1 = adsk.core.Point3D.create (p[0][0],p[0][1],0)
        point2 = adsk.core.Point3D.create (p[1][0],p[1][1],0)
        point3 = adsk.core.Point3D.create (p[2][0],p[2][1],0)
        point4 = adsk.core.Point3D.create (p[3][0],p[3][1],0)
        points = [point1, point2, point3, point4]
        nurbs = adsk.core.NurbsCurve3D.createRational(points, degree, knots, weights, False)
        fixed_splines = splines.addByNurbsCurve(nurbs)
        fixed_splines.isReference = False
    distance = adsk.core.ValueInput.createByReal(height)
        body = extrudes.addSimple(sketch.profiles.item(0), distance, adsk.fusion.FeatureOperations.IntersectFeatureOperation)
        body = extrudes.addSimple(sketch.profiles.item(0), distance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
    return body

def generate_model(rootComp, json_data, ui):
    control_points = json_data["param"]["points"]
    weights = json_data["param"]["weights"]
    heights = json_data["param"]["heights"]
    planes = json_data["param"]["planes"]
    intersections = json_data["intersection"]
    union = json_data["union"]
    for c in range(len(intersections[0])):
        if union[c]!=1:
        newCom = rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create())
        revComp = newCom.component
        for k in range(len(intersections)):
            if intersections[k][c] == 1:
                ext = generate_primitive(revComp, control_points[k], weights[k], heights[k], planes[k], 0)

def parse_json(rootComp, category,start_id, n, ui):
    dir = "C:/Users/86454/Desktop/jsons/"+category
    count = 0
    for index, file in enumerate(os.listdir(dir)):
        if index < start_id:
        with open("{}/{}".format(dir, file), "r") as fp:
            generate_model(rootComp, json.load(fp), ui)
        count += 1
        if count >= n:

def run(context):
    ui = None
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = app.activeProduct
        rootComp = design.rootComponent
        category = "bench"
        id = 0
        num = 1
        parse_json(rootComp, category, id, num, ui)
        if ui:


and here is what i want to achieve:


Message 2 of 5
in reply to: 2022282210229

Hi @2022282210229 .


I think the desired processing can be done by using the createInput method instead of the addSimple method.

Here is a sample. 

Message 3 of 5
in reply to: 2022282210229

I think there are two basic approaches to what you want. The first is to perform the CSG boolean operation when you create the extrusion. This is done by specifying the operation for the boolean, which for the first primitive will be to create a new body and for subsequent primitives will be to either add or subtract. Using the ExtrudeFeatureInput you can use the participantBodies properties to control which bodies the new extrusion will affect.


The other approach is to create the primitive as a new body and then use the Combine feature to combine them in different ways where you can specify if they should be unioned, subtracted, or intersected.

Brian Ekins
Inventor and Fusion 360 API Expert
Message 4 of 5
in reply to: BrianEkins

thansk a lot!!! I'll have a try.
Message 5 of 5
in reply to: kandennti

thanks a lot!!! I'll have a try.

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