TAGGED: macros-scripting, python, spaceclaim
-
-
May 14, 2024 at 11:11 pmDavid HillsSubscriber
Hello, 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 amAtharv JoshiForum Moderator
Hi David,
Let me check and get back to you.Â
Thanks and Regards
Atharv -
May 16, 2024 at 4:11 pmDavid HillsSubscriber
Hi 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 pmDavid HillsSubscriber
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)
-
- The topic ‘Select all objects in Layer’ is closed to new replies.
- Unable to attach geometry 2024 R2
- Getting Mesh Faces With Specified Normal Via SpaceClaim Scripting (V241)
- How to provide blade angles in bladegen.
- DXF file loaded incorrectly
- plugin error failed to import assembly from spaceclaim
- Overlapping contact face
- Thermoelectric Cooler Model
- Issue Seeing Explore
- Warning Plugin Error Geometry in Design Modeler
- SpaceClaim stops sharing topology
-
1406
-
599
-
591
-
550
-
366
© 2025 Copyright ANSYS, Inc. All rights reserved.