How to select beams using Mechanical Scripting?

Options

Some solutions like https://discuss.ansys.com/discussion/2468/beam-results-dpf-mechanical 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:

assm=DataModel.GeoData.Assemblies
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
                #From: https://discuss.ansys.com/discussion/2361/getting-a-mechanical-body-from-a-geometry-geobodywrapper
                true_body=DataModel.Project.Model.Geometry.GetBody(body)
                #Next line shows that a beam has DataModelObjectCategory==Body instead of Beam
                print('DataModelObjectCategory= '+str(true_body.DataModelObjectCategory)+"; "+\
                                                  str(true_body.CrossSectionSelection.DataModelObjectCategory)+"; "+\
                                                  str(true_body.GeometryType))

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 ✓
    Options

    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.

Answers

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

    To complete the info to retrieve the Beams it means that in the code one has to check for:
    true_body.ModelType==PrototypeModelType.Beam

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