Mesh Selected Bodies Example
Description
This demonstrates the ability for the user to pick entities in the current model to mesh with defined values for mesh type and mesh size.
Python Script Files
- mesh_selected_bodies_ui.py
- mesh_selected_bodies.py
Significant Script Features
mesh_selected_bodies_ui.py:
# Set pre-defined properties of ToolPropertyContainer def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Mesh Selected Bodies" # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand(System.Action(HandleApplyButton)) # Define PickFilterList my_toolProperty.ShowPickChoice = True my_toolProperty.PickFilterList = setPickFilterList() return my_toolProperty # Set PickFilters def setPickFilterList(): # Create an empty List of strings pickChoices = System.Collections.Generic.List[System.String]() # Exclusive picking and visibility picking pickChoices.Add(apex_sdk.PickFilterTypes.ExclusivePicking) pickChoices.Add(apex_sdk.PickFilterTypes.VisibilityPicking) # Add Types pickChoices.Add(apex_sdk.PickFilterTypes.Part) pickChoices.Add(apex_sdk.PickFilterTypes.Solid) pickChoices.Add(apex_sdk.PickFilterTypes.Surface) # Return the pick filter list return pickChoices # Apply button handler (Green check mark) # This function is called each time the Apply button is clicked @apex_sdk.errorhandler def HandleApplyButton(): # Create a Dictionary to store the user defined tool data dictionary = {} # Populate the Dictionary with the user defined tool data you need dictionary["MeshSize"]= meshSizeTextBox.Text dictionary["MeshType"]= meshTypeComboBox.Text # Call you Apex API script using the sunrScriptFunction() method # argument 1 = the fully qualified path name of your API script # argument 2 is the name of the function in your API script that will receive the Dictionary # argument 3 is the Dictionary containing the UI data apex_sdk.runScriptFunction(os.path.join(current_file_path, r"mesh_selected_bodies.py"), "mesh_selected_bodies", dictionary)
mesh_selected_bodies.py:
def mesh_selected_bodies(dictionary={}):
import apex
import time
# Disable showing output dialog at the end
apex.disableShowOutput()
# Get the UI data from the dictionary
mesh_size = float(dictionary["MeshSize"])
mesh_type = dictionary["MeshType"]
# Convert the mesh type to the enum required for the meshing function
mesh_types = {
"Mixed" : apex.mesh.SurfaceMeshElementShape.Mixed,
"Quadrilateral" : apex.mesh.SurfaceMeshElementShape.Quadrilateral,
"Triangle" : apex.mesh.SurfaceMeshElementShape.Triangle
}
mesh_type = mesh_types[mesh_type]
# Get all selected entities
meshable_bodies = apex.selection.getCurrentSelection()
# Start Meshing
apex.session.displayStatusMessage("Meshing started ...")
result = apex.mesh.createSurfaceMesh(
name = "",
target = meshable_bodies,
meshSize = mesh_size,
meshType = mesh_type,
meshMethod = apex.mesh.SurfaceMeshMethod.Auto,
mappedMeshDominanceLevel = 2,
elementOrder = apex.mesh.ElementOrder.Linear,
meshUsingPrincipalAxes = False,
refineMeshUsingCurvature = False,
elementGeometryDeviationRatio = 0.10,
elementMinEdgeLengthRatio = 0.20,
createFeatureMeshOnFillets = False,
createFeatureMeshOnChamfers = False,
createFeatureMeshOnWashers = False,
createFeatureMeshOnQuadFaces = False)
apex.session.displayStatusMessage("Meshing completed.")Notes
- The AppliedCommand is set to register the function handle for the Apply button click
- The mesh_selected_bodies() function receives a single Dictionary argument which meshes the selected bodies using the dictionary's definitions of mesh_size and mesh_type
- The apex.selection.getCurrentSelection() function is used in mesh_selected_bodies() to retrieve the current picked entities from the user
- Log in to post comments

