Display Node and Element Counts
Description
This demonstrates the ability for the user to pick a selection of entities and show the total nodes and elements from the selection.
Python Script Files
- display_node_element_counts_ui.py
- display_node_element_counts.py
Significant Script Features
display_node_element_counts_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 = "Node Element Counts" # 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.Assembly) pickChoices.Add(apex_sdk.PickFilterTypes.Part) pickChoices.Add(apex_sdk.PickFilterTypes.SolidMesh) pickChoices.Add(apex_sdk.PickFilterTypes.SurfaceMesh) pickChoices.Add(apex_sdk.PickFilterTypes.CurveMesh) # Return the pick filter list return pickChoices
display_node_element_counts.py:
def get_node_element_counts(dict={}):
import apex
# Disable showing output dialog at the end
apex.disableShowOutput()
# Get all selected entities
selected_entities = apex.selection.getCurrentSelection()
num_nodes = 0
num_elements = 0
for entity in selected_entities:
num_nodes += entity.nodes.len()
num_elements += entity.elements.len()
ret_dict = {}
ret_dict['num_nodes'] = num_nodes
ret_dict['num_elements'] = num_elements
return ret_dict
- Log in to post comments

