How to find surface area or volume in mechanical scriting

Options
Happy Kumar
Happy Kumar Member Posts: 15
First Comment

I want to find the surface area of surface and volume of different body which is in name selection by looping how I can do this ?

Answers

  • Abel Ramos
    Abel Ramos Member, Employee Posts: 40
    5 Likes First Answer First Comment First Anniversary
    Options

    Hello, you can use the GeoData

    Faces Example

    Volume Example

    Code:

    geoData=ExtAPI.DataModel.GeoData
    
    #-----Calculate Face Areas-----#
    
    myfacesNS = ExtAPI.DataModel.GetObjectsByName("MYFACES")[0]
    TotalArea = 0
    for faceId in myfacesNS.Location:
        face = geoData.GeoEntityById(faceId)
        TotalArea += face.Area
    
    print("Total Area = " + str(TotalArea))
    
    #-----Calculate Bodies Volumes-----#
    
    myBodiesNS = ExtAPI.DataModel.GetObjectsByName("MYVOLUMES")[0]
    TotalVolume = 0
    for bodyId in myBodiesNS.Location:
        body = geoData.GeoEntityById(bodyId)
        TotalVolume += body.Volume
    
    print("Total Volume = " + str(TotalVolume))
    

    Solution
    Total Area = 0.00119999996969
    Total Volume = 1.6e-05