I'm trying to create a circular pattern using the following code. It creates the pattern but not the same way the GUI does and it creates a something in the component tree which will cause a hard crash of Fusion 360.
Here's my code:
class fusionAPI: def __init__(self): try: self.app = adsk.core.Application.get() self.core = adsk.core self.ui = self.app.userInterface self.product = self.app.activeProduct self.design = adsk.fusion.Design.cast(self.product) self.rootComp = self.design.rootComponent self.sketches = self.rootComp.sketches self.pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062 self.globalOrigin = adsk.core.Point3D.create(0,0,0) self.extrudes = self.rootComp.features.extrudeFeatures self.getUserParameterNames() self.orientAligned = adsk.fusion.DimensionOrientations.AlignedDimensionOrientation self.orientHorizontal = adsk.fusion.DimensionOrientations.HorizontalDimensionOrientation self.orientVertical = adsk.fusion.DimensionOrientations.VerticalDimensionOrientation except: if self.ui: self.ui.messageBox('Problem in __init__:\n{}'.format(traceback.format_exc())) def circularPatternFeature(self,feature, axis = None, n = 6, totalAngle = 360, AngleUnits = 'deg'): if axis == None: axis = self.rootComp.yConstructionAxis if not isinstance(n,str): n = str(n) if not isinstance(totalAngle,str): totalAngle = str(totalAngle) totalAngle += ' ' + AngleUnits #Create a new component to stick the pattern in newOcc = self.rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create()) # grab the body from the feature anc create an Assembly Context in the new component body = feature.faces.item(0).body body = body.createForAssemblyContext(newOcc) # create an assembly contect for the axis as well in the new component axis = self.rootComp.yConstructionAxis.createForAssemblyContext(newOcc) # create an object collection and add the body to it entities = adsk.core.ObjectCollection.create() entities.add(body) # create a circular pattern circularPatterns = self.rootComp.features.circularPatternFeatures patternInput = circularPatterns.createInput(entities,axis) numInstances = adsk.core.ValueInput.createByString(n) totalAngle = adsk.core.ValueInput.createByString(totalAngle) patternInput.quantity = numInstances patternInput.totalAngle = totalAngle circularPatterns.add(patternInput) return newOcc
create in insance of fusionAPI and then pass a feature into circularPatternFeature
This is what I get:
The original component was the Single_Segment:1. I turned off the visibility to highlight the new component (Component2:1). Now look at the C-Pattern1 Group(8). It does indeed have 8 bodies, but notice that it has 2 bodies labled Body1. If I click on the first Body 1 or even mouse over it, it will cause a crash.
Am I doing something wrong or is this a bug?
I'm beginning to think this is a bug and that it is not doing some cleanup like it should. If you return the created component to a variable called pComp and do print(pComp.component.bRepBodies.count) you only get 7 bodies, not 8 like the component tree shows. If I go and create a new pattern in the gui after creating the one from the script, the mistery component disappears.
Thank you for posting the issue.
We verifed the workflow with your scipts, they worked as expected on the next release build, while we can reproduce the issue with the previous release, so I assume the issue should have been fixed in the new release (coming soon).
From your scripts it looks there is a bug: if a body is not inside of a component, the assembly context with the component for this body should be invalid. We will figure out the solution soon.
# grab the body from the feature anc create an Assembly Context in the new component
body = feature.faces.item(0).body
body = body.createForAssemblyContext(newOcc)