Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module3
Private theSession As NXOpen.Session = NXOpen.Session.GetSession()
Private theUfSession As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "change body density")
lw.Open()
Dim theBody As Body = Nothing
If SelectBody("Select a body", theBody) = Selection.Response.Cancel Then
'selection cancelled, exit journal
Return
End If
If theBody.IsOccurrence Then
lw.WriteLine("body is occurrence")
Dim partLoadStatus1 As NXOpen.PartLoadStatus
theSession.Parts.SetWorkComponent(theBody.OwningComponent, NXOpen.PartCollection.RefsetOption.Current, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)
theBody = theBody.Prototype
Else
lw.WriteLine("body is prototype")
End If
If theBody.HasUserAttribute("NX_Material", NXObject.AttributeType.String, -1) Then
If String.IsNullOrEmpty(theBody.GetUserAttributeAsString("NX_Material", NXObject.AttributeType.String, -1)) Then
lw.WriteLine("no material assigned")
Else
lw.WriteLine("Material: " & theBody.GetUserAttributeAsString("NX_Material", NXObject.AttributeType.String, -1))
End If
End If
Dim bodyDensity As Double
theUfSession.Modl.AskBodyDensity(theBody.Tag, UFModl.DensityUnits.KilogramsMeters, bodyDensity)
lw.WriteLine("original body density: " & bodyDensity.ToString & " kg/m^3")
theUfSession.Modl.SetBodyDensity(theBody.Tag, UFModl.DensityUnits.KilogramsMeters, 1.0)
theUfSession.Modl.AskBodyDensity(theBody.Tag, UFModl.DensityUnits.KilogramsMeters, bodyDensity)
lw.WriteLine("new body density: " & bodyDensity.ToString & " kg/m^3")
lw.Close()
End Sub
Function SelectBody(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a body"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
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.SelectTaggedObject(prompt,
title, scope, selAction,
includeFeatures, keepHighlighted, selectionMask_array,
selObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module