Hi,
The first loop is to visit all the profiles on the sketch. The second loop is to visit all the profile loops of one profile. The third loop is to visit all the profile curves of one profile loop. The intention is to check if the input sketch curve is contained in the profiles curves of the profile, if yes, select the profile.
I add a new function ‘isInsideCircle’ in the script to check if the profile is inside the circle. That would be better to match your requirements.
#Author-
#Description-
import adsk.core, adsk.fusion, adsk.cam, traceback
near_zero = 0.000001
ui = None
#If all points in the profile are inside the circle, then the profile is inside the circle.
def isInsideCircle(profile, sketchCircle):
# Get center and radius from sketch circle
circle = sketchCircle.geometry
center = circle.center
radius = circle.radius
loops = profile.profileLoops
for loop in loops:
profileCurves = loop.profileCurves
for profileCurve in profileCurves:
#Get the start point and end point
curve = profileCurve.geometry
eva = curve.evaluator
(retVal, startPoint, endPoint) = eva.getEndPoints()
#Check if the points are outside the circle
if startPoint.distanceTo(center) - radius > near_zero:
return False
if endPoint.distanceTo(center) - radius > near_zero:
return False
return True
def findProfiles(containedCurve):
sketchCurve = adsk.fusion.SketchCurve.cast(containedCurve)
sketch = sketchCurve.parentSketch
profiles = sketch.profiles
for profile in profiles:
found = False
loops = profile.profileLoops
for loop in loops:
if found:
break
profileCurves = loop.profileCurves
for profileCurve in profileCurves:
if profileCurve.sketchEntity == containedCurve:
# Check if the profile is inside the circle
sketchCircle = adsk.fusion.SketchCircle.cast(containedCurve)
if sketchCircle:
if isInsideCircle(profile, sketchCircle):
ui.activeSelections.add(profile)
else:
ui.activeSelections.add(profile)
found = True
break;
def run(context):
try:
app = adsk.core.Application.get()
global ui
ui = app.userInterface
curve = ui.selectEntity('Select a sketch curve', 'SketchCurves').entity
ui.activeSelections.clear()
findProfiles(curve)
ui.messageBox(str(ui.activeSelections.count))
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
About your another question, the triangle is a profile. You can add the filter to select profiles.
ui.selectEntity('Select a sketch curve', 'SketchCurves,Profiles')
Thanks,
Jack