There is a bug in when using the API to create a circular pattern feature within a component besides the root component. It has been fixed for the next release but the problem exists in the released version. There is a way to work around the problem in the current release, which is to create the pattern in the context of the root component. This is actually how everything is done in Fusion when using it interactively. Below is a small Python script that demonstrates the workaround. The key to this is understand the "context" of the geometry and where you're working. If I create the pattern in the context of the root, the goemetry also needs to exist in the root context. In the program below, when it first gets the cylindrical face, which is used as the pattern axis, and the body that will be patterned, they're in the context of the sub component. If there were two instances of this component then there would be two cylinders and two bodies from the context of the assembly (the root component) and to create the pattern you need to uniquely specify one of them. This is done using the createForAssemblyContext method. This creates objects that represent the face and body in the context of the assembly. This new object contains the path of which occurrence the geometry is with respect to. These objects are also referred to as "proxy" objects because they represent an object.
import adsk.core, adsk.fusion, traceback
def main():
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
rootComp = design.rootComponent
newOcc = design.rootComponent.occurrences.addNewComponent(adsk.core.Matrix3D.create())
comp = newOcc.component
baseSketch = comp.sketches.add(comp.xYConstructionPlane)
baseSketch.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 2)
baseSketch.sketchCurves.sketchLines.addCenterPointRectangle(adsk.core.Point3D.create(-0,3.5,0), adsk.core.Point3D.create(1,4.5,0))
if baseSketch.profiles.item(0).profileLoops.item(0).profileCurves.count == 1:
circleProfile = baseSketch.profiles.item(0)
rectangleProfile = baseSketch.profiles.item(1)
else:
circleProfile = baseSketch.profiles.item(1)
rectangleProfile = baseSketch.profiles.item(0)
extrudes = comp.features.extrudeFeatures
extInput = extrudes.createInput(circleProfile, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
distance = adsk.core.ValueInput.createByReal(10)
extInput.setDistanceExtent(False, distance)
cylinderExtrude = extrudes.add(extInput)
extInput = extrudes.createInput(rectangleProfile, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
distance = adsk.core.ValueInput.createByReal(5)
extInput.setDistanceExtent(False, distance)
rectangleExtrude = extrudes.add(extInput)
cylFace = cylinderExtrude.sideFaces.item(0)
cylFace = cylFace.createForAssemblyContext(newOcc)
boxBody = rectangleExtrude.faces.item(0).body
boxBody = boxBody.createForAssemblyContext(newOcc)
circularPatterns = rootComp.features.circularPatternFeatures
entities = adsk.core.ObjectCollection.create()
entities.add(boxBody)
patternInput = circularPatterns.createInput(entities, cylFace)
numInstances = adsk.core.ValueInput.createByString("6")
patternInput.quantity = numInstances
pattern = circularPatterns.add(patternInput)
except Exception:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
main()