TypeError: CombineFeatures_createInput() takes exactly 3 arguments (2 given).

TypeError: CombineFeatures_createInput() takes exactly 3 arguments (2 given).

Anonymous
Not applicable
1,370 Views
6 Replies
Message 1 of 7

TypeError: CombineFeatures_createInput() takes exactly 3 arguments (2 given).

Anonymous
Not applicable

I am trying to combine 3 solid bodies using the CombineFeatures in script environment. The part highlighted in blue is the target body, the other 2 bodies are tool bodies. However, I kept getting this error message:

TypeError: CombineFeatures_createInput() takes exactly 3 arguments (2 given). 

 

Capture.PNG

 

 

I have looked up the createInput() method, which requires only 2 arguments, I don't understand what should the 3rd argument to be. Below is a section of my code:

 

# Combine 3 solid bodies together

tool_bodies = adsk.core.ObjectCollection.create()

tool_bodies.add(rootComp.bRepBodies[0])

tool_bodies.add(rootComp.bRepBodies[2])

 

combines = adsk.fusion.CombineFeatures

combine_input = combines.createInput(rootComp.bRepBodies[1], tool_bodies)

 

Many thanks in advance.

 

0 Likes
Accepted solutions (1)
1,371 Views
6 Replies
Replies (6)
Message 2 of 7

BrianEkins
Mentor
Mentor

I'm not seeing the same problem.  My code below works as expected where the first body is the target and the next two are used as tool bodies.

def run(context):
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent
        
        combineFeatures = root.features.combineFeatures
        targetBody = root.bRepBodies[0]
        
        toolBodies = adsk.core.ObjectCollection.create()
        toolBodies.add(root.bRepBodies[1])
        toolBodies.add(root.bRepBodies[2])
        
        combineInput = combineFeatures.createInput(targetBody, toolBodies)
        combineInput.operation = adsk.fusion.FeatureOperations.CutFeatureOperation
        combineInput.isKeepToolBodies = False
        combineFeatures.add(combineInput)
    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 3 of 7

Anonymous
Not applicable

That's really weird...I still keep getting the same error. Do you mind taking a look at my whole code?

0 Likes
Message 4 of 7

BrianEkins
Mentor
Mentor

Feel free to post it here, or you can send it to me directly using the email in my signature.

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

Anonymous
Not applicable

Thank you. Below is my code. Its a bit longwinded, as I am just working out the workflow first without simplifying it. Also, there are 3 parts where external data points are imported as csv, which I have replaced the actual file location with the pseudo 'filelocation'. Many thanks.

import adsk.core, adsk.fusion, adsk.cam, traceback
import io

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)
        title = 'Create mask'
        rootComp = design.rootComponent
        
        
        if not design:
            ui.messageBox('No active Fusion design', title)
            return
  
        # import points in csv file: spline_points
        filename = r'filelocation.csv'
        with io.open(filename, 'r', encoding='utf-8-sig') as f:
            spline_points = adsk.core.ObjectCollection.create()
            line = f.readline()
            data = []
            while line:
                pntStrArr = line.split(',')
                for pntStr in pntStrArr:
                    try:
                        data.append(float(pntStr))
                    except:
                        break
            
                if len(data) >= 3 :
                    point = adsk.core.Point3D.create(data[0], data[1], data[2])
                    spline_points.add(point)
                line = f.readline()
                data.clear()            
        
        # Sketch spline through imported points: 
        # xYConstructionPlane, sketch0, seal_spline        
        if spline_points.count:
            sketch0 = rootComp.sketches.add(rootComp.xYConstructionPlane)
            seal_spline= sketch0.sketchCurves.sketchFittedSplines.add(spline_points)
        else:
            ui.messageBox('No valid points', title)  
            
        # Create sweep profile from imported csv points
        filename = r'filelocation.csv'
        with io.open(filename, 'r', encoding='utf-8-sig') as f:
            prof_points = adsk.core.ObjectCollection.create()
            line = f.readline()
            data = []
            while line:
                pntStrArr = line.split(',')
                for pntStr in pntStrArr:
                    try:
                        data.append(float(pntStr))
                    except:
                        break
# Create points from imported csv data if len(data) >= 3 : point = adsk.core.Point3D.create(data[0], data[1], data[2]) prof_points.add(point) line = f.readline() data.clear() # Create sketch1 from xYConstructionPlane sketch1 = rootComp.sketches.add(rootComp.xYConstructionPlane) lines = sketch1.sketchCurves.sketchLines line1 = lines.addByTwoPoints(prof_points[0], prof_points[1]) line2 = lines.addByTwoPoints(line1.endSketchPoint, prof_points[2]) line3 = lines.addByTwoPoints(line2.endSketchPoint, prof_points[3]) line4 = lines.addByTwoPoints(line3.endSketchPoint, line1.startSketchPoint) # Create the sweep: seal_sweep sweeps = rootComp.features.sweepFeatures # Create a sweep input: sweeps prof = sketch1.profiles[0] # Define profile for sweep function path = rootComp.features.createPath(seal_spline) # Define path for sweep function sweepInput = sweeps.createInput(prof, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation) seal_sweep= sweeps.add(sweepInput) # Create new profiles for patch loft: xYConstructionPlane, sketch2, circle0-3 # Import offset data filename = r'filelocation.csv' with io.open(filename, 'r', encoding='utf-8-sig') as f: circle_ref = adsk.core.ObjectCollection.create() line = f.readline() data = [] while line: pntStrArr = line.split(',') for pntStr in pntStrArr: try: data.append(float(pntStr)) except: break if len(data) >=3: point = adsk.core.Point3D.create(data[0],data[1],data[2]) circle_ref.add(point) line = f.readline() data.clear() # Create 4 circles from first point in circle_ref sketch2 = rootComp.sketches.add(rootComp.xYConstructionPlane) circles = sketch2.sketchCurves.sketchCircles circle0 = circles.addByCenterRadius(circle_ref[0], 0.1) circle1 = circles.addByCenterRadius(circle_ref[0], 0.12) circle2 = circles.addByCenterRadius(circle_ref[1], 0.1) circle3 = circles.addByCenterRadius(circle_ref[1], 0.12) # Create patch loft: # Define profiles: # Profile0 body = rootComp.bRepBodies.itemByName('Body1') edges = body.edges path0 = adsk.fusion.Path.create(edges[6], adsk.fusion.ChainedCurveOptions.connectedChainedCurves) path1 = adsk.fusion.Path.create(edges[1], adsk.fusion.ChainedCurveOptions.connectedChainedCurves) # Define profiles for patch loft profile0 = path0 profile1 = sketch2.profiles.item(1) profile2 = sketch2.profiles.item(0) profile3 = path1 profile4 = sketch2.profiles.item(3) profile5 = sketch2.profiles.item(2) # Create loft feature input0 for inner patch loft loftInput0 = rootComp.features.loftFeatures.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation) loftSectionObj0 = loftInput0.loftSections loftSectionObj0.add(profile0) loftSectionObj0.add(profile1) loftSectionObj0.add(profile2) # Create loft feature input1 for outer patch loft loftInput1 = rootComp.features.loftFeatures.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation) loftSectionObj1 = loftInput1.loftSections loftSectionObj1.add(profile3) loftSectionObj1.add(profile4) loftSectionObj1.add(profile5) # Create loft feature input2 to close the inlet end loftInput2 = rootComp.features.loftFeatures.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation) loftSectionObj2 = loftInput2.loftSections loftSectionObj2.add(profile2) loftSectionObj2.add(profile5) # Create loft feature input3 to close the seal end loftInput3 = rootComp.features.loftFeatures.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation) loftSectionObj3 = loftInput3.loftSections loftSectionObj3.add(profile0) loftSectionObj3.add(profile3) # Create loft feature loftInput0.isSolid = False loftInput1.isSolid = False loftInput2.isSolid = False loftInput3.isSolid = False shell_inner = rootComp.features.loftFeatures.add(loftInput0) shell_outer = rootComp.features.loftFeatures.add(loftInput1) close_inlet = rootComp.features.loftFeatures.add(loftInput2) close_seal = rootComp.features.loftFeatures.add(loftInput3) # Stich the four patch lofts # Define tolerance with 1 cm. tolerance = adsk.core.ValueInput.createByReal(1.0) # Create a stitch input to be able to define the input needed for an stitch. stitch = rootComp.features.stitchFeatures surfaces = adsk.core.ObjectCollection.create() for i in range(rootComp.bRepBodies.count-1): surfaces.add(rootComp.bRepBodies.item(i+1)) stitchInput = stitch.createInput(surfaces, tolerance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation) # Create a stitch feature. the_body = stitch.add(stitchInput) # Create inlet from extrusion # Identify profile for extrusion through areas comparison profiles = sketch2.profiles # Create extrude: inlet extrudes = rootComp.features.extrudeFeatures extrude_input = extrudes.createInput(profiles[1], adsk.fusion.FeatureOperations.NewBodyFeatureOperation) distance = adsk.core.ValueInput.createByString('0.5mm') extrude_distance = adsk.fusion.DistanceExtentDefinition.create(distance) extrude_input.setOneSideExtent(extrude_distance, adsk.fusion.ExtentDirections.PositiveExtentDirection) inlet = extrudes.add(extrude_input) # Combine 3 solid bodies together targetbody = rootComp.bRepBodies[1] tool_bodies = adsk.core.ObjectCollection.create() tool_bodies.add(rootComp.bRepBodies[0]) tool_bodies.add(rootComp.bRepBodies[2]) combines = adsk.fusion.CombineFeatures combine_input = combines.createInput(targetbody, tool_bodies) combine_input.operation = adsk.fusion.FeatureOperations.JoinFeatureOperation combine_input.isKeepToolBodies = False mask = combines.add(combine_input) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Message 6 of 7

BrianEkins
Mentor
Mentor
Accepted solution

It's a simple mistake that I should have noticed in your original post.  The line:

combines = adsk.fusion.CombineFeatures

should be

 

combines = rootComp.features.combineFeatures
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 7 of 7

Anonymous
Not applicable

Yes, it is. I have changed and now it works. Thank you Brian.

0 Likes