The following runs in just under 1 second on my machine 🙂
import adsk.core
import adsk.fusion
from adsk.core import Point3D, Vector3D, OrientedBoundingBox3D, Matrix3D
import time
def app():
return adsk.core.Application.get()
def design():
return adsk.fusion.Design.cast(app().activeProduct)
def root() -> adsk.fusion.Component:
return design().rootComponent
def brep():
return adsk.fusion.TemporaryBRepManager.get()
def rect(x, y, width, height):
# The top face of a box is always index 0
top_index = 0
top_face = brep().createBox(OrientedBoundingBox3D.create(
Point3D.create(
x + width/2,
y + width/2,
-.5),
Vector3D.create(1, 0, 0),
Vector3D.create(0, 1, 0),
width, height, 1)).faces[top_index]
return brep().copy(top_face)
def circle(x, y, radius):
# The top face of a cylinder is always index 2
top_index = 2
top_face = brep().createCylinderOrCone(
Point3D.create(x, y, -1), radius,
Point3D.create(x, y, 0), radius).faces[top_index]
return brep().copy(top_face)
def difference(target, *tools):
for tool in tools:
brep().booleanOperation(target, tool, adsk.fusion.BooleanTypes.DifferenceBooleanType)
return target
def union(*bodies):
target = None
for body in bodies:
if target is None:
target = body
else:
brep().booleanOperation(target, body, adsk.fusion.BooleanTypes.UnionBooleanType)
return target
def create_occurrence(body):
occurrence = root().occurrences.addNewComponent(Matrix3D.create())
occurrence.component.bRepBodies.add(body)
return occurrence
def run(_):
start = time.time()
design().designType = adsk.fusion.DesignTypes.DirectDesignType
sheets = []
for row in range(0, 10):
for col in range(0, 20):
sheet = rect(col * 102, row * 102, 100, 100)
hole = circle(col * 102 + 20, row * 102 + 20, 2)
sheets.append(difference(sheet, hole))
occurrence = create_occurrence(union(*sheets))
sketch = root().sketches.add(root().xYConstructionPlane)
sketch.include(occurrence.bRepBodies[0])
occurrence.deleteMe()
end = time.time()
print(end-start)