How can I create a selection of all edges parallel to the x-axis using Scripting?

Ryoma
Ryoma Member, Employee Posts: 7
Second Anniversary First Answer Ansys Employee First Comment
✭✭✭

How can I create a selection of all edges parallel to the x-axis using Scripting ?

Best Answer

  • Ryoma
    Ryoma Member, Employee Posts: 7
    Second Anniversary First Answer Ansys Employee First Comment
    ✭✭✭
    Answer ✓

    You can do that by using scripts below.
    This code traverses all edges in the model and select the edge parallel to the x-axis.

    geometry = ExtAPI.DataModel.GeoData
    assemblies = geometry.Assemblies
    assemblies_count = assemblies.Count
    
    #selection info 
    selmgr=ExtAPI.SelectionManager
    selmgr.ClearSelection()
    selection_info = selmgr.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
    
    target_direction = [1, 0, 0] #Parallel to X-Axis
    neg_target_direction =[ -1*i for i in target_direction]
    
    # Select Edges parallel to Z-Axis
    with Transaction():
        for assembly in assemblies:
            assembly_name = assembly.Name
            parts = assembly.Parts
            parts_count = parts.Count
            for part in parts:
                part_name = part.Name
                bodies = part.Bodies
                bodies_count = bodies.Count
                for body in bodies:
                    faces = body.Faces
                    faces_count = faces.Count
                    for face in faces:
                        edges = face.Edges
                        edges_count = edges.Count
                        for edge in edges:
                            direction = list(edge.TangentAtParam(0))
    
                            if direction== target_direction:
                                selection_info.Ids.Add(edge.Id)
                            elif direction== neg_target_direction:
                                selection_info.Ids.Add(edge.Id)
    
    
    selmgr.NewSelection(selection_info)