Script performance degradation / Release Memory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good Morning!
I have a script that processes fairly large amounts of information and I am running into some memory / speed issues.
As a starting point, my script produces alot of temporary geometry and then deletes that temporary geometry once it is no longer needed. In the sample script below, I create and delete a simple extrude 10,000 times, and it seems to exhibit the same behavior as my larger script.
On Startup: Fusion Private Memory= 1,455 MB Speed= 80 create/delete cycles per second
Script Finished: Fusion Private Memory= 2,700 MB Speed=2 create/delete cycles per second
Is there any way I can get fusion to release the memory after I delete the object? I assume the accumulating memory is what is slowing the script down?
On a similar note, is there a way to clear out transient objects?
Thanks in advance!
import adsk.core, adsk.fusion, traceback def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface product = app.activeProduct design = adsk.fusion.Design.cast(product) rootComp = design.rootComponent extrudes = rootComp.features.extrudeFeatures sketches = rootComp.sketches centerPoint = adsk.core.Point3D.create(0, 0, 0) nIterations=10000 progressdialog=ui.createProgressDialog() progressmessage="Extrude create/delete: %v of %m, %p% Complete" progressdialog.show("Progress Dialog", progressmessage,0,nIterations) #(title, message, minimumValue, maximumValue, delay) adsk.doEvents() for i in range(nIterations): if (i%10)==0: if progressdialog.wasCancelled: break progressdialog.progressValue=i sketch = sketches.add(rootComp.xZConstructionPlane) sketchCircles = sketch.sketchCurves.sketchCircles circle = sketchCircles.addByCenterRadius(centerPoint, 5.0) prof = sketch.profiles.item(0) distance = adsk.core.ValueInput.createByReal(5) extrude1 = extrudes.addSimple(prof, distance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation) # Get the extrusion body body1 = extrude1.bodies.item(0) sketch.deleteMe() body1.deleteMe() except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))