How to select beams using Mechanical Scripting?


Some solutions like mention the following line to select Beams in a mechanical model:
allBeams = DataModel.GetObjectsByType(DataModelObjectCategory.Beam)
This doesn't work for me in 24R1 even though the model has only beams present in it.

I have run the following script to find out what the DataModelObjectCategory is for beam elements:

for my_assm in assm:
    for part in my_assm.AllParts:
        for body in part.Bodies:
            if body.Suppressed==False:
                #body is a GeoBodyWrapper
                print(body.Name+" ("+str(body.GetType())+";"+str(body.BodyType)+")")
                #Get true body object instead of GeoBodyWrapper so that DataModelObjectCategory can be checked
                #Next line shows that a beam has DataModelObjectCategory==Body instead of Beam
                print('DataModelObjectCategory= '+str(true_body.DataModelObjectCategory)+"; "+\
                                                  str(true_body.CrossSectionSelection.DataModelObjectCategory)+"; "+\

The output shows that beam bodies have Body as DataModelObjectCategory and not Beam:

Beam (Bulb Profile L Equivalent) (Ansys.ACT.Common.Geometry.GeoBodyWrapper;GeoBodyWire)
DataModelObjectCategory= Body; ZCrossSection; Line
Beam (Bulb Profile L Equivalent) (Ansys.ACT.Common.Geometry.GeoBodyWrapper;GeoBodyWire)
DataModelObjectCategory= Body; ICrossSection; Line
Beam (Bulb Profile L Equivalent) (Ansys.ACT.Common.Geometry.GeoBodyWrapper;GeoBodyWire)
DataModelObjectCategory= Body; TCrossSection; Line
Beam (Bulb Profile L Equivalent) (Ansys.ACT.Common.Geometry.GeoBodyWrapper;GeoBodyWire)
DataModelObjectCategory= Body; CircularTubeCrossSection; Line
Beam (Bulb Profile L Equivalent) (Ansys.ACT.Common.Geometry.GeoBodyWrapper;GeoBodyWire)
DataModelObjectCategory= Body; LCrossSection; Line

My questions are:
1. Which type of bodies have the DataModelObjectCategory=Beam?
2. How can one easily select all beams in a model when selecting based on DataModelObjectCategory doesn't work?

Best Answer

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 308
    First Anniversary First Comment 5 Likes Ansys Employee
    Answer ✓

    There are “Beam” objects that can be created under the connections branch that are NOT based on the CAD geometry. This is what you would get with your code.

    For beam elements that are a result of mesh of a line body you would need to loop through the CAD bodies and then filter it by the ones with a beam formulation (vs link, cable etc…). This will get you the bodies themselves, but for the actual beam elements you will need to use the mesh data of the model to get the elements associated with those bodies.

    FYI, you can also use named selection worksheet logic to get this.


  • RvdH
    RvdH Member Posts: 5
    First Comment
    edited June 20

    To complete the info to retrieve the Beams it means that in the code one has to check for:

    Enum: PrototypeModelType
    Specifies the PrototypeModelType.
    Name Description
    AxisymmetricShell AxisymmetricShell.
    Beam Beam.
    Cable Cable.
    Link Link.
    ModelPhysicsTypeFluid ModelPhysicsTypeFluid.
    Pipe Pipe.
    Reinforcement Reinforcement.
    Shell Shell.