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

'Errorhandler
On Error Resume Next
Application.ActiveDocument.SelectionSets("TempSS").Delete
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

oSS.Delete

End Sub
Login

Sign up now and upload your code to the website.

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