Easy Material Weight Management - Part 1

NX Study for Joinery Designers and others: Mastering Weight Management Through Journals, Component Creation, Dimension Tool and more without any licences

Hello guys,

I'm sharing my journals I've written to enhance my workflows with the hope that someone will find them just as useful as I have. If you encounter any issues or have some good ideas to add, feel free to reach out.

1. Weight Calculation in a Multi-body environment for solid bodies
I created several versions of the Material Journal and placed them on the ribbon.
To create and edit the journals, I recommend using Notepad++ or Visual Studio Code. Remember to save the files with a .vb extension - all my code is written in VB.Net
https://notepad-plus-plus.org/

- UPDATE: As a significant improvement to all journals, the recommended modifications mentioned in the comments are no longer relevant. All codes now have built-in unit system recognition or settings for it.
You can also download all of these, including icons, from GitHub:
https://github.com/lumberjack1970/EasyWeightforNX

Original thread used as a base code and guide for my first journal:
https://nxjournaling.com/content/random-appearance-color-selected-compon...

1. Material Journal
- EW_Material_12mm Plywood.vb: Changes body color, layer and transparency, sets a density value, measures volume, calculates weight, and attributes it: EW_Material, EW_Material_Density and EW_Body_Weight.

- NX_Material_12mm Plywood.vb: Changes body color, layer and transparency and sets an NX's built in material. You have to create your own Material Library - physicalmateriallibrary.xml - to use this.

- Face Material Journal - EW_Material_FACE_Inside: Alters the color of selected faces. Has priority over the main Material Journal. Used to distinguish the inside/outside of the body.

- Raw Body Journal - EW_Material_RAW BODY.vb and NX_Material_RAW BODY.vb: By selecting the original body and the raw body, this calculates the weight difference and adds a new attribute: Raw_Body_Delta_Weight. It also moves the raw body to a predefined layer and makes it transparent. Useful to handle this on a custom level.

- Delete Attributes Journal - EW_Material_DELETE ATTRIBUTES.vb and NX_Material_NULLMATERIAL.vb:
Keeps the body unchanged but removes any weight-related attributes or sets a "NullMaterial" with zero weight respectively. Created, so these bodies won’t be included in the weight calculation on the drawing.

2. Solid Body Material Filter Tool
Using this tool, you can control the visibility of specific solid bodies on your screen using the attributes assigned before. When creating components, it simplifies the process of organizing them. This tool automatically adjusts visibility based on the chosen materials. If no attribute is found, it hides them among the others. "Without Weight" option at the bottom displays all bodies that lack weight information. This allows you to double-check your work.
https://www.nxjournaling.com/content/easy-material-weight-management-sol...

3. Component Creator
This tool enables you to automatically create parts by requesting you a main component name. For example, "MyProject-01" creates: MyProject-01-101-Metal Front Frame, MyProject-01-102-Front Panel, etc. The names for the components will be created from the names of the solid bodies. If a solid body does not have anything assigned, the default name “Panel” will be used. You can change this later in the code. Select solid bodies to create components for. Follow the link below for detailed information.
https://www.nxjournaling.com/content/easy-material-weight-management-com...

4. Component Weight Transfer
In the Modeling environment/Main Assembly, this journal transfers weight information (weight attribute - EW_Body_Weight) from solid bodies to components. Summarizes all component weights to assign a Total Assembly Weight attribute to the Main Assembly, excluding weights of underlying components. To be used exclusively with the original - EW_Material_12mm Plywood. When you assign one of NX's built-in materials, this function occurs natively.
https://www.nxjournaling.com/content/easy-material-weight-management-com...

5. Total Weight to Drawings
In the Drafting environment, sums all solid body weights for a Total Built-in Weight and adds Raw body differences for a Total Environmental Weight in the title block. Does not require Component Weight Transfer Journal.
https://www.nxjournaling.com/content/easy-material-weight-management-tot...

Here are two additional journals to get you through the day, which are not related to 'weight':

6. Fully Automatic Dimension Tool - Length, Width, And Thickness
Automates dimension and material thickness annotation in Siemens NX components for non-aligned solid bodies. Follow the link below for detailed information.
https://www.nxjournaling.com/content/fully-automatic-dimension-tool-leng...

7. Report Missing Parts List Balloons
I believe this comprehensive workflow wouldn't be complete without mentioning a very important journal. While I am not its creator, I am a devoted user of it. If you're new to this, it's a must have. Originally written by Frank Berger. Wherever I go, I find it being used by many companies. It has undergone some iterations, and as of 2024, this is the working version refined by NXJournaling. It performs exactly as the title suggests: in the drafting environment, when you have created an exploded view, for example, this journal will report which items in the parts list do not have a corresponding balloon callout.
https://www.nxjournaling.com/content/report-missing-parts-list-balloons

8. Construction Objects Visibility
This journal offers an intuitive way to manage the visibility of various construction objects, such as Sketches, Curves, Datums, Routing, Assembly Constraints, and Layers.
https://www.nxjournaling.com/content/construction-objects-visibility

Important to know:
- EasyWeight is calculated during the Material Journal to a solid body.
- Journals are not associative. Any geometry changes require Journal reapplication.
- Component Creator updates all relevant EasyWeight information by default.

EasyWeight Material Journal:

' Journal desciption: Changes body color, layer and translucency, sets a density value, measures volume, calculates weight, and attributes it: EW_Body_Weight, EW_Material_Density and EW_Material.
' Shared on NXJournaling.com
' Written in VB.Net
' Tested on Siemens NX 2212 and 2306, Native and Teamcenter 13
' V100 - Initial Release - November 2023
' V101 - Unit system support and Configuration Settings

Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.UF

Module NXJournal
Dim theSession As Session
Dim theUFSession As UFSession
Dim workPart As Part
Dim displayPart As Part
Dim mySelectedObjects As New List(Of DisplayableObject)
Dim theUI As UI
Dim bodyWeight As Double

'------------------------
' Configuration Settings:

' Material Name - Change this name to your own material
Dim materialname As String = "12mm Plywood"

' Material Density - Kg/m3 or Pound/Cubic Foot - Change this value to your own specific density
Dim density As Double = 440

' Unit System - "kg" for Kilograms or "lbm" for Pounds.
Dim unitsystem As String = "kg"

' Body Settings:
Dim bodycolor As Double = 111 ' Set the solid body color to ID: 111
Dim bodylayer As Double = 1 ' Set the solid body to layer 1
Dim bodytranslucency As Double = 0 ' Set the solid body transparency to 0

'------------------------

Sub Main(ByVal args() As String)
Try
theSession = Session.GetSession()
theUFSession = UFSession.GetUFSession()
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
theUI = UI.GetUI()

Dim markId1 As Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Material Journal")

If SelectObjects("Hey, select multiple somethings", mySelectedObjects) = Selection.Response.Ok Then
For Each tempComp As Body In mySelectedObjects
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()

With displayModification1
.ApplyToAllFaces = False
.ApplyToOwningParts = True
.NewColor = bodycolor
.NewLayer = bodylayer
.NewTranslucency = bodytranslucency
.Apply({tempComp})
End With

displayModification1.Dispose()

'DeleteAllAttributes(tempComp)
AddBodyAttribute(tempComp, "EW_Material", materialname)

Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, {tempComp}, AttributePropertiesBuilder.OperationType.None)
attributePropertiesBuilder1.Title = "EW_Material_Density"
attributePropertiesBuilder1.DataType = NXOpen.AttributePropertiesBaseBuilder.DataTypeOptions.Number

If unitsystem = "kg" Then
attributePropertiesBuilder1.Units = "KilogramPerCubicMeter"
Else
attributePropertiesBuilder1.Units = "PoundMassPerCubicFoot"
End If

attributePropertiesBuilder1.NumberValue = density

AddBodyAttribute(tempComp, "Component_created", String.Empty)

Dim nXObject1 As NXObject
nXObject1 = attributePropertiesBuilder1.Commit()
attributePropertiesBuilder1.Destroy()

' Calculate volume using mass properties
Dim myMeasure As MeasureManager = workPart.MeasureManager()
Dim massUnits(4) As Unit
massUnits(1) = workPart.UnitCollection.GetBase("Volume")
Dim mb As MeasureBodies = myMeasure.NewMassProperties(massUnits, 0.99, {tempComp})

' Create or update an attribute named 'EW_Body_Weight' and assign the weight value to it
Dim attributePropertiesBuilderForWeight As AttributePropertiesBuilder
attributePropertiesBuilderForWeight = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, {tempComp}, AttributePropertiesBuilder.OperationType.Create)

If unitsystem = "kg" Then
mb.InformationUnit = MeasureBodies.AnalysisUnit.KilogramMilliMeter
' Extract volume and multiply it by density to get weight
Dim bodyVolume As Double = mb.Volume
bodyWeight = bodyVolume / 1000000000.0 * density
attributePropertiesBuilderForWeight.Units = "Kilogram"
Else
mb.InformationUnit = MeasureBodies.AnalysisUnit.PoundInch
Dim bodyVolume As Double = mb.Volume
bodyWeight = bodyVolume / 1728 * density
attributePropertiesBuilderForWeight.Units = "Lbm"
End If

attributePropertiesBuilderForWeight.Title = "EW_Body_Weight"
attributePropertiesBuilderForWeight.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.Number
attributePropertiesBuilderForWeight.NumberValue = bodyWeight
Dim attributeObjectForWeight As NXObject = attributePropertiesBuilderForWeight.Commit()
attributePropertiesBuilderForWeight.Destroy()
Next
End If
Catch ex As Exception
Console.WriteLine("Houston, we have a situation... an error occurred: " & ex.Message)
End Try
End Sub

Function SelectObjects(prompt As String,
ByRef dispObj As List(Of DisplayableObject)) As Selection.Response
Dim selObj As NXObject()
Dim title As String = ("Select solid bodies - " & materialname)
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt,
title, scope, selAction,
includeFeatures, keepHighlighted, selectionMask_array,
selObj)

If resp = Selection.Response.ObjectSelected Or
resp = Selection.Response.ObjectSelectedByName Or
resp = Selection.Response.Ok Then
For Each item As NXObject In selObj
dispObj.Add(CType(item, DisplayableObject))
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function

Sub AddBodyAttribute(ByVal theBody As Body, ByVal attTitle As String, ByVal attValue As String)
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, {theBody}, AttributePropertiesBuilder.OperationType.None)

attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String

attributePropertiesBuilder1.Title = attTitle
attributePropertiesBuilder1.StringValue = attValue

Dim nXObject1 As NXObject
nXObject1 = attributePropertiesBuilder1.Commit()

attributePropertiesBuilder1.Destroy()
End Sub

Sub DeleteAllAttributes(ByVal theObject As NXObject)
Dim attributeInfo() As NXObject.AttributeInformation = theObject.GetUserAttributes()

For Each temp As NXObject.AttributeInformation In attributeInfo
theObject.DeleteUserAttributes(temp.Type, Update.Option.Now)
Next
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module

NX Material Journal:

' Journal desciption: Changes body color, layer and translucency, and sets a NX's built in material.
' Shared on NXJournaling.com
' Written in VB.Net
' Tested on Siemens NX 2212 and 2306, Native and Teamcenter 13
' V100 - Initial Release - November 2023
' V101 - Code cleanup to focus mainly on NX's built in material and added Configuration Settings

Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.UF

Module NXJournal
Dim theSession As Session
Dim theUFSession As UFSession
Dim workPart As Part
Dim displayPart As Part
Dim mySelectedObjects As New List(Of DisplayableObject)
Dim physicalMaterial1 As PhysicalMaterial = Nothing
Dim theUI As UI

'------------------------
' Configuration Settings:

' Material Name - This name has to match with your created material in your library
Dim materialName As String = "12mm Plywood"

' Material Library Path
Dim materialLibraryPath As String = "C:\Your Folder\To your material library\physicalmateriallibrary_custom.xml"

' Body Settings:
Dim bodycolor As Double = 111 ' Set the solid body color to ID: 111
Dim bodylayer As Double = 1 ' Set the solid body to layer 1
Dim bodytranslucency As Double = 0 ' Set the solid body transparency to 0
'------------------------

Sub Main(ByVal args() As String)

Try
theSession = Session.GetSession()
theUFSession = UFSession.GetUFSession()
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
theUI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim markId1 As Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Material Journal")

' Initialize the builders
Dim physicalMaterialListBuilder1 As NXOpen.PhysMat.PhysicalMaterialListBuilder = Nothing
Dim physicalMaterialAssignBuilder1 As NXOpen.PhysMat.PhysicalMaterialAssignBuilder = Nothing
physicalMaterialListBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder()
physicalMaterialAssignBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateMaterialAssignBuilder()
Dim materialLibraryLoaded As Boolean = False
Try
' Check if the material is already loaded
Dim loadedMaterial As NXOpen.Material = workPart.MaterialManager.PhysicalMaterials.GetLoadedLibraryMaterial(materialLibraryPath, materialName)
If loadedMaterial Is Nothing Then
' Material is not loaded, load it from the library
physicalMaterial1 = workPart.MaterialManager.PhysicalMaterials.LoadFromMatmlLibrary(materialLibraryPath, materialName)
materialLibraryLoaded = True
'lw.WriteLine("Material library loaded.")
Else
physicalMaterial1 = loadedMaterial
materialLibraryLoaded = True
'lw.WriteLine("Material already loaded.")
End If
Catch ex As Exception
lw.WriteLine("Failed to check/load material library: " & ex.Message)
End Try

If SelectObjects("Hey, select multiple somethings", mySelectedObjects) = Selection.Response.Ok Then
For Each tempComp As Body In mySelectedObjects
Try
Dim pmaterialname as String = ("PhysicalMaterial[" & materialName & "]")
Dim physicalMaterial1 As NXOpen.PhysicalMaterial = CType(workPart.MaterialManager.PhysicalMaterials.FindObject(pmaterialname), NXOpen.PhysicalMaterial)
If physicalMaterial1 Is Nothing Then
lw.WriteLine("Error: Material " & materialName & " not found.")
Return
End If

Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()

With displayModification1
.ApplyToAllFaces = False
.ApplyToOwningParts = True
.NewColor = bodycolor
.NewLayer = bodylayer
.NewTranslucency = bodytranslucency
.Apply({tempComp})
End With

displayModification1.Dispose()

AddBodyAttribute(tempComp, "Component_created", String.Empty)

If physicalMaterial1 IsNot Nothing Then
physicalMaterial1.AssignObjects(New NXOpen.NXObject() {tempComp})
'lw.WriteLine("Material " & materialName & " successfully assigned to body: " & tempComp.JournalIdentifier)
Else
lw.WriteLine("Error: Material " & materialName & " not found in the material library.")
End If
Catch ex As Exception
lw.WriteLine("Error processing body: " & tempComp.JournalIdentifier & " - " & ex.Message)
lw.WriteLine("Exception occurred: " & ex.ToString())
End Try
Next
theSession.UpdateManager.DoUpdate(markId1)
Else
lw.WriteLine("No objects were selected.")
End If

If physicalMaterialAssignBuilder1 IsNot Nothing Then
physicalMaterialAssignBuilder1.Destroy()
physicalMaterialAssignBuilder1 = Nothing
End If

If physicalMaterialListBuilder1 IsNot Nothing Then
physicalMaterialListBuilder1.Destroy()
physicalMaterialListBuilder1 = Nothing
End If
Catch ex As Exception
Console.WriteLine("Houston, we have a situation... an error occurred: " & ex.Message)
Finally
If physicalMaterial1 IsNot Nothing Then
physicalMaterial1 = Nothing
End If
End Try
End Sub

Function SelectObjects(prompt As String,
ByRef dispObj As List(Of DisplayableObject)) As Selection.Response
Dim selObj As NXObject()
Dim title As String = ("Select solid bodies - " & materialName)
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt,
title, scope, selAction,
includeFeatures, keepHighlighted, selectionMask_array,
selObj)

If resp = Selection.Response.ObjectSelected Or
resp = Selection.Response.ObjectSelectedByName Or
resp = Selection.Response.Ok Then
For Each item As NXObject In selObj
dispObj.Add(CType(item, DisplayableObject))
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function

Sub AddBodyAttribute(ByVal theBody As Body, ByVal attTitle As String, ByVal attValue As String)
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, {theBody}, AttributePropertiesBuilder.OperationType.None)

attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String

attributePropertiesBuilder1.Title = attTitle
attributePropertiesBuilder1.StringValue = attValue

Dim nXObject1 As NXObject
nXObject1 = attributePropertiesBuilder1.Commit()

attributePropertiesBuilder1.Destroy()
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module

Face Material Journal:

' Journal desciption: Alters the color of selected faces. Has priority over the main Material Journal. Used to distinguish the inside/outside of the body.
' Shared on NXJournaling.com
' Written in VB.Net
' Tested on Siemens NX 2212 and 2306, Native and Teamcenter 13
' V100 - Initial Release - November 2023
' V101 - Configuration Settings

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow

'------------------------
' Configuration Settings:

' Face Settings:
Dim facecolor As Double = 17 ' Set the face color to ID: 17
Dim facename As String = "Inside"
'------------------------

Sub Main()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Face Color")
Dim selobj As NXObject
Dim type As Integer
Dim subtype As Integer
Dim theFaces As New List(Of Face)
Dim theUI As UI = UI.GetUI
Dim numsel As Integer = theUI.SelectionManager.GetNumSelectedObjects()

' Process the preselected Faces
If numsel > 0 Then
For inx As Integer = 0 To numsel - 1
selobj = theUI.SelectionManager.GetSelectedTaggedObject(inx)
theUfSession.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)
If type = UFConstants.UF_solid_type Then
theFaces.Add(selobj)
End If
Next
Else
' Prompt to select Faces
If SelectFaces("Select Faces to change color", theFaces) = Selection.Response.Cancel Then
Return
End If
End If

For Each temp As Face In theFaces
Dim displayModification As DisplayModification = theSession.DisplayManager.NewDisplayModification()
With displayModification
' .ApplyToAllFaces = False
.ApplyToOwningParts = True
.NewColor = facecolor
.Apply({temp})
End With
displayModification.Dispose()
Next
End Sub

Function SelectFaces(ByVal prompt As String, ByRef selFace As List(Of Face)) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = ("Select Faces - " & facename)
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj() As TaggedObject

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt,
title, scope, selAction,
includeFeatures, keepHighlighted, selectionMask_array, selObj)

If resp = Selection.Response.Ok Then
For Each temp As TaggedObject In selObj
selFace.Add(temp)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function

End Module

EW_Raw Body Journal:

' Journal desciption: By selecting the original body and the raw body, this calculates the weight difference and adds a new attribute: Raw_Body_Delta_Weight. It also moves the raw body to a predefined layer and makes it transparent.
' Shared on NXJournaling.com
' Written in VB.Net
' Tested on Siemens NX 2212 and 2306, Native and Teamcenter 13
' V100 - Initial Release - November 2023
' V101 - Unit system support and added Configuration Settings

Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.UF

Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession
Dim workPart As Part
Dim displayPart As Part
Dim mySelectedObjects As New List(Of DisplayableObject)
Dim theUI As UI
Dim lw As ListingWindow = theSession.ListingWindow
Dim scrib_weight As Double

'------------------------
' Configuration Settings:

' Body Settings:
Dim bodyLayer As Integer = 170 ' Set the solid body to layer 170
Dim bodyTranslucency As Integer = 70 ' Set the solid body transparency to 70
'------------------------

Sub Main(ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Raw Body Journal")

lw.Open()
Try
theSession = Session.GetSession()
theUFSession = UFSession.GetUFSession()
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
theUI = UI.GetUI()

' Variables to store attributes from the first selected body (original body)
Dim origmat_density As Double = 0.0
Dim orig_weight As Double = 0.0

' First selection for the original body
Try
If SelectObjects("Select the Original body", mySelectedObjects) = Selection.Response.Ok Then
For Each tempComp As Body In mySelectedObjects
Dim attributes = tempComp.GetUserAttributes()
For Each attr1 As NXObject.AttributeInformation In attributes
If attr1.Title = "EW_Material_Density" Then
origmat_density = CDbl(attr1.StringValue)
ElseIf attr1.Title = "EW_Body_Weight" Then
orig_weight = CDbl(attr1.StringValue)
End If
Next
Next
End If
If origmat_density = 0.0 Or orig_weight = 0.0 Then
'Throw New Exception("Failed to decipher the weight value for this body! Please apply the appropriate Material Journal before proceeding")
End If

' Clear previous selections
mySelectedObjects.Clear()

' Second selection for the Raw body
If SelectObjects("Select the Raw body", mySelectedObjects) = Selection.Response.Ok Then
For Each tempComp As Body In mySelectedObjects
' Measure Raw body volume
Dim myMeasure As MeasureManager = workPart.MeasureManager()
Dim massUnits(4) As Unit
massUnits(1) = workPart.UnitCollection.GetBase("Volume")

Dim mb As MeasureBodies = myMeasure.NewMassProperties(massUnits, 0.99, {tempComp})

Dim bodyVolume As Double = mb.Volume
If bodyVolume = 0.0 Then
Throw New Exception("Invalid body volume.")
End If

If Double.IsNaN(scrib_weight) Or Double.IsInfinity(scrib_weight) Then
Throw New Exception("Invalid Raw weight calculated.")
End If

' Add new attribute
Dim attributePropertiesBuilderForWeight As AttributePropertiesBuilder
attributePropertiesBuilderForWeight = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, {tempComp}, AttributePropertiesBuilder.OperationType.Create)
attributePropertiesBuilderForWeight.Title = "Raw_Body_Delta_Weight"
attributePropertiesBuilderForWeight.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.Number

' Now, perform the unit check on the currentPart
If workPart.PartUnits = BasePart.Units.Inches Then

mb.InformationUnit = MeasureBodies.AnalysisUnit.PoundInch
attributePropertiesBuilderForWeight.Units = "Lbm"
scrib_weight = origmat_density * (bodyVolume / 1728) - orig_weight
Else

mb.InformationUnit = MeasureBodies.AnalysisUnit.KilogramMilliMeter
attributePropertiesBuilderForWeight.Units = "Kilogram"
scrib_weight = origmat_density * (bodyVolume / 1000000000.0) - orig_weight
End If

attributePropertiesBuilderForWeight.NumberValue = scrib_weight
AddBodyAttribute(tempComp, "Component_created", String.Empty)
Dim attributeObjectForWeight As NXObject = attributePropertiesBuilderForWeight.Commit()
attributePropertiesBuilderForWeight.Destroy()

' Delete old attribute
DeleteUserAttribute(tempComp, "EW_Body_Weight")

' Move body to Layer
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
With displayModification1
.ApplyToAllFaces = False
.ApplyToOwningParts = True
.NewTranslucency = bodyTranslucency
.NewLayer = bodyLayer
.Apply({tempComp})
End With
displayModification1.Dispose()
Next
End If
Catch ex As Exception
lw.WriteLine("An error occurred: " & ex.Message)
Finally
lw.Close()
End Try

Catch ex As Exception
Console.WriteLine("An error occurred: " & ex.Message)
End Try
End Sub

Function SelectObjects(prompt As String,
ByRef dispObj As List(Of DisplayableObject)) As Selection.Response
Dim selObj As NXObject() = Nothing
Dim title As String = prompt
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt,
title, scope, selAction,
includeFeatures, keepHighlighted, selectionMask_array,
selObj)

If resp = Selection.Response.ObjectSelected Or
resp = Selection.Response.ObjectSelectedByName Or
resp = Selection.Response.Ok Then
For Each item As NXObject In selObj
dispObj.Add(CType(item, DisplayableObject))
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function

Sub AddBodyAttribute(ByVal theBody As Body, ByVal attTitle As String, ByVal attValue As String)
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, {theBody}, AttributePropertiesBuilder.OperationType.None)

attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String

attributePropertiesBuilder1.Title = attTitle
attributePropertiesBuilder1.StringValue = attValue

Dim nXObject1 As NXObject
nXObject1 = attributePropertiesBuilder1.Commit()

attributePropertiesBuilder1.Destroy()
End Sub

Sub DeleteUserAttribute(ByVal theObject As NXObject, ByVal attributeName As String)
Dim attributeInfo() As NXObject.AttributeInformation = CType(theObject, Body).GetUserAttributes()

For Each temp As NXObject.AttributeInformation In attributeInfo
If temp.Title = attributeName Then
theObject.DeleteUserAttribute(temp.Type, temp.Title, False, Update.Option.Now)
Exit For
End If
Next
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

NX_Raw Body Journal:

' Journal desciption: By selecting the original body and the raw body, this calculates the weight difference and adds a new attribute: Raw_Body_Delta_Weight. It also moves the raw body to a predefined layer and makes it transparent.
' Shared on NXJournaling.com
' Written in VB.Net
' Tested on Siemens NX 2212 and 2306, Native and Teamcenter 13
' V100 - Initial Release - November 2023
' V101 - Code cleanup to focus mainly on NX's built in material, Unit system support and added Configuration Settings

Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.UF

Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim workPart As Part
Dim displayPart As Part
Dim mySelectedObjects As New List(Of DisplayableObject)
Dim physicalMaterial1 As PhysicalMaterial = Nothing
Dim theUI As UI
Dim lw As ListingWindow = theSession.ListingWindow

'------------------------
' Configuration Settings:

' Material Name - This name has to match with your created material in your library
Dim materialName As String = "NullMaterial"

' Material Library Path
Dim materialLibraryPath As String = "C:\Your Folder\To your material library\physicalmateriallibrary_custom.xml"

' Body Settings:
Dim bodyLayer As Integer = 170 ' Set the solid body to layer 170
Dim bodyTranslucency As Integer = 70 ' Set the solid body transparency to 70
'------------------------

Sub Main(ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Raw Body Journal")

lw.Open()
Try
theSession = Session.GetSession()
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
theUI = UI.GetUI()

' Variables to store weight from the first and second selected body
Dim orig_weight As Double = 0.0
Dim Raw_weight As Double = 0.0

' First selection for the original body
If SelectObjects("Select the Original body", mySelectedObjects) = Selection.Response.Ok Then
For Each tempComp As Body In mySelectedObjects
orig_weight = GetBodyWeight(tempComp)
Next
End If

mySelectedObjects.Clear()

' Second selection for the Raw body
If SelectObjects("Select the Raw body", mySelectedObjects) = Selection.Response.Ok Then
For Each tempComp As Body In mySelectedObjects
Raw_weight = GetBodyWeight(tempComp)
' Calculate the weight difference
Dim weight_difference As Double = Raw_weight - orig_weight

' Add new attribute for weight difference
Dim attributePropertiesBuilderForWeight As AttributePropertiesBuilder
attributePropertiesBuilderForWeight = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, {tempComp}, AttributePropertiesBuilder.OperationType.Create)
attributePropertiesBuilderForWeight.Title = "Raw_Body_Delta_Weight"
attributePropertiesBuilderForWeight.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.Number
attributePropertiesBuilderForWeight.NumberValue = weight_difference

' Now, perform the unit check on the currentPart
If workPart.PartUnits = BasePart.Units.Inches Then
attributePropertiesBuilderForWeight.Units = "Lbm"
Else
attributePropertiesBuilderForWeight.Units = "Kilogram"
End If

Dim attributeObjectForWeight As NXObject = attributePropertiesBuilderForWeight.Commit()
attributePropertiesBuilderForWeight.Destroy()

' Initialize the builders
Dim physicalMaterialListBuilder1 As NXOpen.PhysMat.PhysicalMaterialListBuilder = Nothing
Dim physicalMaterialAssignBuilder1 As NXOpen.PhysMat.PhysicalMaterialAssignBuilder = Nothing
physicalMaterialListBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder()
physicalMaterialAssignBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateMaterialAssignBuilder()
Dim materialLibraryLoaded As Boolean = False
Try
' Check if the material is already loaded
Dim loadedMaterial As NXOpen.Material = workPart.MaterialManager.PhysicalMaterials.GetLoadedLibraryMaterial(materialLibraryPath, materialName)
If loadedMaterial Is Nothing Then
' Material is not loaded, load it from the library
physicalMaterial1 = workPart.MaterialManager.PhysicalMaterials.LoadFromMatmlLibrary(materialLibraryPath, materialName)
materialLibraryLoaded = True
'lw.WriteLine("Material library loaded.")
Else
physicalMaterial1 = loadedMaterial
materialLibraryLoaded = True
'lw.WriteLine("Material already loaded.")
End If
Catch ex As Exception
'lw.WriteLine("Failed to check/load material library: " & ex.Message)
End Try

' Apply display and material changes
Try
Dim pmaterialname As String = ("PhysicalMaterial[" & materialName & "]")
Dim physicalMaterial1 As NXOpen.PhysicalMaterial = CType(workPart.MaterialManager.PhysicalMaterials.FindObject(pmaterialname), NXOpen.PhysicalMaterial)
If physicalMaterial1 Is Nothing Then
lw.WriteLine("Error: Material " & materialName & " not found.")
Return
End If

Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()

With displayModification1
.ApplyToAllFaces = False
.ApplyToOwningParts = True
.NewLayer = bodyLayer
.NewTranslucency = bodyTranslucency
.Apply({tempComp})
End With

displayModification1.Dispose()

If physicalMaterial1 IsNot Nothing Then
physicalMaterial1.AssignObjects(New NXOpen.NXObject() {tempComp})
'lw.WriteLine("Material " & materialName & " successfully assigned to body: " & tempComp.JournalIdentifier)
Else
lw.WriteLine("Error: Material " & materialName & " not found in the material library.")
End If
Catch ex As Exception
lw.WriteLine("Error processing body: " & tempComp.JournalIdentifier & " - " & ex.Message)
lw.WriteLine("Exception occurred: " & ex.ToString())
End Try

If physicalMaterialAssignBuilder1 IsNot Nothing Then
physicalMaterialAssignBuilder1.Destroy()
physicalMaterialAssignBuilder1 = Nothing
End If

If physicalMaterialListBuilder1 IsNot Nothing Then
physicalMaterialListBuilder1.Destroy()
physicalMaterialListBuilder1 = Nothing
End If
Next
End If
Catch ex As Exception
lw.WriteLine("An error occurred: " & ex.Message)
Finally
lw.Close()
End Try
End Sub

Function SelectObjects(prompt As String,
ByRef dispObj As List(Of DisplayableObject)) As Selection.Response
Dim selObj As NXObject() = Nothing
Dim title As String = prompt
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt,
title, scope, selAction,
includeFeatures, keepHighlighted, selectionMask_array,
selObj)

If resp = Selection.Response.ObjectSelected Or
resp = Selection.Response.ObjectSelectedByName Or
resp = Selection.Response.Ok Then
For Each item As NXObject In selObj
dispObj.Add(CType(item, DisplayableObject))
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function

Function GetBodyWeight(body As Body) As Double
Dim weight As Double = 0.0
Dim myMeasure As MeasureManager = theSession.Parts.Work.MeasureManager
Dim theBodies(0) As Body
theBodies(0) = body

Dim massUnits(4) As NXOpen.Unit
massUnits(2) = theSession.Parts.Work.UnitCollection.GetBase("Mass")

Try
Dim mb As MeasureBodies = myMeasure.NewMassProperties(massUnits, 0.99, theBodies)
weight = mb.Mass
mb.Dispose()
Catch ex As Exception
lw.WriteLine("Error measuring body weight: " & ex.Message)
End Try
Return weight
End Function

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

EW_Delete Attributes Journal:

' Journal desciption: Keeps the solid body unchanged but removes any weight-related EasyWeight attributes.
' Shared on NXJournaling.com
' Written in VB.Net
' Tested on Siemens NX 2212 and 2306, Native and Teamcenter 13
' V100 - Initial Release - November 2023

Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.UF

Module NXJournal
Dim theSession As Session
Dim theUFSession As UFSession
Dim workPart As Part
Dim displayPart As Part
Dim mySelectedObjects As New List(Of DisplayableObject)
Dim theUI As UI

Sub Main(ByVal args() As String)
Try
theSession = Session.GetSession()
theUFSession = UFSession.GetUFSession()
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
theUI = UI.GetUI()

Dim markId1 As Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete Attributes")

Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

If SelectObjects("Select bodies", mySelectedObjects) = Selection.Response.Ok Then
' Convert DisplayableObjects to Bodies
Dim selectedBodies As New List(Of Body)
For Each obj As DisplayableObject In mySelectedObjects
If TypeOf obj Is Body Then
selectedBodies.Add(CType(obj, Body))
End If
Next

' Delete user attributes
For Each body As Body In selectedBodies
DeleteUserAttribute(body, "EW_Material")
DeleteUserAttribute(body, "EW_Body_Weight")
DeleteUserAttribute(body, "EW_Material_Density")
Next

' Commit the changes
theSession.UpdateManager.DoUpdate(markId1)
Else
lw.WriteLine("No objects were selected.")
End If
Catch ex As Exception
' Handle exceptions here
Console.WriteLine("An error occurred: " & ex.Message)
End Try
End Sub

Function SelectObjects(prompt As String,
ByRef dispObj As List(Of DisplayableObject)) As Selection.Response
Dim selObj As NXObject()
Dim title As String = "Select solid bodies to DELETE their Weight Data"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt,
title, scope, selAction,
includeFeatures, keepHighlighted, selectionMask_array,
selObj)

If resp = Selection.Response.ObjectSelected Or
resp = Selection.Response.ObjectSelectedByName Or
resp = Selection.Response.Ok Then
For Each item As NXObject In selObj
dispObj.Add(CType(item, DisplayableObject))
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function

Sub DeleteUserAttribute(ByVal theObject As NXObject, ByVal attributeName As String)
Dim attributeInfo() As NXObject.AttributeInformation = CType(theObject, Body).GetUserAttributes()

For Each temp As NXObject.AttributeInformation In attributeInfo
If temp.Title = attributeName Then
theObject.DeleteUserAttribute(temp.Type, temp.Title, False, Update.Option.Now)
Exit For
End If
Next
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module

NX_Material_NULLMATERIAL Journal:

' Journal desciption: Sets a NX's built in 'Null' material for empty values.
' Shared on NXJournaling.com
' Written in VB.Net
' Tested on Siemens NX 2212 and 2306, Native and Teamcenter 13
' V100 - Initial Release - November 2023
' V101 - Code cleanup to focus mainly on NX's built in material and added Configuration Settings

Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.UF

Module NXJournal
Dim theSession As Session
Dim theUFSession As UFSession
Dim workPart As Part
Dim displayPart As Part
Dim mySelectedObjects As New List(Of DisplayableObject)
Dim physicalMaterial1 As PhysicalMaterial = Nothing
Dim theUI As UI

'------------------------
' Configuration Settings:

' Material Name
Dim materialName As String = "NullMaterial" ' Make sure this name is matches with your created material in your library

' Material Library Path
Dim materialLibraryPath As String = "C:\Your Folder\To your material library\physicalmateriallibrary_custom.xml"
'------------------------

Sub Main(ByVal args() As String)

Try
theSession = Session.GetSession()
theUFSession = UFSession.GetUFSession()
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
theUI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim markId1 As Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Material Journal")

' Initialize the builders
Dim physicalMaterialListBuilder1 As NXOpen.PhysMat.PhysicalMaterialListBuilder = Nothing
Dim physicalMaterialAssignBuilder1 As NXOpen.PhysMat.PhysicalMaterialAssignBuilder = Nothing
physicalMaterialListBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder()
physicalMaterialAssignBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateMaterialAssignBuilder()
Dim materialLibraryLoaded As Boolean = False
Try
' Check if the material is already loaded
Dim loadedMaterial As NXOpen.Material = workPart.MaterialManager.PhysicalMaterials.GetLoadedLibraryMaterial(materialLibraryPath, materialName)
If loadedMaterial Is Nothing Then
' Material is not loaded, load it from the library
physicalMaterial1 = workPart.MaterialManager.PhysicalMaterials.LoadFromMatmlLibrary(materialLibraryPath, materialName)
materialLibraryLoaded = True
'lw.WriteLine("Material library loaded.")
Else
physicalMaterial1 = loadedMaterial
materialLibraryLoaded = True
'lw.WriteLine("Material already loaded.")
End If
Catch ex As Exception
'lw.WriteLine("Failed to check/load material library: " & ex.Message)
End Try

If SelectObjects("Hey, select multiple somethings", mySelectedObjects) = Selection.Response.Ok Then
For Each tempComp As Body In mySelectedObjects
Try
Dim pmaterialname as String = ("PhysicalMaterial[" & materialName & "]")
Dim physicalMaterial1 As NXOpen.PhysicalMaterial = CType(workPart.MaterialManager.PhysicalMaterials.FindObject(pmaterialname), NXOpen.PhysicalMaterial)
If physicalMaterial1 Is Nothing Then
lw.WriteLine("Error: Material " & materialName & " not found.")
Return
End If

If physicalMaterial1 IsNot Nothing Then
physicalMaterial1.AssignObjects(New NXOpen.NXObject() {tempComp})
'lw.WriteLine("Material " & materialName & " successfully assigned to body: " & tempComp.JournalIdentifier)
Else
lw.WriteLine("Error: Material " & materialName & " not found in the material library.")
End If
Catch ex As Exception
lw.WriteLine("Error processing body: " & tempComp.JournalIdentifier & " - " & ex.Message)
lw.WriteLine("Exception occurred: " & ex.ToString())
End Try
Next
theSession.UpdateManager.DoUpdate(markId1)
Else
lw.WriteLine("No objects were selected.")
End If

If physicalMaterialAssignBuilder1 IsNot Nothing Then
physicalMaterialAssignBuilder1.Destroy()
physicalMaterialAssignBuilder1 = Nothing
End If

If physicalMaterialListBuilder1 IsNot Nothing Then
physicalMaterialListBuilder1.Destroy()
physicalMaterialListBuilder1 = Nothing
End If
Catch ex As Exception
Console.WriteLine("Houston, we have a situation... an error occurred: " & ex.Message)
Finally
If physicalMaterial1 IsNot Nothing Then
physicalMaterial1 = Nothing
End If
End Try
End Sub

Function SelectObjects(prompt As String,
ByRef dispObj As List(Of DisplayableObject)) As Selection.Response
Dim selObj As NXObject()
Dim title As String = ("Select solid bodies - " & materialName)
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt,
title, scope, selAction,
includeFeatures, keepHighlighted, selectionMask_array,
selObj)

If resp = Selection.Response.ObjectSelected Or
resp = Selection.Response.ObjectSelectedByName Or
resp = Selection.Response.Ok Then
For Each item As NXObject In selObj
dispObj.Add(CType(item, DisplayableObject))
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module

Links:
Go to Part 2

Thanks for posting your code!

The material and raw body journal were initially scripted for use with meters. If you are operating in millimeters, please implement these adjustments to avoid disrupting the Measure Tool Units.
Material Journal:
Line 63 - change to this:
mb.InformationUnit = MeasureBodies.AnalysisUnit.KilogramMilliMeter
Line 68 - change to this:
Dim bodyWeight As Double = bodyVolume/1e+9 * density

Raw Body Journal
Line 63 - change to this:
mb.InformationUnit = MeasureBodies.AnalysisUnit.KilogramMilliMeter
Line 71 - change to this:
Dim scrib_weight As Double = origmat_density * (bodyVolume/1e+9) - orig_weight

The material and raw body journal were initially scripted for use with meters. If you are operating in lbm and inches, please implement these adjustments.
Material Journal:

Line 27 - change to this:
Dim density As Double = 27.4683 ' Pound/Cubic Foot - Change this value if you need your own specific density

Line 49 - change to this:
attributePropertiesBuilder1.Units = "PoundMassPerCubicFoot"

Line 65 - change to this:
mb.InformationUnit = MeasureBodies.AnalysisUnit.PoundInch

Line 69 - change to this:
Dim bodyWeight As Double = bodyVolume/1728 * density

Line 76 - change to this:
attributePropertiesBuilderForWeight.Units = "lbm"

Raw Body Journal

Line 63 - change to this:
mb.InformationUnit = MeasureBodies.AnalysisUnit.PoundInch

Line 71 - change to this:
Dim scrib_weight As Double = origmat_density * (bodyVolume/1728) - orig_weight

Line 81 - change to this:
attributePropertiesBuilderForWeight.Units = "lbm"