If you have a complex sketch it can sometimes be difficult to find the specific profiles you need but I believe it should always be possible. A couple of points to remember. First, you don't explicitly create profiles. You draw sketch entities and Fusion automatically determines the possible profiles. Second, sketch entities can end up participating in many profiles. In the example below I've drawn three overlapping circles. This results in 7 profiles (each shown in a different color) and each circle participates in defining all 7 of the profiles. This is probably one of the worst cases you could run into.
Another thing that can cause problems because it increases the complexity, is that when you create a new sketch using a face as input, the edges of the face are automatically included into the sketch it is also considered when the profiles are calculated. We'll be adding a new method soon to create a sketch on a face that will create the sketch without including the edges. A couple of approaches you can use now is to delete all of the automatically created entities right after the sketch is created or change them all to construction so they won't participate in profile calculations.
Using the picture above as an example, and assuming you want to use the blue profile, you need to somehow figure out what makes the blue profile unique. Assuming you created the three sketch circles in the same script so you should have references to those, you can use that information to help find the blue profile. What I see that makes the blue profile unique is that it's the only profile that is inside circle 1 and 2 and outside circle 3. Below is my code that creates the three circles, finds the profile, and creates an extrusion.
import adsk.core, adsk.fusion, adsk.cam, traceback
_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)
def run(context):
try:
global _app, _ui
_app = adsk.core.Application.get()
_ui = _app.userInterface
des = adsk.fusion.Design.cast(_app.activeProduct)
root = des.rootComponent
sk = root.sketches.add(root.xYConstructionPlane)
circs = sk.sketchCurves.sketchCircles
circ1 = circs.addByCenterRadius(adsk.core.Point3D.create(-5,-5,0), 7)
circ2 = circs.addByCenterRadius(adsk.core.Point3D.create(5,-5,0), 7)
circ3 = circs.addByCenterRadius(adsk.core.Point3D.create(0,4,0), 7)
prof = adsk.fusion.Profile.cast(None)
for prof in sk.profiles:
# Get the centroid of the current profile.
profCenter = adsk.core.Point3D.cast(prof.areaProperties().centroid)
# Check to see if the center is within circle 1.
if profCenter.distanceTo(circ1.centerSketchPoint.geometry) < circ1.radius:
# Check to see if the center is within circle 2.
if profCenter.distanceTo(circ2.centerSketchPoint.geometry) < circ2.radius:
# Check to see if the center is outside circle 3.
if profCenter.distanceTo(circ3.centerSketchPoint.geometry) > circ3.radius:
break
# Create an extrusion with the found profile.
root.features.extrudeFeatures.addSimple(prof, adsk.core.ValueInput.createByReal(5), adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
except:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
The problem with this code and somewhat the main point of my reply, is that this isn't likely to be useful to you or most anyone else. The reason being that every set of sketch geometry is a little different and the approach you might take to figure out which profile(s) you want to use will be different in each case.
Another thing to be aware of is what's available with a profile. In the example above I take advantage of the fact that you can get area properties from a profile but you can also get the sketch curves that are used to define the profile. That's actually more useful in most cases but in my example above since every circle participates in every profile it's not useful. A profile is made up of one or more loops. If it has more than one loop then there is one outer loop and one or more inner loops. For example, in the sketch pictured below there are two profiles, the one highlighted in blue and the one in the triangle. The blue one is made up of two loops; the outer rectangle and the inner triangle. There could also be additional inner loops but a profile always has only one outer loop. If I want the blue profile I can check to see which of the two profiles has two loops. In other cases it can be useful to check which which sketch entities are used to define a profile. Each loop provides the profile curves that make up that loop and each profile curve can tell you which sketch entity it's based on. One way to think of getting profiles is that it's like solving a puzzle. You're given a certain set of tools and you need to figure out how to use those tools to get to the specific solution you want.