Sketch profiles added in random order

Sketch profiles added in random order

hpekristiansen
Advocate Advocate
693 Views
2 Replies
Message 1 of 3

Sketch profiles added in random order

hpekristiansen
Advocate
Advocate

 

The oct 2019 update includes a fix for missing profiles:

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/profiles-disappear-from-3d-sketch/m-p/9087...

 

##################

Now I think there is a new error: The sketch profiles is added in seemingly random order. 

##################

 

To illustrate the problem, I draw two spheres by revolving profiles.

 

import adsk.core, adsk.fusion, math

app = adsk.core.Application.get()
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
root = app.activeProduct.rootComponent

sketch = root.sketches.add(root.xYConstructionPlane)
arcs = sketch.sketchCurves.sketchArcs
lines = sketch.sketchCurves.sketchLines
revolves = root.features.revolveFeatures

#First sphere 
arc = arcs.addByCenterStartSweep(adsk.core.Point3D.create(10, 4, 2), adsk.core.Point3D.create(9, 4, 2), math.pi)
axisLine = lines.addByTwoPoints(adsk.core.Point3D.create(9, 4, 2), adsk.core.Point3D.create(11, 4, 2))
print(sketch.profiles.count)
profile = sketch.profiles.item(0)
revInput = revolves.createInput(profile, axisLine, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
revInput.setAngleExtent(False, adsk.core.ValueInput.createByReal(2*math.pi))
revolves.add(revInput)

#Second sphere
arc = arcs.addByCenterStartSweep(adsk.core.Point3D.create(0, 2, 1), adsk.core.Point3D.create(-2, 2, 1), math.pi)
axisLine = lines.addByTwoPoints(adsk.core.Point3D.create(-2, 2, 1), adsk.core.Point3D.create(2, 2, 1))
print(sketch.profiles.count)
profile = sketch.profiles.item(0)  #This is wrong!!
revInput = revolves.createInput(profile, axisLine, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
revInput.setAngleExtent(False, adsk.core.ValueInput.createByReal(2*math.pi))
revolves.add(revInput)

Notice, that the second sphere also uses

sketch.profiles.item(0)

This is should be

sketch.profiles.item(1)

as there has just been added a profile.

I have tried with 100 randomly generated profiles(spheres), and I can not see any pattern in when the profile is added to the beginning or end of sketch.profiles !

 

##################

Output(correct) of the above(wrong) code:

ScreenShot2019-10-31T174548@1X.png

If the code is corrected, the output is wrong:

ScreenShot2019-10-31T174802@1X.png

 

0 Likes
694 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor

I don't know the specific internals of how profiles are being calculated, but I don't think you should expect any kind of order or consistency in the order when they're returned.  The only thing you should expect is that a list of the current profiles that can be calculated from the sketch and nothing more.  If you need to know which profile goes with specific sketch geometry, you'll need to do the work to find the match.

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

hpekristiansen
Advocate
Advocate

I am very surprised.

 

Before the bug correction, I could generate 100 different spheres by using only

 

profile = sketch.profiles.item(0)

for all of them as all new profiles outside of the sketch plane was overwriting the first profiles item.

 

 

Now new profiles are added randomly to the start or end of profiles. -the situation is worse than ever.

 

#################

The "Extrude Feature API Sample API Sample" :

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-CB1A2357-C8CD-474D-921E-992CA3621D04

uses

sketch.profiles.item(0)   and
sketch.profiles.item(1)

for extrusion, so it among many other scripts is depended on the order of profiles. The only reason this example does not fail is because the profiles are on the sketch plane or by pure luck!?

0 Likes