-
Notifications
You must be signed in to change notification settings - Fork 338
/
Copy pathSolidWeight.rvb
74 lines (63 loc) · 2.32 KB
/
SolidWeight.rvb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' SolidWeight.rvb
' Copyright (c) 2018 Robert McNeel & Associates.
' See License.md in the root of this repository for details.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Main subroutine
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub SolidWeight
' Declare local constants
Const RH_SURFACE = 8
Const RH_POLYSRF = 16
Const RH_MESH = 32
Const RH_CM = 3
' Declare local variables
Dim strObject, intType
Dim arrVolume, dblVolume, strVolume
Dim arrElement, strElement
Dim dblDensity, dblScale
Dim dblWeight, strWeight
' Prompt to select a solid object
intType = RH_SURFACE + RH_POLYSRF + RH_MESH
strObject = Rhino.GetObject("Select solid surface, polysurface, or mesh", intType, True)
If IsNull(strObject) Then Exit Sub
If Not Rhino.IsObjectSolid(strObject) Then Exit Sub
' Calculate the volume of the selected object
dblVolume = Null
If Rhino.IsMesh(strObject) Then
arrVolume = Rhino.MeshVolume(strObject)
If IsArray(arrVolume) Then dblVolume = arrVolume(1)
Else
arrVolume = Rhino.SurfaceVolume(strObject)
If IsArray(arrVolume) Then dblVolume = arrVolume(0)
End If
' Verify volume
If IsNull(dblVolume) Then
Call Rhino.Print("Unable to calculate volume.")
Exit Sub
End If
' Prompt for the element type
arrElement = Array("Gold", "Silver", "Platinum", "Palladium", "Copper")
strElement = Rhino.ListBox(arrElement, "Select element type:", "Solid Weight")
If IsNull(strElement) Then Exit Sub
' Density in grams per cubic centimeter
Select Case strElement
Case "Gold" dblDensity = 19.3
Case "Silver" dblDensity = 10.5
Case "Platinum" dblDensity = 21.4
Case "Palladium" dblDensity = 12.0
Case "Copper" dblDensity = 9.0
End Select
' Convert volume to cubic centimeters
dblScale = Rhino.UnitScale(RH_CM)
dblVolume = dblVolume * (dblScale ^ 3)
strVolume = FormatNumber(dblVolume, 3)
Call Rhino.Print("Volume = " & strVolume & " cubic centimeters")
' Calculate the weight in grams, where
' Weight = Volume x Density
dblWeight = dblVolume * dblDensity
strWeight = FormatNumber(dblWeight, 3)
Call Rhino.Print("Weight = " & strWeight & " grams")
End Sub