Volume of a body in Mechanical

Indrajit
Indrajit Member Posts: 5
First Comment
**
edited June 2023 in Structures

Hello,

I am trying to get the volume of individual bodies in a Geometry assembly.

ExtAPI.DataModel.Project.Model.Geometry.Volume gave me the total volume of the model.

How should I get the volume of individual ones

Thanks,

Indrajit

Answers

  • Indrajit
    Indrajit Member Posts: 5
    First Comment
    **

    The following works

    entity = ExtAPI.DataModel.GeoData.GeoEntityById(sel.Ids[i])

    Volume = entity.Volume


    Thanks!

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭

    Hi @Indrajit , happy to see you on the forum and thanks for sharing your knowledge! There's two ways you can retrieve that information.

    As it is some information that is shown in the details view of the "tree geometry" for each body:

    You can use the Model API to get that info:

    bodies = Model.Geometry.GetChildren(DataModelObjectCategory.Body, True)
    for body in bodies:
        print('Body volume is: ' + str(body.Volume))
    

    This returns:


    Another method is to use GeoData to retrieve that information:

    bodies = Model.Geometry.GetChildren(DataModelObjectCategory.Body, True)
    for body in bodies:
        geobody = body.GetGeoBody()
        print('Body volume is: ' + str(geobody.Volume))
    

    This returns:

    For an explanation of the difference between a body as seen from the Mechanical tree and as seen from Geodata, please refer to this post:

    https://discuss.ansys.com/discussion/2288/whats-the-difference-between-tree-geometry-and-geodata-in-mechanical-api/p1?new=1

  • Indrajit
    Indrajit Member Posts: 5
    First Comment
    **

    Hi Pernelle,

    Thanks a lot.

    Lots of options to select from.

    Is there a Python command manual for Spaceclaim?

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭

    Hi @Indrajit , sorry for the late answer, I am back in the office just today.

    You can find a Developers Guide in the SpaceClaim installation files. If you're using a standard installation path, for 2023R1 this would be: C:\Program Files\ANSYS Inc\v231\scdm\SpaceClaim.Api.V23.

  • M
    M Member, Employee Posts: 244
    50 Answers 100 Comments 100 Likes Second Anniversary
    ✭✭✭✭
    edited March 5

    If you wanted to write the body data to file, you could use this script:

    import os
    
    save_directory = 'D:\\temp'
    save_file = 'body_data.csv'
    
    bodies = Model.Geometry.GetChildren(DataModelObjectCategory.Body, True)
    
    data = [] # result will be stored in the parameter 'data'
    
    for body in bodies:
        name = body.Name
        volume = body.Volume.Value #.Value for numeric results without units, !always be sure of your units
        mass = body.Mass.Value
        material = body.Material # Name of material
        data.append([name,material,volume,mass])
    
    with open(os.path.join(save_directory,save_file),'w') as f: # 'w' is to write to file
        for line in data:
            for data_point in line:
                f.write(str(data_point) + ',')
            f.write('\n')