- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
try:
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()
inputEntites.add(body)
# 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()
inputEntites2.add(rootComp.bRepBodies.item(all))
rectangularPatternInput2 = rectangularPatterns.createInput(inputEntites2, zAxis, quantityThree, distanceThree, adsk.fusion.PatternDistanceType.SpacingPatternDistanceType)
rectangularFeature2 = rectangularPatterns.add(rectangularPatternInput2)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.