# How do I calculate the Area, Volume and Mass of an entity?

For each entity that implements the IFace interface are available the GetArea(), GetVolume() and GetMess() methods that allow you to easily get its area, volume and mass. Here is a sample code:

``````//here we set the linear units for the Area and Volume
model1.RootBlock.Units = linearUnitsType.Centimeters;

Brep cylinder = Brep.CreateCylinder(5, 10);

//prepares the material to apply to the cylinder
Material mat = Material.Gold;

//we need to regen the Brep in order to compute its geometric properties
cylinder.Regen(0.1);

double area = cylinder.GetArea(out Point3D areaCentroid);

double volume = cylinder.GetVolume(out Point3D volumeCentroid);

//The default system of measurement for the density of each material is kilograms per cubic meters.
//But we want to express the mass in cubic grams.
double mass = cylinder.GetMass(mat, linearUnitsType.Centimeters, massUnitsType.Grams,
out double convertedDensity);
``````
0 out of 0 found this helpful
Have more questions? Submit a request

• I cannot implement your sent code. When you implement the new changes in your examples. It is important to have a guide for all developed.

This is your code in the example: EyeshotDemo.vb

Private Sub areaButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles areaButton.Click
Dim ap As New AreaProperties()

Dim count As Integer = 0
Dim blockReferenceNotScaled As Boolean = True

For i As Integer = 0 To model1.Entities.Count - 1

Dim ent As Entity = model1.Entities(i)

If Not blockReferenceNotScaled Then Exit For
Next

Dim text As New StringBuilder()

If blockReferenceNotScaled Then

text.AppendLine(count.ToString() + " entity(ies) selected")
text.AppendLine("---------------------")

If ap.Centroid IsNot Nothing Then

Dim x As Double, y As Double, z As Double
Dim xx As Double, yy As Double, zz As Double, xy As Double, zx As Double, yz As Double
Dim world As MomentOfInertia, centroid As MomentOfInertia

ap.GetResults(ap.Area, ap.Centroid, x, y, z, xx,
yy, zz, xy, zx, yz, world,
centroid)

text.AppendLine("Cumulative area: " + ap.Area.ToString() + " square " + model1.CurrentBlock.Units.ToString().ToLower())
text.AppendLine("Cumulative centroid: " + ap.Centroid.ToString())
text.AppendLine("Cumulative area moments:")
text.AppendLine(" First moments")
text.AppendLine(" x: " + x.ToString("g6"))
text.AppendLine(" y: " + y.ToString("g6"))
text.AppendLine(" z: " + z.ToString("g6"))
text.AppendLine(" Second moments")
text.AppendLine(" xx: " + xx.ToString("g6"))
text.AppendLine(" yy: " + yy.ToString("g6"))
text.AppendLine(" zz: " + zz.ToString("g6"))
text.AppendLine(" Product moments")
text.AppendLine(" xy: " + xx.ToString("g6"))
text.AppendLine(" yz: " + yy.ToString("g6"))
text.AppendLine(" zx: " + zz.ToString("g6"))
text.AppendLine(" Area Moments of Inertia about World Coordinate Axes")
text.AppendLine(" Ix: " + world.Ix.ToString("g6"))
text.AppendLine(" Iy: " + world.Iy.ToString("g6"))
text.AppendLine(" Iz: " + world.Iz.ToString("g6"))
text.AppendLine(" Rx: " + world.Rx.ToString("g6"))
text.AppendLine(" Ry: " + world.Ry.ToString("g6"))
text.AppendLine(" Rz: " + world.Rz.ToString("g6"))
text.AppendLine(" Area Moments of Inertia about Centroid Coordinate Axes:")
text.AppendLine(" Ix: " + centroid.Ix.ToString("g6"))
text.AppendLine(" Iy: " + centroid.Iy.ToString("g6"))
text.AppendLine(" Iz: " + centroid.Iz.ToString("g6"))
text.AppendLine(" Rx: " + centroid.Rx.ToString("g6"))
text.AppendLine(" Ry: " + centroid.Ry.ToString("g6"))

text.AppendLine(" Rz: " + centroid.Rz.ToString("g6"))
End If
Else
text.AppendLine("Error: scaled BlockReference not supported")
text.AppendLine("---------------------")
End If

Dim rf As New DetailsForm()

rf.Text = "Area Properties"

rf.contentTextBox.Text = text.ToString()

rf.Show()

End Sub

REGARDS,

Gustavo Vigo

• Hi Gustavo,

The code you found within the EyeshotDemo source sample still represents a valid approach to compute Volume and Area of a set of entities.

With the release 2020, we simply add a few methods to immediately computes the Area and Volume of a single entity is a more intuitive way.

What problems did you encounter in using the code reported within this article?

Here is the Visual Basic sample:

model1.RootBlock.Units = linearUnitsType.Centimeters
Dim cylinder As Brep = Brep.CreateCylinder(5, 10)
Dim mat As Material = Material.Gold
cylinder.Regen(0.1)
Dim areaCentroid As Point3D = Nothing
Dim area As Double = cylinder.GetArea(areaCentroid)
Dim volumeCentroid As Point3D = Nothing
Dim volume As Double = cylinder.GetVolume(volumeCentroid)
Dim convertedDensity As Double = Nothing
Dim mass As Double = cylinder.GetMass(mat, linearUnitsType.Centimeters, massUnitsType.Grams, convertedDensity)