Example of creating mesh named selection based on mesh quality criteria
Pernelle Marone-Hitz
Member, Moderator, Employee Posts: 871
✭✭✭✭
Answers
-
The following function can be adapted:
def CreateElementQualityNSworksheet(nsName, criterion, operator, value1, value2): ''' Create a worksheet named selection of element quality ''' NbElementsInSelection = 0 try: model = ExtAPI.DataModel.Project.Model newNS = model.AddNamedSelection() newNS.Name = nsName newNS.ScopingMethod = GeometryDefineByType.Worksheet objId = newNS.ObjectId DataModel.GetObjectById(objId).GenerationCriteria.Add(None) DataModel.GetObjectById(objId).GenerationCriteria[0].Active = True DataModel.GetObjectById( objId).GenerationCriteria[0].EntityType = SelectionType.MeshElement if criterion == "Skewness": DataModel.GetObjectById(objId).GenerationCriteria[ 0].Criterion = SelectionCriterionType.Skewness elif criterion == "Warping": DataModel.GetObjectById(objId).GenerationCriteria[ 0].Criterion = SelectionCriterionType.WarpingFactor elif criterion == "AspectRatio": DataModel.GetObjectById(objId).GenerationCriteria[ 0].Criterion = SelectionCriterionType.AspectRatio elif criterion == "MaxCornerAngleTri": DataModel.GetObjectById(objId).GenerationCriteria[ 0].Criterion = SelectionCriterionType.Type DataModel.GetObjectById(objId).GenerationCriteria[ 0].Operator = SelectionOperatorType.Equal DataModel.GetObjectById( objId).GenerationCriteria[0].Value = MeshElementShape.Tri3 DataModel.GetObjectById(objId).GenerationCriteria.Add(None) DataModel.GetObjectById(objId).GenerationCriteria[ 1].Criterion = SelectionCriterionType.Type DataModel.GetObjectById(objId).GenerationCriteria[ 1].Operator = SelectionOperatorType.Equal DataModel.GetObjectById( objId).GenerationCriteria[1].Value = MeshElementShape.Tri6 DataModel.GetObjectById(objId).GenerationCriteria.Add(None) DataModel.GetObjectById(objId).GenerationCriteria[ 2].Action = SelectionActionType.Remove DataModel.GetObjectById(objId).GenerationCriteria[ 2].Criterion = SelectionCriterionType.MaximumCornerAngle DataModel.GetObjectById(objId).GenerationCriteria[ 2].Operator = SelectionOperatorType.RangeInclude LowerBound = str(value1) + "[deg]" UpperBound = str(value2) + "[deg]" DataModel.GetObjectById( objId).GenerationCriteria[2].LowerBound = Quantity(LowerBound) DataModel.GetObjectById( objId).GenerationCriteria[2].UpperBound = Quantity(UpperBound) elif criterion == "MaxCornerAngleQuad": DataModel.GetObjectById(objId).GenerationCriteria[ 0].Criterion = SelectionCriterionType.Type DataModel.GetObjectById(objId).GenerationCriteria[ 0].Operator = SelectionOperatorType.Equal DataModel.GetObjectById( objId).GenerationCriteria[0].Value = MeshElementShape.Quad4 DataModel.GetObjectById(objId).GenerationCriteria.Add(None) DataModel.GetObjectById(objId).GenerationCriteria[ 1].Criterion = SelectionCriterionType.Type DataModel.GetObjectById(objId).GenerationCriteria[ 1].Operator = SelectionOperatorType.Equal DataModel.GetObjectById( objId).GenerationCriteria[1].Value = MeshElementShape.Quad8 DataModel.GetObjectById(objId).GenerationCriteria.Add(None) DataModel.GetObjectById(objId).GenerationCriteria[ 2].Action = SelectionActionType.Remove DataModel.GetObjectById(objId).GenerationCriteria[ 2].Criterion = SelectionCriterionType.MaximumCornerAngle DataModel.GetObjectById(objId).GenerationCriteria[ 2].Operator = SelectionOperatorType.RangeInclude LowerBound = str(value1) + "[deg]" UpperBound = str(value2) + "[deg]" DataModel.GetObjectById( objId).GenerationCriteria[2].LowerBound = Quantity(LowerBound) DataModel.GetObjectById( objId).GenerationCriteria[2].UpperBound = Quantity(UpperBound) elif criterion == "Jacobian": DataModel.GetObjectById(objId).GenerationCriteria[ 0].Criterion = SelectionCriterionType.JacobianRatioGaussPoints else: pass if operator == "Range": DataModel.GetObjectById(objId).GenerationCriteria[ 0].Operator = SelectionOperatorType.RangeInclude DataModel.GetObjectById( objId).GenerationCriteria[0].LowerBound = value1 DataModel.GetObjectById( objId).GenerationCriteria[0].UpperBound = value2 elif operator == "LessThanOrEqual": DataModel.GetObjectById(objId).GenerationCriteria[ 0].Operator = SelectionOperatorType.LessThanOrEqual DataModel.GetObjectById(objId).GenerationCriteria[0].Value = value1 elif operator == "GreaterThan": DataModel.GetObjectById(objId).GenerationCriteria[ 0].Operator = SelectionOperatorType.GreaterThan DataModel.GetObjectById(objId).GenerationCriteria[0].Value = value1 elif operator == "LessThan": DataModel.GetObjectById(objId).GenerationCriteria[ 0].Operator = SelectionOperatorType.LessThan DataModel.GetObjectById(objId).GenerationCriteria[0].Value = value1 else: pass DataModel.GetObjectById(objId).Generate() NbElementsInSelection = len(DataModel.GetObjectById(objId).Ids) except: ExtAPI.Log.WriteMessage("Error : Could not create named selection") return NbElementsInSelection
10