Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Public Enum units
PoundsInches = 1
PoundsFeet = 2
GramsCentimeters = 3
KilogramsMeters = 4
End Enum
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const undoMarkName As String = "measure body"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim theSolid As Body = Nothing
Dim found As Boolean = False
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'$ change desired units here
Const analysisUnits As units = units.KilogramsMeters
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'iterate through the bodies collection, measure first solid body found
For Each temp As Body In workPart.Bodies
If temp.IsSolidBody Then
found = True
theSolid = temp
End If
Next
If Not found Then
lw.WriteLine("no solid body found in file")
Return
End If
Dim accuracyValues(10) As Double
accuracyValues(0) = 0.99
Dim massProps(46) As Double
Dim stats(12) As Double
theUfSession.Modl.AskMassProps3d({theSolid.Tag}, 1, 1, analysisUnits, 1, 1, accuracyValues, massProps, stats)
Dim surfaceArea As Double = massProps(0)
Dim volume As Double = massProps(1)
Dim mass As Double = massProps(2)
lw.WriteLine("units used: " & analysisUnits.ToString)
lw.WriteLine("mass: " & mass.ToString)
lw.WriteLine("volume: " & volume.ToString)
lw.WriteLine("surface area: " & surfaceArea.ToString)
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module