David Hills
Subscriber

An Ansys engineer has helped me to close this issue. The resulting code is:

 

def fillSelected(layer_curves):
    #fill the curves in the layer. this creates a new surf body
    selection = Selection.Create(layer_curves)
    secondarySelection = Selection.Empty()
    options = FillOptions()
    result = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD)

allCurves = GetRootPart().GetDescendants[IDesignCurve]()
for layer in Layers.GetAllLayers():
    layer_curves=[i for i in allCurves if i.Layer==layer]
    if not len(layer_curves)==0:
        Layers.Activate(layer.GetName())
        fillSelected(layer_curves)