Split Body using multiple splitting tools

Split Body using multiple splitting tools

ChapmanM605
Participant Participant
569 Views
2 Replies
Message 1 of 3

Split Body using multiple splitting tools

ChapmanM605
Participant
Participant

Hi,

 

I am experienced on F360 but new to API, I have a tiny bit of Python knowledge so please forgive any rookie errors.

 

I am writing a script that splits a body into multiple, concentric cylinders. I want the script to be able to take limited inputs and then be able to conduct the process automatically from that data. For example - the spacing or pitch of the concentric cylinders determines how many there are within the start point (0,0,0) and outer radius decided by the user. I have managed to get this part to work correctly, a loop takes this information and sketches concentric circles on the end of a cylinder (1st picture). However, what I cant get to work is to be able to select all of the circle sketches as splitting tools which is allowed in the normal F360 design environment. (2nd picture) I have also tried to loop through each circle but that stops after the first split which I 'think' might be the fact that the original target body 'disappears' as it turns into two new bodies so loses its reference? This is the code version i include below but i have tried other ideas.

 

This is my code - forgive any rookie errors. Any help is appreciated on how i can efficiently, without needing to define and use every circle 'line by line' as a splitting tool, split the target body using all previously generated sketch circles.

 

Thank you

 

Matt

 

import adsk.core, adsk.fusion, traceback
import math

def run(context😞
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
       
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
       
        design = app.activeProduct

        # Get the root component of the active design.
        rootComp = design.rootComponent

        # Get extrude features
        extrudes = rootComp.features.extrudeFeatures

        # Create a new sketch on the xy plane.
        sketches = rootComp.sketches
        xyPlane = rootComp.xYConstructionPlane
        sketch = sketches.add(xyPlane)

        Interval = 0.1
        Outerradius = 5
        Factor = 10
        SInt = int(Interval * Factor)
        SOR = int(Outerradius * Factor)
        distance1 = adsk.core.ValueInput.createByReal(5)

        radius = [(x+(Interval*Factor))/Factor for x in range(SInt,SOR,SInt)]
       
        # Draw the circles.
        circles = sketch.sketchCurves.sketchCircles
        for r in radius:
            circle1 = [circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), r)]
       
        # Create a target body to use as a test case
        sketch2 = sketches.add(xyPlane)
        circles = sketch2.sketchCurves.sketchCircles
        circle100 = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 10)
        profile100 = sketch2.profiles.item(0)
        extrude2 = extrudes.addSimple(profile100, distance1, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
         
        body = extrude2.bodies.item(0)
        # Create SplitBodyFeatureInput
        splitBodyFeats = rootComp.features.splitBodyFeatures
        for x in circle1:
           splitBodyInput = splitBodyFeats.createInput(body, x, True)
       
        # Create split body feature
        splitBodyFeats.add(splitBodyInput)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Accepted solutions (1)
570 Views
2 Replies
Replies (2)
Message 2 of 3

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi,

 

The split body feature allows only to make it with a single tool at a time as it stated in the documentation:

Jorge_Jaramillo_0-1725371817342.png

 

In your code I fixed three errors you had:

1. circle1 was a list that kept just the last circle in the loop; need to be filled with every circle in the sketch.

2. splitBodyFeats.add() was called only at the end of the loop; need to be called for every split body input created.

3. body wasn't updated to keep the outer splitted part in preparation to the next split.

 

Here you have the script source code:

import adsk.core, adsk.fusion, traceback
import math

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
       
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
       
        design: adsk.fusion.Design = adsk.fusion.Design.cast(app.activeProduct)

        # Get the root component of the active design.
        rootComp = design.rootComponent

        # Get extrude features
        extrudes = rootComp.features.extrudeFeatures

        # Create a new sketch on the xy plane.
        sketches = rootComp.sketches
        xyPlane = rootComp.xYConstructionPlane
        sketch = sketches.add(xyPlane)

        Interval = 0.1
        Outerradius = 5
        Factor = 10
        SInt = int(Interval * Factor)
        SOR = int(Outerradius * Factor)
        distance1 = adsk.core.ValueInput.createByReal(5)

        radius = [(x+(Interval*Factor))/Factor for x in range(SInt,SOR,SInt)]
       
        # Draw the circles.
        circles = sketch.sketchCurves.sketchCircles
        # for r in radius:
        circle1 = [circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), r) for r in radius]
       
        # Create a target body to use as a test case
        sketch2 = sketches.add(xyPlane)
        circles = sketch2.sketchCurves.sketchCircles
        circle100 = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 10)
        profile100 = sketch2.profiles.item(0)
        extrude2 = extrudes.addSimple(profile100, distance1, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
         
        body = extrude2.bodies.item(0)
        # Create SplitBodyFeatureInput
        splitBodyFeats = rootComp.features.splitBodyFeatures
        for x in circle1:

            splitBodyInput = splitBodyFeats.createInput(body, x, True)
       
            # Create split body feature
            sbf = splitBodyFeats.add(splitBodyInput)
            body = sbf.bodies[1]
    except:
        # if ui:
        #     ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
        app.log('Failed:\n{}'.format(traceback.format_exc()))

 

Regards,

Jorge Jaramillo

 

Message 3 of 3

ChapmanM605
Participant
Participant

That is incredibly helpful, thank you for taking time to help!

 

Matt

0 Likes