TAGGED: macros-scripting, python, spaceclaim
-
-
May 14, 2024 at 11:11 pm
David Hills
SubscriberHello, I'd like to enumerate through all layers, select all objects on a layer, then perform a custom function on the selected objects. I'm not able to identify if the objects i have selected are part of the active layer. i would expect it to work similar to this:
def selectObjinLayer():  doc = Window.ActiveWindow.Document  for layer in Layers.GetAllLayers():    #print(layer.GetName())    Layers.Activate(layer.GetName())    selection = Selection.Clear()    selection = Selection.Create(Layers.GetActive())    secondarySelection = Selection.Empty()    Â    #this is the point where the script fails    # the GetAllBodies returns empty, so no iteration occurs    for design_body in doc.MainPart.GetAllBodies():      print("check if ", design_body," is in layer ", layer)#this is a nonsense getter and comparison:      if design_body.Layer == layer:        selection.AddToActive()    return selectionÂselectedOBJS = selectObjinLayer()customFunction(selectedOBJS)Âthe customFunction fills all objects, then renames the associated Surfaces based on the layer name. -
May 16, 2024 at 5:06 am
Atharv Joshi
Forum ModeratorHi David,
Let me check and get back to you.Â
Thanks and Regards
Atharv -
May 16, 2024 at 4:11 pm
David Hills
SubscriberHi Atharv,
Thanks for investigating this, I'm excited to see what you come up with. Â
Perhaps this is helpful: when right-clicking on a layer, the "select all objects" function does exactly what I need, but the macro recorder cannot record its action.
BEst,
DaveÂ
-
May 16, 2024 at 9:46 pm
David Hills
SubscriberAn 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)
-
- The topic ‘Select all objects in Layer’ is closed to new replies.
- Unable to attach geometry 2024 R2
- Data Center Simulation
- DXF file loaded incorrectly
- plugin error failed to import assembly from spaceclaim
- Inventor 2025 files
- Ansys SpaceClaim and Discovery 2024 Facet shelling bug – 2022 version is better
- solidwork parameters for optimization in ansys
- Masonry Brick Simulation
- Spaceclaim 2024 error FNE activation failed
- Simulating PCB
-
1932
-
823
-
599
-
591
-
366
© 2025 Copyright ANSYS, Inc. All rights reserved.