Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
Hi All,
I have a sketch with many individual profiles in it and I would to loft some of them together. Can anybody answer the following questions?
1> Are profiles stored with indexes corresponding to the order in which they are drawn? e.g. the first profile drawn is always index zero and the last profile drawn always index -1?
2> Is there any way, given either a point or a line, to determine the profiles it is a part of?
Thanks.
Solved! Go to Solution.
Solved by kandennti. Go to Solution.
Solved by BrianEkins. Go to Solution.
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
Hi @a.g.ashwood -San.
@a.g.ashwood さんは書きました:2> Is there any way, given either a point or a line, to determine the profiles it is a part of?
I tried only sketch points because it seemed like a fun theme.
The following sample finds a profile that contains a point in the same sketch as the selected sketch point and ends up in the selected state.
The search method creates a temporary surface body to determine.
# Fusion360API Python script
import traceback
import adsk.core as core
import adsk.fusion as fusion
def run(context):
ui: core.UserInterface = None
try:
app: core.Application = core.Application.get()
ui = app.userInterface
msg: str = 'Select Sketch Point'
selFilter: str = 'SketchPoints'
sel: core.Selection = select_ent(msg, selFilter)
if not sel:
return
profLst = find_profiles_containing_point(sel.entity)
sels: core.Selections = ui.activeSelections
sels.clear()
[sels.add(prof) for prof in profLst]
ui.messageBox("Done")
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def find_profiles_containing_point(
pnt: fusion.SketchPoint,
) -> list[fusion.Profile]:
skt: fusion.Sketch = pnt.parentSketch
print(skt.profiles.count)
if skt.profiles.count < 1:
return []
targetProfLst = []
prof: fusion.Profile = None
for prof in skt.profiles:
loops = list(prof.profileLoops)
outer = [l for l in loops if l.isOuter]
inner = [l for l in loops if not l.isOuter]
if not all([is_containment(l, pnt) for l in outer]):
continue
if any([is_containment(l, pnt) for l in inner]):
continue
targetProfLst.append(prof)
return targetProfLst
def is_containment(
loop: fusion.ProfileLoop,
pnt: fusion.SketchPoint,
) -> bool:
crvs = [c.geometry for c in loop.profileCurves]
tmpMgr: fusion.TemporaryBRepManager = fusion.TemporaryBRepManager.get()
wireBody, _ = tmpMgr.createWireFromCurves(
crvs,
)
faceBody: fusion.BRepBody = tmpMgr.createFaceFromPlanarWires([wireBody])
if faceBody.pointContainment(pnt.geometry) == fusion.PointContainment.PointOnPointContainment:
return True
else:
return False
def select_ent(
msg: str,
filter: str
) -> core.Selection:
try:
app: core.Application = core.Application.get()
ui: core.UserInterface = app.userInterface
sel = ui.selectEntity(msg, filter)
return sel
except:
return None
Can't find what you're looking for? Ask the community or share your knowledge.