You should never expect the indices of the profiles to indicate anything and assume they are random. Profiles aren't explicitly created but are calculated by Fusion as you create sketch geometry.
To find specific profiles, you need to use other clues like their topology, geometry, or position in space.
A sketch entity, like a line or circle, doesn't know what profiles it was used for. However, each profile knows which entities are used for its definition, and you can use that information. Remember that geometry can be used to define multiple profiles. Below is a simple example where two circles were created and three profiles were calculated.
All profiles consist of one outer loop and can have multiple interior loops to define voids. In this example, all of the three profiles only have the one outer loop. If I want to find the blue profile, I can get the area properties of each profile and use the one with the smallest area. If I want the orange profile, I can also use the area properties but use the one whose centroid is the furthest in the X direction (assuming positive X is to the right in the picture above).
Here's some example code that demonstrates finding the profiles associated with a selected sketch entity.
def run(context):
ui: adsk.core.UserInterface = None
try:
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
root: adsk.fusion.Component = des.rootComponent
skEnt: adsk.fusion.SketchEntity = ui.selectEntity('Select a sketch curve', 'SketchCurves').entity
foundProfs = FindRelatedProfiles(skEnt)
cnt = 0
for prof in foundProfs:
ui.activeSelections.clear()
ui.activeSelections.add(prof)
cnt += 1
ui.messageBox(f'Profile {cnt} of {len(foundProfs)} is highlighted.')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def FindRelatedProfiles(skCurve: adsk.fusion.SketchCurve) -> list[adsk.fusion.Profile]:
sk = skCurve.parentSketch
foundProfs = []
for prof in sk.profiles:
for loop in prof.profileLoops:
for curve in loop.profileCurves:
if curve.sketchEntity == skCurve:
# This curve is part of the profile but make
# sure it's not already in the list. This can
# happen if the profile uses seperate sections
# of the curve.
found = False
for foundProf in foundProfs:
if foundProf == prof:
found = True
break
if not found:
# Add this profile to the list.
foundProfs.append(prof)
return foundProfs
---------------------------------------------------------------
Brian EkinsInventor and Fusion 360 API Expert
Website/Blog:
https://EkinsSolutions.com