Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick journal/macro for measuring dimensions of model, and displaying Volume?

Status
Not open for further replies.

heythere

Aerospace
Dec 27, 2016
15
0
0
US
The model would be different each time I run the journal, but I'd like to get a quick way to orient the model ISO, then have the width, length, and height measurements displayed, along with a volume. (assigning material would be a bonus) Any help is greatly appreciated!

NX 10
 
Replies continue below

Recommended for you

In Nx there is some feature called "stock size". But it (probably) only work in Mold Wizard license. When You first use it on model, it will create properties called MW_STOCK_SIZE. Since NX 10, after You change your model, this properties will also change. The You can link it Values to expressions and calculate Volume.

Some time ago I was looking for journal to calculate mass of each part in assembly. I have found this journal, it can be useful for You.

Code:
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

With best regards
Michael
 
Status
Not open for further replies.
Back
Top