Goal: Given a motor model with a named selection of faces and two named selections of vertices, all of the same size, for each of the three lists, add a coordinate system at the center of the face with its +Y axis pointed out of the face. The -X direction will be from the vertex in the second list to the vertex in the third list.
Note: The following script example is model-specific. Click to download the archived Ansys projecthere.
Code:
# Get all faces and vertices of named selections face_named_selection = Model.NamedSelections.Children[0] # First named selection, of faces face_ids = face_named_selection.Ids start_vertex_named_selection = Model.NamedSelections.Children[1] # Second named selection, of vertices start_vertex_ids = start_vertex_named_selection.Ids end_vertex_named_selection = Model.NamedSelections.Children[2] # Third named selection, of vertices end_vertex_ids = end_vertex_named_selection.Ids # Create axis systems selection_info = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) with Transaction(): # Suppress tree update for performance for iFaceCount in range(0, face_ids.Length): coordinate_system = Model.CoordinateSystems.AddCoordinateSystem() selection_info.Ids.Clear() selection_info.Ids.Add(face_ids[iFaceCount]) # Create a temporary selection # Define origin in face center coordinate_system.OriginLocation = selection_info # Define primary axis (Y) normal into face coordinate_system.PrimaryAxis = CoordinateSystemAxisType.PositiveYAxis coordinate_system.PrimaryAxisDefineBy = CoordinateSystemAlignmentType.Associative # Geometry selection coordinate_system.PrimaryAxisLocation = selection_info # Define orientation around principle axis from start- to endvertex selection_info.Ids.Clear() selection_info.Ids.Add(end_vertex_ids[iFaceCount]) # Create a temporary selection selection_info.Ids.Add(start_vertex_ids[iFaceCount]) # Create a temporary selection coordinate_system.SecondaryAxis = CoordinateSystemAxisType.PositiveXAxis coordinate_system.SecondaryAxisDefineBy = CoordinateSystemAlignmentType.Associative # Geometry selection coordinate_system.SecondaryAxisLocation = selection_info