Volume of a body in Mechanical
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
-
The following works
entity = ExtAPI.DataModel.GeoData.GeoEntityById(sel.Ids[i])
Volume = entity.Volume
Thanks!
0 -
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:
2 -
Hi Pernelle,
Thanks a lot.
Lots of options to select from.
Is there a Python command manual for Spaceclaim?
0 -
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.
0 -
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')
1