Ok, not just splines! I turned my spline blob into a line blob and the same bad behavior happened (but not as bad). I suspect your initial attempt failed to reproduce the problem because lines which lie on an axis require special code paths - not to mention the obvious optimizations which are possible. I'm willing to bet that if you rotated your drawing (or drew all lines at some minor angle) it would also see some slowdown.
import adsk.core, adsk.fusion, traceback
import time, random
def linesTest(ui, sk):
def drawLine(sk, lines, point1, point2, isConst):
newLine = adsk.fusion.SketchLine.cast(lines.addByTwoPoints(point1, point2))
if isConst:
newLine.isConstruction = True
return newLine
lines = sk.sketchCurves.sketchLines
sk.isComputeDeferred = True
lastLine = lines.addByTwoPoints(adsk.core.Point3D.create(-1,1,0), adsk.core.Point3D.create(30,1,0))
lastLine = lines.addByTwoPoints(lastLine.endSketchPoint, adsk.core.Point3D.create(30,9,0))
lastLine = lines.addByTwoPoints(lastLine.endSketchPoint, adsk.core.Point3D.create(-1,9,0))
lastLine = lines.addByTwoPoints(lastLine.endSketchPoint, adsk.core.Point3D.create(-1,1,0))
t0 = time.time()
lastLine = drawLine(sk, lines, adsk.core.Point3D.create(0,0,0), adsk.core.Point3D.create(0,10,0), True)
x = 0.25
y = 0
for step in range(100):
if step % 2 == 0:
lastLine = drawLine(sk, lines, lastLine.endSketchPoint, adsk.core.Point3D.create(x,y,0), True)
else:
lastLine = drawLine(sk, lines, lastLine.endSketchPoint, adsk.core.Point3D.create(x,y,0), False)
x += .25
if y == 0:
y = 10
else:
y = 0
t1 = time.time()
total = t1-t0
sk.isComputeDeferred = False
ui.messageBox('Total time: ' + str(total))
def makeSplineBlob(sk, seed=None):
w = 40
h = 12
oc = adsk.core.ObjectCollection.create()
random.seed(seed)
for i in range(0, 12):
p = adsk.core.Point3D.create(random.uniform(0, w), random.uniform(0, h), 0)
oc.add(p)
oc.add(oc.item(0))
sk.sketchCurves.sketchFittedSplines.add(oc)
def makeLineBlob(sk, seed=None):
lines = sk.sketchCurves.sketchLines
w = 40
h = 12
random.seed(seed)
p0 = adsk.core.Point3D.create(random.uniform(0, w), random.uniform(0, h), 0)
pp = p0
for i in range(0, 11):
p = adsk.core.Point3D.create(random.uniform(0, w), random.uniform(0, h), 0)
lines.addByTwoPoints(p, pp)
pp = p
lines.addByTwoPoints(p, p0)
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
des = adsk.fusion.Design.cast(app.activeProduct)
root = des.rootComponent
sk = root.sketches.add(root.xYConstructionPlane)
#makeSplineBlob(sk, 98767493)
makeLineBlob(sk, 98767493)
linesTest(ui, sk)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Baseline: Refactored (but otherwise unmodified) script on my computer (multiple runs)
# 1.1380650997161865
# 1.1350648403167725
# 1.1320645809173584
# modification 1 commenting out the IF isCons and setting of construction
# #if isConst:
# #newLine.isConstruction = True
# 0.08600497245788574
# 0.08500480651855469
# 0.08400487899780273
# always setting construction to false, still behind IF
# if isConst:
# newLine.isConstruction = False
# 0.11200642585754395
# 0.11800670623779297
# always setting constructin to isCons
# newLine.isConstruction = isConst
# 1.1240642070770264
# 1.1260643005371094
# with spline blob (seed 98767493) AND NOT setting construction to any value
# #if isConst:
# #newLine.isConstruction = True
# 0.08200478553771973
# 0.08300471305847168
# with spline blob (seed 98767493) AND ALWAYS setting construction = False
# newLine.isConstruction = False
# 0.08400487899780273
# 0.08500504493713379
# with spline blob (seed 98767493) AND ALWAYS setting construction = True
# newLine.isConstruction = True
# 12.036688566207886
# 12.079690933227539
# with spline blob (seed 98767493) AND setting constuction behind IF check
# if isConst:
# newLine.isConstruction = True
# 22.79530358314514
# 22.137266159057617
# with line blob (seed 98767493) AND setting constuction behind IF check
# if isConst:
# newLine.isConstruction = True
# 6.4013659954071045
# 6.428367614746094
# with line blob (seed 98767493) AND NOT setting construction to any value
# #if isConst:
# #newLine.isConstruction = True
# 0.0870048999786377
# 0.08600473403930664