Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Collect all BRep Bodies to Create a Pattern

Message 1 of 3
778 Views, 2 Replies

Collect all BRep Bodies to Create a Pattern

Hopefully this is an easy one!


I'm trying to create a 3D array of BRep cube bodies. I want the array to be 3 x 4 x 5 bodies (60 bodies in total).


I'm using a "rectangular pattern" example to create a 3 x 4 array of cubes in the XY plane. Then, I want to collect all the cubes in the root component do a 1D pattern in the Z direction.


I can't figure out how to actually add all the bodies from the first rectangular pattern to the input objects for the second 1D pattern operation. I see a way to grab one of them using rootComp.BRepbodies.item(n) where 0<n+1<11. Is there something I can use to add all the existing bodies at once? I tried rootComp.BRepbodies.item(*), rootComp.BRepbodies.item(:), rootComp.BRepbodies.item(all), but those didn't seem to work.


here is my code:


import adsk.core, adsk.fusion, traceback


def run(context):

ui = None


app = adsk.core.Application.get()

ui = app.userInterface


# Create a document.

doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)


product = app.activeProduct

design = adsk.fusion.Design.cast(product)


# Get the root component of the active design.

rootComp = design.rootComponent


# Create sketch

sketches = rootComp.sketches

sketch = sketches.add(rootComp.xZConstructionPlane)

lines = sketch.sketchCurves.sketchLines;


# Draw a rectangle by two points.

recLines = lines.addTwoPointRectangle(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(1, 1, 0))


# Get the profile defined by the circle.

prof = sketch.profiles.item(0)


# Create an extrusion input

extrudes = rootComp.features.extrudeFeatures

extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)


# Define that the extent is a distance extent of 5 cm.

distance = adsk.core.ValueInput.createByReal(1)

extInput.setDistanceExtent(False, distance)


# Create the extrusion.

ext = extrudes.add(extInput)


# Get the body created by extrusion

body = ext.bodies.item(0)


# Create input entities for rectangular pattern

inputEntites = adsk.core.ObjectCollection.create()



# Get x and y axes for rectangular pattern

xAxis = rootComp.xConstructionAxis

yAxis = rootComp.yConstructionAxis

zAxis = rootComp.zConstructionAxis


# Quantity and distance

quantityOne = adsk.core.ValueInput.createByString('3')

distanceOne = adsk.core.ValueInput.createByString('1 cm')

quantityTwo = adsk.core.ValueInput.createByString('4')

distanceTwo = adsk.core.ValueInput.createByString('1 cm')

quantityThree = adsk.core.ValueInput.createByString('5')

distanceThree = adsk.core.ValueInput.createByString('1 cm')


# Create the input for rectangular pattern

rectangularPatterns = rootComp.features.rectangularPatternFeatures

rectangularPatternInput = rectangularPatterns.createInput(inputEntites, xAxis, quantityOne, distanceOne, adsk.fusion.PatternDistanceType.SpacingPatternDistanceType)


# Set the data for second direction

rectangularPatternInput.setDirectionTwo(yAxis, quantityTwo, distanceTwo)


# Create the rectangular pattern

rectangularFeature = rectangularPatterns.add(rectangularPatternInput)


# Second pattern

inputEntites2 = adsk.core.ObjectCollection.create()


rectangularPatternInput2 = rectangularPatterns.createInput(inputEntites2, zAxis, quantityThree, distanceThree, adsk.fusion.PatternDistanceType.SpacingPatternDistanceType)

rectangularFeature2 = rectangularPatterns.add(rectangularPatternInput2)




if ui:


Message 2 of 3
in reply to: Lawsmith408

I think you are looking for a method on BrepBodies which returns a collection object containing all bodies. No such method exists at present and only way is to create a collection object explicitly and add each body one by one.

Shyam Goyal
Sr. Software Dev. Manager
Message 3 of 3
in reply to: goyals

Yes, that's exactly what I was looking for. I found an example of adding bodies one by one in a for loop - thanks for the help.


for k in range(0, rootComp.bRepBodies.count):


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th

Autodesk Design & Make Report