occurence.transform is super slow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I try to improve the speed of my "Import IDF" add-in.
Basically, the code creates a board and places electrical components on it. So I heavily use the occurence.transform property. And this transformation takes ages even in its simpliest form.
import adsk.core, adsk.fusion, adsk.cam, traceback import time def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface design = adsk.fusion.Design.cast(app.activeProduct) design.designType = adsk.fusion.DesignTypes.DirectDesignType rootComponent = design.rootComponent trans = adsk.core.Matrix3D.create() occ = rootComponent.occurrences.addNewComponent(trans) firstComp = occ.component firstComp.name = '0' sketches = firstComp.sketches sketchesPlane = firstComp.xYConstructionPlane sketch1 = sketches.add(sketchesPlane) sketch1.name = 'Square' lines = sketch1.sketchCurves.sketchLines; lines.addTwoPointRectangle(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(2, 2, 0)) extrudes = firstComp.features.extrudeFeatures extrudeInput1 = extrudes.createInput(sketch1.profiles.item(0), adsk.fusion.FeatureOperations.NewBodyFeatureOperation) distance = adsk.core.ValueInput.createByReal(2.0) extrudeInput1.setSymmetricExtent(distance, True) extrudes.add(extrudeInput1) trans = adsk.core.Matrix3D.create() start_time = time.time() for i in range(0, 200): occ = rootComponent.occurrences.addExistingComponent(firstComp, trans) # occ.transform = trans elapsed_time = time.time() - start_time app.activeViewport.refresh() adsk.doEvents() ui.messageBox('{:.2f} s'.format(elapsed_time)) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
On my machine, it takes 5 seconds to create 200 occurences. Now if I uncomment the line with the transform action, the same code takes 18 seconds to finish. It's approximatly x4 just for a matrix product!
Note that I can't use the Component.transformOccurrences method because as I said before, in my real design, there are many different components (up to 1500).
For example, my add-in takes 26 seconds to create 277 components. It takes 74 seconds to create the same components with transformation. And the elapsed time is not linear. It's getting worst and worst.
Do you have any idea to accelerate this code?
Thanks.
Jérôme Briot, Freelance engineer - Mechanical design and prototyping
3D Print Plus / Pro | IDF Import | GitHub To Fusion 360 | Tube Bending Data Exchanger | Slice Data Export
Memory Used | Basic Calculator | Check Computer Specifications | Import spline from any CSV file