How to create a Mesh Sizing object scoped to all Solid bodies?
I have a Model that contains Solids, Surfaces, and Lines (Beams). I want to create a Mesh Sizing object scoped to all active Solid bodies. The Sizing Type should be Sphere of Influence. Is there a way to do this automatically?
Best Answer
-
In order to make the process automatic, it's required to use a Mesh object that has a specified name. This way, the code can go through the objects in the Mesh group and check whether the one with the specified name exists. If it exists, then the script will only modify the scoping of the object. Otherwise, the code will create a Mesh object with the parameters specified in the script itself by the user.
A Python Code object can be used under the Model group with an 'After Geometry Changed' callback, so that the code is triggered each time the Geometry is updated. The code to use is:
# Parameters meshObjName = 'Element Sizing - Sphere of Influence' # Parameters if mesh object does not exist csName = 'Coordinate System' meshSphereRadius = 5 meshElementSize = 2 meshUnits = 'mm' # Select Solids that are unsuppressed solidsList = [] for obj in DataModel.Project.Model.Geometry.GetBodies(): if obj.GeometryType == GeometryType.Solid and not obj.ObjectState == ObjectState.Suppressed: solidsList.append(obj) selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = [solid.GetGeoBody().Id for solid in solidsList] # Create / Modify mesh object meshGroup = DataModel.Project.Model.Mesh if meshObjName not in [meshChild.Name for meshChild in meshGroup.Children]: meshObj = meshGroup.AddSizing() meshObj.Name = meshObjName meshObj.Location = selection meshObj.Type = SizingType.SphereOfInfluence csObj = DataModel.GetObjectsByName(csName)[0] meshObj.SphereCenter = csObj meshObj.SphereRadius = Quantity(meshSphereRadius, meshUnits) meshObj.ElementSize = Quantity(meshElementSize, meshUnits) elif meshObjName in [meshChild.Name for meshChild in meshGroup.Children]: meshObj = DataModel.GetObjectsByName(meshObjName)[0] meshObj.Location = selection
This script can be also executed manually in the Mechanical Scripting interface.
0