this works good for me:
def FlatMillFaces(tool: int, machine, faces, sheet: adsk.cam.Setup):
if len(faces) > 0:
edgelist = []
for items in faces:
items: adsk.fusion.BRepFace
for loop in items.loops:
if loop.isOuter:
for e in loop.edges:
edgelist.append(e)
tool = Utility.ToolGetter(machine, tool)
sheets = sheet.parentSetup
flatInput: adsk.cam.OperationInput = sheets.operations.createInput("flat")
flatInput.tool = tool
preset = tool.presets.itemsByName("Default preset")
flatInput.toolPreset = preset[0]
flatInput.displayName = f'PocketMill {tool.parameters.itemByName("tool_description").value.value}'
#flatInput.parameters.itemByName("tool_coolant").value.value = "disabled"
flatInput.parameters.itemByName("useRestMachining").value.value = False
flatInput.parameters.itemByName("restMaterialSource").value.value = "job"
flatInput.parameters.itemByName("topHeight_mode").value.value = "from stock top"
flatInput.parameters.itemByName("topHeight_offset").expression = "0 in"
#flatInput.parameters.itemByName("topHeight_checkStockTop").value.value = True
flatOp: adsk.cam.Operation = sheets.operations.add(flatInput)
flatOp.parameters.itemByName("boundaryMode").value.value = "none"
flatOp.parameters.itemByName("direction").value.value = "both ways"
flatOp.parameters.itemByName("transitionType").value.value = "curve"
surfaceGroupsParam: adsk.cam.CadMachineAvoidGroupsParameterValue = flatOp.parameters.itemByName('checkSurfaceSelectionSets').value
machineAvoidGroups = surfaceGroupsParam.getMachineAvoidGroups()
ModelGroup = machineAvoidGroups.defaultGroup(1)
ModelGroup.machineMode = adsk.cam.MachiningMode.Avoid_MachiningMode
machineAvoidGroup: adsk.cam.MachineAvoidDirectSelection = machineAvoidGroups.createNewMachineAvoidDirectSelectionGroup()
machineAvoidGroup.machineMode = adsk.cam.MachiningMode.Machine_MachiningMode
machineAvoidGroup.inputGeometry = faces
surfaceGroupsParam.applyMachineAvoidGroups(machineAvoidGroups)