Command runs slower with each execution

Command runs slower with each execution

Joshua.mursic
Advocate Advocate
734 Views
5 Replies
Message 1 of 6

Command runs slower with each execution

Joshua.mursic
Advocate
Advocate

Hey everyone, I have a weird situation where evetime I run a command, it gets slower and slower. Are there any known causes of this? Turning the addon off and on again does not fix the issue, but when I restart the Fusion360 application the command runs at normal speed and then begins to degrade again.

0 Likes
Accepted solutions (1)
735 Views
5 Replies
Replies (5)
Message 2 of 6

kandennti
Mentor
Mentor
Accepted solution

Hi @Joshua.mursic -San.

 

I don't know what kind of processing you are doing, but I would expect it to be slower if there are many elements to be created.

 

We have had reports in the past of slower processing when there is more Undo Redo history.
If you save the file, close it, and reopen it and the speed improves, that could be the cause.

0 Likes
Message 3 of 6

Joshua.mursic
Advocate
Advocate

Thank you @kandennti, this was the problem. The command created many sketch lines that filled the Undo/Redo history. Do you know of anyway to clear this history? Or to instead create many sketch lines in one step, similar to the spline creation using an ObjectCollection?

0 Likes
Message 4 of 6

kandennti
Mentor
Mentor

@Joshua.mursic -San.

 

I am not aware of any functionality to remove the Undo/Redo history.
The only way I can think of is to let the API do the manual operations.

 

I did a little simple test.
Create a new document and save it once.
Then run this script, which will create, save, close, and reopen the sketch repeatedly.

# Fusion360API Python script

import traceback
import adsk
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui: core.UserInterface = None
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface

        for _ in range(5):
            des: fusion.Design = app.activeProduct
            root: fusion.Component = des.rootComponent
            root.sketches.add(root.xYConstructionPlane)
            adsk.doEvents()

            refresh_undo_redo(app.activeDocument)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def refresh_undo_redo(
        doc: fusion.FusionDocument
) -> None:
    if not doc.isModified: return

    dataFile: core.DataFile = doc.dataFile
    if not dataFile: return

    app: core.Application = doc.parent

    doc.save("api save")
    doc.close(True)

    docs: core.Documents = app.documents
    docs.open(dataFile)


However, depending on the timing and the size of the data, it may not work correctly.

0 Likes
Message 5 of 6

BrianEkins
Mentor
Mentor

Another possible option is to call the Transaction.Trim text command to clean the current undo stack. You can do this using the line below.

app.executeTextCommand("Transaction.Trim") 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 6 of 6

Joshua.mursic
Advocate
Advocate

Thanks @BrianEkins, that's perfect.

0 Likes