A Python script for Groups Manipulation

Purpose of the script

The script illustrates the reading of groups from a Patran session file, and the manipulation of these groups with the FeResPost Python extension.

Script

Python
from FeResPost import *
import sys

os=sys.stdout

# Reads the Groups into a Hash :

h=Post.readGroupsFromPatranSession("../../MODEL/PATRAN/groups.ses")
print(h)

# Prints Groups' data :

nbrEntitiesPerLine=8
for id,grp in h.items():
    os.write("Group \"%s\":\n"%id)

    nbr=grp.getNbrEntitiesByType("Element")
    os.write("   Nbr Elements: %d"%nbr)
    counter=0
    for id in grp.iter_element():
        if counter%nbrEntitiesPerLine==0:
            os.write("\n      ")
        os.write("%8d"%id)
        counter+=1
    os.write("\n\n")

    nbr=grp.getNbrEntitiesByType("MPC")
    os.write("   Nbr MPCs: %d"%nbr)
    counter=0
    for id in grp.iter_mpc():
        if counter%nbrEntitiesPerLine==0:
            os.write("\n      ")
        os.write("%8d"%id)
        counter+=1
    os.write("\n\n")

    nbr=grp.getNbrEntitiesByType("Node")
    os.write("   Nbr Nodes: %d"%nbr)
    counter=0
    for id in grp.iter_node():
        if counter%nbrEntitiesPerLine==0:
            os.write("\n      ")
        os.write("%8d"%id)
        counter+=1
    os.write("\n\n")

    nbr=grp.getNbrEntitiesByType("CoordSys")
    os.write("   Nbr CoordSys: %d"%nbr)
    counter=0
    for id in grp.iter_coordsys():
        if counter%nbrEntitiesPerLine==0:
            os.write("\n      ")
        os.write("%8d"%id)
        counter+=1
    os.write("\n\n")

Explanation

The different steps of the script are:

References

More information on this example, and on the functions it uses, is given in the FeResPost User Manual.

← Back to the examples