If i have 2 named selections created through scripting, i need to create a beam between one face of first named selection and one face of the second named selection when the faces are below/above each other representing a bolted connection.
You can use the blow code where each face in the 2 named selection will be compared on the centroidal location and the beam will be created only when the z-coordinate is same.
NS1 = ExtAPI.DataModel.GetObjectsByName("Selection")[0] NS2 = ExtAPI.DataModel.GetObjectsByName("Selection 2")[0] geo = ExtAPI.DataModel.GeoData face_ids2 = list(NS2.Location.Ids) centroids2 = {} for fid in face_ids2: geoEnt = geo.GeoEntityById(fid) if geoEnt.Type == GeoCellTypeEnum.GeoFace: centroids2[fid] = geoEnt.Centroid tol = 1e-6 # Loop over all faces in NS1 for fid1 in NS1.Location.Ids: geoEnt1 = geo.GeoEntityById(fid1) cent1 = geoEnt1.Centroid z1 = cent1[2] # For each face in NS2, compare z for fid2, cent2 in centroids2.items(): z2 = cent2[2] if abs(z1 - z2) < tol: beam = ExtAPI.DataModel.Project.Model.Connections.AddBeam() sel_ref = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) sel_ref.Ids = [fid1] beam.ReferenceLocation = sel_ref sel_mob = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) sel_mob.Ids = [fid2] beam.MobileLocation = sel_mob beam.Radius = Quantity(2, "mm") break