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: 

Strange Sketch Copy / Move Behaviour

19 REPLIES 19
Reply
Message 1 of 20
asheepcalledgeorge
1753 Views, 19 Replies

Strange Sketch Copy / Move Behaviour

One of the things that always takes me ages in Fusion is to lay out parts for a laser cutter.  I make my face, create a sketch, then export it to DXF.  Repeat for all the faces, then open Illustrator and lay them out by hand.  Doing about 5 or 10 faces can easily take 10 minutes.  There must be a better way!

 

I've started writing a Python Script / AddIn to speed up this part of my workflow.  However, I can't seem to copy or move all the different includes / projections reliably via the API or the interface.

 

My script runs as follows:

 

  1. Select the faces of interest.
  2. Project each face onto a new sketch defined in the plane of the face (this can be shared or dedicated to the face, the error is the same).
  3. Compute the bounding box of the SketchEntities (aka. group of lines) that are returned.
  4. Run a simple greedy rectangle packing algorithm (this part is tested externally from fusion and always generates valid results).
  5. Then, in one step, move each group of lines back to the origin and add the offset from the rectangle packer.

What I am seeing is that this works for 95% of planar faces, but some refuse to move - or move in an unexpected way.  For instance, I can open up the generated sketch and select the problematic entities, but when I Move them, they will become separated from the move gizmo.

 

I have checked:

  • There are 0 geometric constraints on the projected entities.
  • I set isReference to False.
  • isComputeDeffered = False.
  • Giving each projection its own Sketch.

I'm at a bit of a loose end, any help would be greatly appreciated!

 

 flat_packed.pngselection.png

19 REPLIES 19
Message 2 of 20
ekinsb
in reply to: asheepcalledgeorge

Looks like a very useful program.  It's unclear to me exactly what you're doing in step 5.  You would have sketches in all different orientations within the model.  If you can provide a simple model and a small amount of code in a script that reproduces the problem it would make it much easier for us to understand what the problem is.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 20
asheepcalledgeorge
in reply to: ekinsb

Thanks for the reply!

 

Here is the code: https://pastebin.com/gpL70cCv
Here is my test shape: http://a360.co/2vFQhmb It has 2 components and a body in the root component.

 

Here, I run the script and select all the faces in the scene. Press go, the "processing" bar goes crazy for a few seconds and then the result is returned in a new sketch called "Sheet 1". I would expect the two selected faces (see image below) to also move into the packed grid with the other parts.

 

selected_to_grid.png

 

The relevant code is:

 

 

transform = adsk.core.Matrix3D.create()
transform.translation = adsk.core.Vector3D.create(dx + x, dy + y, dz + z)
pts = self.projection_sketch.copy(self.entity_collection, transform, target_sketch)

The values (dx, dy, dz) are the offset from the centre of the bounding box to the sketch origin. When I transform by JUST these (without the pack offset, (x,y,z), the stubborn faces move to the middle. I thought that it would just be because of a different sketch direction, but it seems any other transform doesn't work correctly all the time either.

 

Cheers!

Message 4 of 20
ekinsb
in reply to: asheepcalledgeorge

Although I would like to, I don't really have the time to spend time fully understand what your program is doing.  Would it be possible to boil it down to a design and a small script that illustrates the problem with copying a sketch you're seeing.  It seems like you should be able to have an existing sketch (possibly created by your program) and a small script that does the copy of the entities.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 20
asheepcalledgeorge
in reply to: ekinsb

Yea, sure thing!

 

Here is the slimmed down code.  The shape is the same as the one linked in my previous post.  

 

What this does is lay out all the selected planar faces in a long line with a fixed spacing (6cm).  I would expect all the faces to be transformed correctly with the `copy` operation, but this is not the behaviour we see.  Curiously, moving them all to the centre works just fine (see commented out code).

 

testcase.png

 

 

Thanks for your help so far.  I am really keen to get to the bottom of this!

 

 

#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback
    
def _bounding_dims(entity_list):
    ''' Compute a bounding box, size, and centroid for specified sketch entities. '''
    bbox = None
    for e in entity_list:
        if not bbox:
            bbox = e.boundingBox.copy()
        else:
            bbox.combine(e.boundingBox)
    width = bbox.maxPoint.x - bbox.minPoint.x
    height = bbox.maxPoint.y - bbox.minPoint.y
    centroid = adsk.core.Vector3D.create(
        ((bbox.maxPoint.x - bbox.minPoint.x) / 2.0) + bbox.minPoint.x,
        ((bbox.maxPoint.y - bbox.minPoint.y) / 2.0) + bbox.minPoint.y,
        ((bbox.maxPoint.z - bbox.minPoint.z) / 2.0) + bbox.minPoint.z)
    return bbox, width, height, centroid
    
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        # Get all the selected planar faces.        
        plane = adsk.core.Plane.classType()
        face = adsk.fusion.BRepFace.classType()
        selections = [ui.activeSelections.item(i) for i in range(ui.activeSelections.count)]
        planar_faces = [s.entity for s in selections if s.entity.classType() == face and s.entity.geometry.objectType == plane]
        print ("You selected ", len(planar_faces), " planar faces")
        if len(planar_faces) == 0:
            ui.messageBox("Select at least one planar face.")
        
        # Create a target sketch to copy all the projected entities into.
        # This is the sketch everything gets laid out into.
        target_sketch = app.activeProduct.rootComponent.sketches.add(app.activeProduct.rootComponent.xZConstructionPlane)
        target_sketch.name = "Sheet of Material"

        # For each face, project into a temp sketch.
        x_offset = 0
        for face in planar_faces:
            # Create the temp sketch to project into.
            temp_sketch = app.activeProduct.rootComponent.sketches.add(face)
            temp_sketch.name = "Temp Face Projection"
            sketch_entities = temp_sketch.project(face)
            
            # Calculate bounding dimensions of the sketch entities.
            bbox, w, h, cen = _bounding_dims(sketch_entities)
            
            # Using the values computed above, copy & transform from the temp sketch into the target one.
            # PROBLEM: The copy does not move all the entities in the same way / as expected.
            transform = adsk.core.Matrix3D.create()
            transform.translation = adsk.core.Vector3D.create(-cen.x + x_offset, -cen.y, -cen.z) # note how the transform in y is not even applied here on some faces
            #transform.translation = adsk.core.Vector3D.create(-cen.x, -cen.y, -cen.z) # curiously, this works fine (is cen relative to the sketch?)
            pts = temp_sketch.copy(sketch_entities, transform, target_sketch)
            
            # This does not have the desired effect either. I was hoping that it would move the entities
            # relative to the basis of the target_sketch.
            #transform2 = adsk.core.Matrix3D.create()
            #transform2.translation = adsk.core.Vector3D.create(x_offset, 0, 0)
            #target_sketch.move(pts, transform2)
            
            # Increment the offset position so the next face is moved further along the layout.
            x_offset += 6       # Fixed width layout
            #x_offset += w       # Variable Width layout
            
            # Clean up.
            temp_sketch.deleteMe()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Message 6 of 20
ekinsb
in reply to: asheepcalledgeorge

I've been able to reproduce the problem.  It works with some sketches and doesn't with others and I haven't been able to figure out the difference.  I'll file a bug and we'll look at it in more detail and work on a fix.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 20
asheepcalledgeorge
in reply to: ekinsb

Hi Ekinsb,

 

 

Apologies for the delayed reply, have been away.  Thanks for letting me know about the issue - is there a place to track updates / issues so that I can listen out for progress?

 

In the meantime I'll try and spot a pattern and tidy up the rest of the app.  When running the work from a UI context (i.e. pressing a button to trigger it, rather than running the script) this bar flashes up and takes a VERY long time to complete.  

 

goes_crazy.png 

 

 

By comparison, running the test case directly works just fine - even on the same data.  Is there something I need to do in order to deffer the computation?  I tried the following, but it prevented the sketches from copying and did not prevent the bar.

 

 

sketch.isComputeDeferred = False

 

 

Thanks

 

Message 8 of 20
Anonymous
in reply to: asheepcalledgeorge

Hey sheep - check out my DXF For Laser add-in which performs kerf compensation and produces clean DXF files. It can even split cutouts from perimeter into separate layers in the DXF output. I'd be more than happy to share the code with you if you'd like to extend it. I know i'd love such a feature too 😉 No strings attached, I'll provide it under the MIT licence (translation you can do whatever you want with it - even straight up resell it if you want to be rude).

 

I had to do a considerable amount of tuning to get my add-in to be performant - i managed a 30x-60x speedup over my initial implementation for example.

 

By the way, I've observed strange behavior with compute differed being true - some calls work as one would expect while others dont - namely project always returns and empty list if isComputeDeferred is True. Before projecting i always set isComputeDeferred  to false, then go back to true after projection.

 

 

I played with the sample code and drawing... this looks like a an issue with 2 arcs. I can reproduce it with the following sketch i drew by hand in a new drawing - i just drew 2 circles and trimmed them then select all and try to move the lines and it gets "stuck". The issue still occures even after removing the coincident constraints - and even after then shrinking the smaller arc so the ends of the 2 arcs are not in contact ... ok, deleting one of the arcs and trying to drag the other by its center point - the issue STILL occurs! and the dang slit in the arc spins wildly as i move it - why is it rotating at all 😞

 

bad_move.png

Message 9 of 20
Anonymous
in reply to: asheepcalledgeorge


@asheepcalledgeorge wrote:

Hi Ekinsb,

 

 

Apologies for the delayed reply, have been away.  Thanks for letting me know about the issue - is there a place to track updates / issues so that I can listen out for progress?

 

In the meantime I'll try and spot a pattern and tidy up the rest of the app.  When running the work from a UI context (i.e. pressing a button to trigger it, rather than running the script) this bar flashes up and takes a VERY long time to complete.  

 

goes_crazy.png 

 

 

By comparison, running the test case directly works just fine - even on the same data.  Is there something I need to do in order to deffer the computation?  I tried the following, but it prevented the sketches from copying and did not prevent the bar.

 

 

sketch.isComputeDeferred = False

 

 

Thanks

 


 

+1 - there's even a difference between preview and execute where preview is ~20% FASTER then when running the SAME CODE under execute

 

Here's some numbers from drawing the same sketch geometry in 3 contexts

A1 - add-in execute) 5.355388002004474

A2 - add-in preview) 3.9028928352236107

A3 - naked script run) 3.644889983235771

 

Here's numbers for the same type of sketch geometry but with exactly 5x more curves/lines:

B1 - add-in execute) 58.428408390814184

B2 - add-in preview) 51.400505475693535

B3 - naked script run) 50.852509769802964

 

Here's the draw timings for every curve/line drawn for the B1 case above - you can clearly see how bad performance gets by the end of this execution. I've tired pre-drawing all points then passing sketch points to the draw functions but this had no impact on render time (except the added time of drawing the points - which was actually remarkably slow too). I tried setting all those pre-drawn points as isFixed but apparently setting isFixed on points is a SLOW operation and increased point draw time by about 4-5x.

 

I'd put this in a collapsible section... but i dont see the option to make such a thing 😞

 

The pattern is spline, arc, spline, arc - repeat - all drawn shapes are connected and the first point of any shape is the endSketchPoint of the previous. None of these shapes cross any of the others - (it's actually the trace of a 100 tooth gear).

 

draw start point: 0.0013260013256513048
draw spline: 0.007337285532230453
draw arc...: 0.0018793327071762178
draw spline: 0.008206429258279968
draw arc...: 0.004198515476673492
draw spline: 0.009308693518505606
draw arc...: 0.00539050914994732
draw spline: 0.010636454246196081
draw arc...: 0.006528547882226121
draw spline: 0.011834312585961015
draw arc...: 0.001901031975648948
draw spline: 0.013129231174389133
draw arc...: 0.008919866062569781
draw spline: 0.014609473256314232
draw arc...: 0.010615634675559704
draw spline: 0.016041038597904844
draw arc...: 0.011594447684728948
draw spline: 0.026402146702821483
draw arc...: 0.013391968278483546
draw spline: 0.018043529321403184
draw arc...: 0.01341132168272452
draw spline: 0.018746702957287198
draw arc...: 0.014458751300480799
draw spline: 0.02052516338244459
draw arc...: 0.016194106419789023
draw spline: 0.021735923992309836
draw arc...: 0.01757640855430509
draw spline: 0.02292615826445399
draw arc...: 0.018386905604529602
draw spline: 0.0235736175582133
draw arc...: 0.019295635836897418
draw spline: 0.02494389712501288
draw arc...: 0.028131637154729106
draw spline: 0.05189439023979503
draw arc...: 0.0433393064977281
draw spline: 0.05041444139169471
draw arc...: 0.04449933773230441
draw spline: 0.04933622226872103
draw arc...: 0.045895421834757144
draw spline: 0.051120840594194306
draw arc...: 0.04783457415032899
draw spline: 0.05301894023705245
draw arc...: 0.04715720505191712
draw spline: 0.053374925555544905
draw arc...: 0.04859874032808875
draw spline: 0.05523519809321442
draw arc...: 0.05942345040057262
draw spline: 0.05728812495726743
draw arc...: 0.049946440924031776
draw spline: 0.05945570607218542
draw arc...: 0.05183984883205994
draw spline: 0.05714385413648415
draw arc...: 0.05390567796530377
draw spline: 0.061927663431561086
draw arc...: 0.054498595852237486
draw spline: 0.06273933341617521
draw arc...: 0.056712507840529724
draw spline: 0.06313725110703672
draw arc...: 0.057247072284553724
draw spline: 0.05331510594714928
draw arc...: 0.048871154133848904
draw spline: 0.054197151941480115
draw arc...: 0.04939369601106591
draw spline: 0.05680047785244824
draw arc...: 0.05196564595098607
draw spline: 0.05715880903790094
draw arc...: 0.05264301504848845
draw spline: 0.06953912217068137
draw arc...: 0.052310781633423176
draw spline: 0.05859535934723681
draw arc...: 0.054337903962732526
draw spline: 0.06054594776378508
draw arc...: 0.055611123280868924
draw spline: 0.061647918791095435
draw arc...: 0.05745116271464212
draw spline: 0.06323841662197083
draw arc...: 0.059775037218969373
draw spline: 0.06684606684666505
draw arc...: 0.05916188622995833
draw spline: 0.06638246487909782
draw arc...: 0.061172880721642287
draw spline: 0.06814127866709896
draw arc...: 0.06129809137291886
draw spline: 0.07563016585572768
draw arc...: 0.06389584585122066
draw spline: 0.0703478598215952
draw arc...: 0.06571946421536268
draw spline: 0.07069886017234239
draw arc...: 0.06362900347812683
draw spline: 0.0714727030517679
draw arc...: 0.06872393338562688
draw spline: 0.07480442066844262
draw arc...: 0.06807324852434249
draw spline: 0.07285999015402922
draw arc...: 0.06995551356430951
draw spline: 0.07820973986417812
draw arc...: 0.06935467837683973
draw spline: 0.08395975313305826
draw arc...: 0.07190346288098226
draw spline: 0.07769452882166661
draw arc...: 0.07203747053335974
draw spline: 0.08011722297396773
draw arc...: 0.07506627807379118
draw spline: 0.08267363154573104
draw arc...: 0.08098020879970136
draw spline: 0.08290851148012734
draw arc...: 0.07454520236478857
draw spline: 0.08075999053380656
draw arc...: 0.07651074568366312
draw spline: 0.08567340898207476
draw arc...: 0.08952209704057168
draw spline: 0.08495234811107366
draw arc...: 0.07903137978246377
draw spline: 0.08531097252944164
draw arc...: 0.08260589463588985
draw spline: 0.08992470646626316
draw arc...: 0.08394714409769222
draw spline: 0.08987837559288891
draw arc...: 0.08674869577134814
draw spline: 0.09138764777799224
draw arc...: 0.08486584426464105
draw spline: 0.10326125363735628
draw arc...: 0.08710732018971612
draw spline: 0.10484852590070659
draw arc...: 0.09238288185679266
draw spline: 0.110156929706136
draw arc...: 0.09463931268419401
draw spline: 0.11468621243056987
draw arc...: 0.09507740334811388
draw spline: 0.09880351985611924
draw arc...: 0.09504280180954083
draw spline: 0.10593026382503012
draw arc...: 0.11182161558099324
draw spline: 0.11244473650458531
draw arc...: 0.10341432145924045
draw spline: 0.11207936771825189
draw arc...: 0.10193935757888539
draw spline: 0.10351402080777916
draw arc...: 0.09966240041467245
draw spline: 0.10578100803650159
draw arc...: 0.09853550455045479
draw spline: 0.10708061835885019
draw arc...: 0.11140229185366479
draw spline: 0.106651617929856
draw arc...: 0.10229065116345737
draw spline: 0.11136681061452691
draw arc...: 0.10317152422339859
draw spline: 0.10759260383292713
draw arc...: 0.10200416215411678
draw spline: 0.10914732719265885
draw arc...: 0.10696244530845433
draw spline: 0.12207188147021952
draw arc...: 0.10554818073615024
draw spline: 0.11323588015329733
draw arc...: 0.10736740060110606
draw spline: 0.11463372365597024
draw arc...: 0.11028419299054804
draw spline: 0.11654707143406995
draw arc...: 0.11265527806881437
draw spline: 0.12311198025508929
draw arc...: 0.12252111500220053
draw spline: 0.11703853057224478
draw arc...: 0.11491786679835059
draw spline: 0.12124173778283875
draw arc...: 0.11698428239742498
draw spline: 0.12192115951529559
draw arc...: 0.1165227330639027
draw spline: 0.12243871642385784
draw arc...: 0.11885804366920638
draw spline: 0.1358614742066493
draw arc...: 0.11936445771061699
draw spline: 0.12460160580394586
draw arc...: 0.12186485870734032
draw spline: 0.12640352489961515
draw arc...: 0.1214481740798874
draw spline: 0.1297847989571892
draw arc...: 0.12227391926626296
draw spline: 0.14028343351583317
draw arc...: 0.12298002523584728
draw spline: 0.13210280879502534
draw arc...: 0.12638710383089347
draw spline: 0.13117032665923034
draw arc...: 0.1261780284339693
draw spline: 0.13266523040965694
draw arc...: 0.13917647752168705
draw spline: 0.13274880192147975
draw arc...: 0.12799490243105538
draw spline: 0.13695846026712388
draw arc...: 0.1292059562738359
draw spline: 0.13451846534553624
draw arc...: 0.1304882658259885
draw spline: 0.13718483643333457
draw arc...: 0.1431260378631123
draw spline: 0.13808359673021187
draw arc...: 0.13372204349616368
draw spline: 0.13846714598639664
draw arc...: 0.13308162180419458
draw spline: 0.14089277247148857
draw arc...: 0.1382196570166343
draw spline: 0.1543331242583008
draw arc...: 0.1386354619435224
draw spline: 0.14371719634891633
draw arc...: 0.13809884486545343
draw spline: 0.14500625026903435
draw arc...: 0.13781088969062694
draw spline: 0.14604928138760442
draw arc...: 0.1503082029394136
draw spline: 0.14700023722616606
draw arc...: 0.13965034265766008
draw spline: 0.14671990611805086
draw arc...: 0.14128394579529413
draw spline: 0.14813651655822468
draw arc...: 0.14456434757175884
draw spline: 0.16563521826628858
draw arc...: 0.14470568605975132
draw spline: 0.15403461268124374
draw arc...: 0.14789049375576724
draw spline: 0.15364285289069812
draw arc...: 0.14993931535263982
draw spline: 0.1555682232374238
draw arc...: 0.16028986705623538
draw spline: 0.15643971283043356
draw arc...: 0.162815192889866
draw spline: 0.16675009156188025
draw arc...: 0.1611953717219876
draw spline: 0.16835642399564676
draw arc...: 0.17606318358230055
draw spline: 0.17083219338837807
draw arc...: 0.16221347800274089
draw spline: 0.16817608546989504
draw arc...: 0.1616833120588126
draw spline: 0.16964870348328986
draw arc...: 0.1634233589120413
draw spline: 0.1818043998491703
draw arc...: 0.16383417887209362
draw spline: 0.17107147182377958
draw arc...: 0.1639429684546485
draw spline: 0.17502161863103538
draw arc...: 0.16924022939019778
draw spline: 0.1867295476322397
draw arc...: 0.16916281577960035
draw spline: 0.17630891315093322
draw arc...: 0.170223734134197
draw spline: 0.17942334483632294
draw arc...: 0.17332907558466104
draw spline: 0.19040991973361088
draw arc...: 0.1747732499607082
draw spline: 0.17796480202468956
draw arc...: 0.17555970187549974
draw spline: 0.18289581447425007
draw arc...: 0.1765531765531705
draw spline: 0.19580424091691384
draw arc...: 0.17675785344999895
draw spline: 0.1841098006507309
draw arc...: 0.17855771991162328
draw spline: 0.1858589377388853
draw arc...: 0.19115737160791468
draw spline: 0.18629761486954521
draw arc...: 0.1799233077435929
draw spline: 0.18726909704309946
draw arc...: 0.183053867264789
draw spline: 0.1921247485161075
draw arc...: 0.1983377772858148
draw spline: 0.19079170958866598
draw arc...: 0.1837294769620712
draw spline: 0.1946034502425391
draw arc...: 0.18700108173743502
draw spline: 0.20675357517393422
draw arc...: 0.18767639820271143
draw spline: 0.19589338386322197
draw arc...: 0.18965718965682754
draw spline: 0.19856679255190102
draw arc...: 0.19063893499969709
draw spline: 0.2090666000440251
draw arc...: 0.19407738956579124
draw spline: 0.20559706273979828
draw arc...: 0.1948151647402483
draw spline: 0.20041328311981488
draw arc...: 0.20641987559338304
draw spline: 0.20027751606721722
draw arc...: 0.19704520456343744
draw spline: 0.20179235968680587
draw arc...: 0.19627957221928227
draw spline: 0.21630418622862635
draw arc...: 0.19617547437155736
draw spline: 0.2038227075818213
draw arc...: 0.1979750475993569
draw spline: 0.20466839263826841
draw arc...: 0.1998461697703533
draw spline: 0.21970100165526674
draw arc...: 0.20555894240078487
draw spline: 0.2084836520925819
draw arc...: 0.20374382780391898
draw spline: 0.20977123984630452
draw arc...: 0.21910632436993183
draw spline: 0.2105823233641786
draw arc...: 0.20741510967036447
draw spline: 0.2121534677917225
draw arc...: 0.20511733293733414
draw spline: 0.22709722709714697
draw arc...: 0.20720779367456998
draw spline: 0.21440843245363794
draw arc...: 0.20914547982192744
draw spline: 0.23129281024012016
draw arc...: 0.21159368527787592
draw spline: 0.21559808025995153
draw arc...: 0.21043717284283048
draw spline: 0.21559045619324024
draw arc...: 0.22413146473445522
draw spline: 0.21779791704648233
draw arc...: 0.21203852030885173
draw spline: 0.21875385785278922
draw arc...: 0.21385627400559315
draw spline: 0.23602413076150697
draw arc...: 0.21456062057586678
draw spline: 0.22065958156235865
draw arc...: 0.2161317650025012
draw spline: 0.22747315228480147
draw arc...: 0.2334524740545021
draw spline: 0.22508300703702844
draw arc...: 0.2199983402988437
draw spline: 0.22491996928147273
draw arc...: 0.23644345448883541
draw spline: 0.22830945387431711
draw arc...: 0.2221920191841491
draw spline: 0.22831033357397246
draw arc...: 0.22307259901208454
draw spline: 0.25065471681955387
draw arc...: 0.22283214764320292
draw spline: 0.2319238484651578
draw arc...: 0.22785963387468655
draw spline: 0.2454251927920268
draw arc...: 0.22593690262874588
draw spline: 0.2310500130060973
draw arc...: 0.22716672340720834
draw spline: 0.2359956871241593
draw arc...: 0.24249755076743895
draw spline: 0.2383617872328614
draw arc...: 0.23000844805392262
draw spline: 0.23735218472029374
draw arc...: 0.24702214175886184
draw spline: 0.23692640985973412
draw arc...: 0.230810441336871
draw spline: 0.2437229730476247
draw arc...: 0.23418526426212338
draw spline: 0.2549397361417505
draw arc...: 0.23403747463999025
draw spline: 0.23957430724294682
draw arc...: 0.2378386588916328
draw spline: 0.26099295272251766
draw arc...: 0.2431781454324664
draw spline: 0.2430564535825397
draw arc...: 0.24161697093950352
draw spline: 0.2621887584300566
draw arc...: 0.2396552396548941
draw spline: 0.24824375200296345
draw arc...: 0.24137593310479133
draw spline: 0.2648724302853225
draw arc...: 0.24208643757629034
draw spline: 0.24928590342096868
draw arc...: 0.24261455088526418
draw spline: 0.2711350154968386
draw arc...: 0.24534103481346392
draw spline: 0.25222175598173635
draw arc...: 0.24522491439711303
draw spline: 0.2541641338630143
draw arc...: 0.26458623451071617
draw spline: 0.2533589150134503
draw arc...: 0.2491929484422144
draw spline: 0.25444094616977964
draw arc...: 0.2662878677911067
draw spline: 0.255469608853673
draw arc...: 0.25337474961452244
draw spline: 0.2589259506567032
draw arc...: 0.27056467657894245
draw spline: 0.2612668326946732
draw arc...: 0.25393130656266294
draw spline: 0.2615239983661013
draw arc...: 0.27250441536125436
draw spline: 0.2626793378676666
draw arc...: 0.2618398107115354
draw spline: 0.27311844604992075
draw arc...: 0.27365887516316434
draw spline: 0.27043360126117477
draw arc...: 0.26074956901902624
draw spline: 0.2834352759164176
draw arc...: 0.2660526946256141
draw spline: 0.26603568708742387
draw arc...: 0.2637704592598311
draw spline: 0.2838082687703718
draw arc...: 0.2633731280348002
draw spline: 0.2671317934473336
draw arc...: 0.26515745312826766
draw spline: 0.28530933042384277
draw arc...: 0.2659617922781763
draw spline: 0.27325773190386826
draw arc...: 0.2672745981017215
draw spline: 0.29131885522838274
draw arc...: 0.26960726960714965
draw spline: 0.27626806574153306
draw arc...: 0.4639221782090317  <-- this arc closed the shape which explains the time spike here

 

And then to turn off compute differed: 0.001083204089809442

 

Or to put it into a picture (last arc spiked time not included)...Plot.png

 

 

There were 400 shapes drawn, funny thing is if you take the first draw times of a given shape type and multiply it by 400... guess what - you get something dang close to the final draw times for that shape. Clearly there is a O(n) going on here where n is the number of shapes and the constant (on my computer) is around 0.9ms

Message 10 of 20
Anonymous
in reply to: Anonymous

I managed to get my 100 tooth gear profile render time (B3 above) down to... Draw Time: 2.083119 seconds Turning off Compute Deferred: 0.454026 seconds I did this by NOT using any sketch points in my drawing calls. Which means my sketch is a bunch of separate lines but a 25x speedup isn't bad... though i'd really like to have all of the lines connected. Anyway, looks like a bug of sorts from my vantage. I can provide some repro scripts but they are too long to post here.
Message 11 of 20
asheepcalledgeorge
in reply to: Anonymous

Excellent bug hunting skills Ross!

 

And then to turn off compute differed: 0.001083204089809442

Are you saying that it is FASTER with sketch.isComputeDeferred = False than sketch.isComputeDeferred = True?

 

Is the Execute UI Context slower by a constant amount or does it vary with the amount of detail/operations in the sketch?  If it varies I guess there is a context sensitive conditional somewhere in the drawThing call.

 

Does anybody know what copy() is doing under the hood?  If I do all these operations by hand (project, select, copy, new sketch, paste) then it doesn't seem as slow as the API.  It seems silly to take the geometry and stitch it together outside Fusion before bringing it back in again, but it seems like it might be the only way to achieve any meaningful performance until this is resolved.

 

 

Message 12 of 20
Anonymous
in reply to: asheepcalledgeorge

(forgive the lack of formatting - the forum is removing it!) I'm saying that with an empty sketch i can draw 400-500 lines per seconds, but once i get 400 lines in it i'm down to 4-5 lines per second. I wrote a sketch recorder (fake sketch object that recorded sketch draw calls and generated the python code) I then made a simple script and pasted in my generated draw calls and i was surprised to see the speedup. My conclusion was that it must be the forwarding of endSketchPoints - but this morning I made the changes to my real implementation to not forward endSketchPoints and found no speedup... I've managed to attain the speedup while using endSketchPoints in my drawing calls (in my real implementation) but I'll be honest I don't yet understand why and I don't have a clear repro to cause the slowdown (I can't make my generated calls code slow down) but it appears to have something to do with either where or when computeDeferred is set. Setting this immediately after sketch creation - in the same function that created the sketch - appears to have something to do with remedying the situation. But this is dang messy - at one point I had to actually toggle areProfilesShown after clearing computeDeferred to get profiles to be computed!
Message 13 of 20
Anonymous
in reply to: Anonymous

Try setting sketch.areProfilesShown = False about when you set sketch.isComputeDeferred = True. Then set sketch.areProfilesShown = True after setting sketch.isComputeDeferred = False. This did the trick for me - i'm curious if it will help you as well... or in the case of your project just leave areProfilesShown off
Message 14 of 20
ekinsb
in reply to: Anonymous

Regarding the original problem, we found and have fixed it and the fix will be available in the update currently scheduled for the end of October.  The problem is that it wasn't picking up and copying the sketch points that the sketch geometry is dependent on.  I think it was primarily an issue with arcs but there could have been issues with other geometry too.  A temporary workaround is to also add the points to the collection of objects you want to copy but in the fix we automatically do this.  This change only applies when copying sketch entities.  When moving it will the your responsibility to get the points and in fact you could only move the points and the curve geometry would just go along for the ride.

 

Regarding the possible performance issues you've found it looks like there might be a combination of API and Fusion core issues that need to be investigated.  Simple test cases are always very beneficial to be able to see and verify the problem and then to also have a metric to test any changes against.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 15 of 20
Anonymous
in reply to: ekinsb

I'm still working on a repro. I'm not at home right now (which is where my code for this is) but I wonder if the isConstruction poor performance issue is related. 

 

I've found a possible workaround - i'll try it on the isConstruction code tonight when i get home but here's my workaround.

sketch.areProfilesShown = False
sketch.computeDeferred = True

... draw stuff

sketch.computeDeferred = False
sketch.areProfilesShown = True
Message 16 of 20
Salient1492
in reply to: Anonymous

I am seeing this strange move behavior too...

 

1. Cannot Free drag a move????.

2. No 'Move' option allowed in the object mouse-click flyout menu?

3. The move actually 'COPIED' the selection? [I would have used the COPY command}

 

Tags (3)
Message 17 of 20
asheepcalledgeorge
in reply to: ekinsb

"Regarding the original problem, we found and have fixed it and the fix will be available in the update currently scheduled for the end of October.  The problem is that it wasn't picking up and copying the sketch points that the sketch geometry is dependent on.  I think it was primarily an issue with arcs but there could have been issues with other geometry too."

 

Ah, that's fantastic news!  I'll aim to release once the update is out.

 

"Regarding the possible performance issues you've found it looks like there might be a combination of API and Fusion core issues that need to be investigated.  Simple test cases are always very beneficial to be able to see and verify the problem and then to also have a metric to test any changes against."

 

Indeed, it looks that way.  

 

Since there has been a lot put in this thread, as I see it there are four problems:

  1. When executing multiple sequential project / copy operations from on OnExecute context, the progress bar is non-sensical and cannot be disabled / swapped for a better indicator.  It might even be partly responsible for the slow down. For instance, running my test script in an OnExecute script can be slower for multiple faces (i.e. 10 with lots of lines) than it would be to do by hand.

  2. The OnExecute context is significantly slower than OnPreview and No UI (see Ross' Post where: OnExecute = 5.3s, OnPreview = 3.9s, and NoUI = 3.6s).

  3. Drawing a new entity in a sketch (even non-intersecting draws) is an O(N) operation, where N appears to be factor of the number of entities in the sketch. 

  4. Changing isComputeDeffered impacts this but I'm unclear how (see Ross' post containing the graph).  Ross said he is working on a repo that deals with sketch.areProfilesShow, sketch.isComputeDeffered and can also achieve some speedups by not connecting the lines.
  5. Lack of a clear best-practice guide to help API users draw/project/copy large numbers of entities into a sketch without causing significant speed problems.  

 

Are these being treated like bugs? If not, are there some specific test scripts we can help with?  I would rather co-ordinate our approach rather than guessing what scripts to write without knowing which are already written, etc 🙂 

 

What is the best way to write a script that executes actions from a number of different contexts (OnExecute, OnPreview, No UI)?

 

Cheers!

Message 18 of 20

hello!

 

It looks like the recent updates have not addressed the initial bug.  Is it still planned to be pushed?

Message 19 of 20
ekinsb
in reply to: asheepcalledgeorge

The fix is included in the next big Fusion 360 update, which was delayed, but is currently scheduled for early December.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 20 of 20
asheepcalledgeorge
in reply to: ekinsb

Ah cool, thanks for the update!

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

Post to forums