Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Time increase when a script is executed successively on the same document

2 REPLIES 2
Reply
Message 1 of 3
JeromeBriot
320 Views, 2 Replies

Time increase when a script is executed successively on the same document

Hello,

 

Here is a code that creates 200 components every time it is executed:

 

import adsk.core, adsk.fusion, traceback
import random
import time
import math

def run(context):
    ui = None
    try:

        app = adsk.core.Application.get()
        ui = app.userInterface

#        x = [[0,1,1,0,0], [1,2,2,0,0,1,1], [0,2,2,0], [0,1,1,0,0]]
#        y = [[0,0,1,1,0], [0,0,2,2,1,1,0], [0,0,1,0], [0,0,1,1,0]]
#        h = [0.2, 0.5, 0.1, 0.2]

        numIteration = 200

        trans = adsk.core.Matrix3D.create()
        transformTrans = adsk.core.Matrix3D.create()
        transformRot = adsk.core.Matrix3D.create()
        transformFlip = adsk.core.Matrix3D.create()

        vector = adsk.core.Vector3D.create(0.0, 0.0, 0.0)
        vectorY = adsk.core.Vector3D.create(0.0, 1.0, 0.0)
        vectorZ = adsk.core.Vector3D.create(0.0, 0.0, 1.0)

        origin = adsk.core.Point3D.create(0.0, 0.0, 0.0)

        design = adsk.fusion.Design.cast(app.activeProduct)
        design.designType = adsk.fusion.DesignTypes.DirectDesignType

        rootComponent = design.rootComponent

        start_time = time.time()

        for i in range(0, numIteration):

#            n = random.randint(0, 3)

            trans.setToIdentity()

            vector.x = 100*random.random()
            vector.y = 100*random.random()
            vector.z = 0.0

            if random.random() > 0.5:
                transformFlip.setToRotation(math.pi, vectorY, origin)
                trans.transformBy(transformFlip)

            transformRot.setToRotation(random.random()*math.pi, vectorZ, origin)
            trans.transformBy(transformRot)

            transformTrans.translation = vector
            trans.transformBy(transformTrans)

            occ = rootComponent.occurrences.addNewComponent(trans)

#            comp = occ.component

#            sketches = comp.sketches
#            sketchesPlane = comp.xYConstructionPlane
#
#            sketch = sketches.add(sketchesPlane)
#            sketch.isComputeDeferred = True
#            sketch.isLightBulbOn = False
#
#            lines = sketch.sketchCurves.sketchLines
#
#            for j in range(0, len(x[n])-1):
#                lines.addByTwoPoints(adsk.core.Point3D.create(x[n][j], y[n][j], 0), adsk.core.Point3D.create(x[n][j+1], y[n][j+1], 0))
#
#            sketch.isComputeDeferred = False
#
#            distance = adsk.core.ValueInput.createByReal(h[n])
#            extrudes = comp.features.extrudeFeatures
#            extrude = extrudes.addSimple(sketch.profiles.item(0), distance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
#            extrude.dissolve()

        elapsed_time = time.time() - start_time

        app.activeViewport.fit()
        app.activeViewport.refresh()
        adsk.doEvents()

        print('{:.2f}s'.format(elapsed_time))

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

 

 

And here are the elapsed times for successive run on my machine (Intel i7-3770K, RAM 16GB, NVidia GTX 960, Windows 7):

  • Run 1: 0.69s
  • Run 2: 1.44s
  • Run 3: 2.47s
  • Run 4: 3.55s
  • Run 5: 4.92s

Here are the same results with all the lines uncommented (sketch and extrusion):

  • Run 1: 5.64s
  • Run 2: 12.64s
  • Run 3: 20.63s
  • Run 4: 29.38s
  • Run 5: 37.47s

Why ?

Does it take so much time to refresh the viewport with the components added at each iteration?

 

Thank you

2 REPLIES 2
Message 2 of 3
MichaelT_123
in reply to: JeromeBriot

Hi Mr. Jerome Briot,

 

Your observation/experiment is symptomatic of similar experiences many are having... seating in silence.

I have posted some time ago some rumblings about it.

The link is:

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/undo-via-api/m-p/8646925#M7521

 

It is a little gastric... so consider reading it while not eating.

 

With Regards

MichaelT

MichaelT
Tags (1)
Message 3 of 3
JeromeBriot
in reply to: MichaelT_123

Thank you @MichaelT_123 

 

Maybe someone from Autodesk will give us a valid reason for such a behavior. I hope so.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators