22 | 02 | 2017

Calculate Solids Mass and Volume

Code below lets you select a 3d Solid and the code will calculate the Volume. When you enter a Density then the Mass can be calculated too.

Sub MassPropD()

Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant

On Error Resume Next
On Error GoTo 0

TotalVolume = 0
'Create a selection set
Set oSS = Application.ActiveDocument.SelectionSets.Add("TempSS")

iFilterCode(0) = 0: vFilterValue(0) = "3dsolid"
'Filter on screen selection for 3d Solids
oSS.SelectOnScreen iFilterCode, vFilterValue
For Each ent In oSS
TotalVolume = TotalVolume + ent.Volume
Next ent

Density = InputBox("Enter Material Density: ")
Mass = Density * TotalVolume

MsgBox "Calculated Totalvolume: " & TotalVolume & vbCrLf & _
"Calculated Mass: " & Mass


End Sub

Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles