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()))