Split and Offset a patch surface body

Anonymous

Split and Offset a patch surface body

Anonymous
Not applicable

Hi, I'd like to split a sphere surface (patch solid) with a closed spline (see attachment). Then, I'd like to offset one of the split body by 2mm. I couldn't find any example for splitting and offsetting patch solid. Anyone can help to provide some sample code for split and offset a patch surface? Much appreciated.1.PNG2.PNGCapture.PNG

0 Likes
Reply
Accepted solutions (1)
1,068 Views
2 Replies
Replies (2)

BrianEkins
Mentor
Mentor
Accepted solution

Here's some code that demonstrates what you described.  It uses the attached model.

 

def trimAndOffset():
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent

        # Get the face to be split and add it to a collection.
        body = root.bRepBodies.item(0)
        face = body.faces.item(0)
        faces = adsk.core.ObjectCollection.create()
        faces.add(face)

        # Get the curve that defines the split.
        curveSketch = root.sketches.itemByName('CutShape')        
        curve = curveSketch.sketchCurves.item(0)                                                           

        # Create the split feature.
        splitInput = root.features.splitFaceFeatures.createInput(faces, curve, False)
        splitInput.setClosestPointSplitType()
        splitFeature = root.features.splitFaceFeatures.add(splitInput)
 
        # Find the smaller face.  This uses the fact that it's the only face
        # that has a single bounding loop.
        foundFace = adsk.fusion.BRepFace.cast(None)
        testFace = adsk.fusion.BRepFace.cast(None)
        for testFace in splitFeature.faces:
            if testFace.loops.count == 1:
                foundFace = testFace
                break
        
        offsetFaces = adsk.core.ObjectCollection.create()
        offsetFaces.add(foundFace)
        offsetInput = root.features.offsetFeatures.createInput(offsetFaces, adsk.core.ValueInput.createByReal(2),
                                                               adsk.fusion.FeatureOperations.NewBodyFeatureOperation,
                                                               False)

        offsetFeature = root.features.offsetFeatures.add(offsetInput)            
    except:
        app = adsk.core.Application.get()
        ui = app.userInterface
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

Anonymous
Not applicable

Dear Brian,

 

Many thanks for your detailed code solution, espectially the part on how to identify the smaller surface for offsetting. Very useful.

 

Just a follow-up question on the use of the splitting tool. I sketched a profile like below with the following code, however, when I want to split a BREP solid body with the sketch, it always raise the following error:  RunTimeError 3: Invalid Splitting Tool

Capture.PNG

I checked in API that it is a closed profile, and when I select the sketch line as split tool in UI, it can be selected as 1 closed loop. But I can't seem to define the correct split tool in API, how do I create the correct split tool for the splitInput? 

        sketch = rootComp.sketches.add(rootComp.yZConstructionPlane)
        lines = sketch.sketchCurves.sketchLines
        arcs = sketch.sketchCurves.sketchArcs
        
        arc0 = arcs.addByCenterStartSweep(hole0_pts.item(4), hole0_pts.item(3), math.pi)     
        line0 = lines.addByTwoPoints(arc0.endSketchPoint, hole0_pts.item(1))
        arc1 = arcs.addByCenterStartSweep(hole0_pts.item(5), line0.endSketchPoint, math.pi)
        line1 = lines.addByTwoPoints(arc1.endSketchPoint, arc0.startSketchPoint)
        
        #arc = arcs.addByCenterStartSweep(hole0_pts.item(4), hole0_pts.item(3), math.pi)
        
        # split body with the profile
        bodies = adsk.core.ObjectCollection.create()
        bodies.add(rootComp.bRepBodies.itemByName('Body10'))
        tool = adsk.fusion.Path.create(arc0,adsk.fusion.ChainedCurveOptions.connectedChainedCurves)
        splitInput = splits.createInput(bodies, tool, True)
        splits.add(splitInput)
0 Likes