Report Weld Points

In a recent forum thread, the topic of weld points came up; those working with the weld points were looking for an easy way to highlight and differentiate the different weld point types. The journal code below performs the following actions:

  • Create a small colored sphere on each weld point; two-thickness welds will be colored green, three-thickness welds will be colored red.
  • A fixed datum axis is created according to the weld vector.
  • The sphere and datum axis features are renamed to match the weld point ID.
  • The weld point ID, location, weld vector, and number of sheets welded are all output to the information window.


The Code

The code was tested with NX 8.5.




'NXJournaling.com
'report_weld_point_location
'September 17, 2014
'NX 8.5
'
'Create small spheres on weld points: green for two-thickness welds, red for three thickness welds.
'Create a fixed datum axis to visualize the weld vector.
'Report weld points to the information window.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module3

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work

Sub Main()

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

Const undoMarkName As String = "weld point spheres"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim sphereDia As Double
If workPart.PartUnits = BasePart.Units.Millimeters Then
sphereDia = 5
Else
sphereDia = 0.25
End If

Dim theAttributeInfo As NXObject.AttributeInformation
Dim numSheets As Integer
Dim strWeldIVal As String
Dim strWeldJVal As String
Dim strWeldKVal As String
Dim weldIVal As Double
Dim weldJVal As Double
Dim weldKVal As Double
Dim weldID As String

For Each myPt As Point In workPart.Points

Try
theAttributeInfo = myPt.GetUserAttribute("ID", NXObject.AttributeType.String, -1)
weldID = theAttributeInfo.StringValue
'lw.WriteLine("weldID: " & weldIVal.ToString)
Catch ex As NXException
lw.WriteLine("NX exception: " & ex.Message)
Continue For
Catch ex As Exception
lw.WriteLine("exception: " & ex.Message)
Continue For
End Try

Try
theAttributeInfo = myPt.GetUserAttribute("NUMBER OF SHEETS WELDED", NXObject.AttributeType.Integer, -1)
numSheets = theAttributeInfo.IntegerValue
Dim sphereColor As Integer = 103
Select Case numSheets
Case 2
'default cdf green = 36
sphereColor = 36
Case 3
'default cdf red = 186
sphereColor = 186
Case Else
sphereColor = 103
End Select
CreateSphereOnPoint(myPt, sphereDia, sphereColor, weldID)

Catch ex As NXException
Continue For
End Try

Try
theAttributeInfo = myPt.GetUserAttribute("WELD_I_VALUE", NXObject.AttributeType.String, -1)
strWeldIVal = theAttributeInfo.StringValue
weldIVal = Double.Parse(strWeldIVal)
Catch ex As NXException
lw.WriteLine("NX exception: " & ex.Message)
Continue For
Catch ex As Exception
lw.WriteLine("exception: " & ex.Message)
Continue For
End Try

Try
theAttributeInfo = myPt.GetUserAttribute("WELD_J_VALUE", NXObject.AttributeType.String, -1)
strWeldJVal = theAttributeInfo.StringValue
weldJVal = Double.Parse(strWeldJVal)
Catch ex As NXException
lw.WriteLine("NX exception: " & ex.Message)
Continue For
Catch ex As Exception
lw.WriteLine("exception: " & ex.Message)
Continue For
End Try

Try
theAttributeInfo = myPt.GetUserAttribute("WELD_K_VALUE", NXObject.AttributeType.String, -1)
strWeldKVal = theAttributeInfo.StringValue
weldKVal = Double.Parse(strWeldKVal)
Catch ex As NXException
lw.WriteLine("NX exception: " & ex.Message)
Continue For
Catch ex As Exception
lw.WriteLine("exception: " & ex.Message)
Continue For
End Try

Dim origin1 As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim vector1 As Vector3d = New Vector3d(weldIVal, weldJVal, weldKVal)
Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(origin1, vector1, SmartObject.UpdateOption.WithinModeling)

CreateWeldAxis(myPt, direction1, weldID)

lw.WriteLine("ID: " & weldID)
lw.WriteLine("location: " & myPt.Coordinates.ToString)
lw.WriteLine("weld vector: " & direction1.Vector.ToString)
lw.WriteLine("number of sheets: " & numSheets.ToString)
lw.WriteLine("")

Next

lw.Close()

End Sub

Sub CreateSphereOnPoint(ByVal cenPoint As Point, _
ByVal diameter As Double, _
ByVal color As Integer, _
ByVal name As String)

Dim theColor As Integer
If color < 0 Or color > 216 Then
theColor = 103
Else
theColor = color
End If

Dim nullFeatures_Sphere As Features.Sphere = Nothing

Dim sphereBuilder1 As Features.SphereBuilder
sphereBuilder1 = workPart.Features.CreateSphereBuilder(nullFeatures_Sphere)

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

Try
sphereBuilder1.Diameter.RightHandSide = diameter.ToString
sphereBuilder1.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
sphereBuilder1.CenterPoint = cenPoint

Dim theSphere As Features.Sphere
theSphere = sphereBuilder1.Commit()
theSphere.SetName(name)

displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = False
displayModification1.NewColor = theColor

Dim objects1(0) As DisplayableObject
Dim body1 As Body = theSphere.GetBodies(0)

objects1(0) = body1
displayModification1.Apply(objects1)

Catch ex As NXException

Finally
sphereBuilder1.Destroy()
displayModification1.Dispose()

End Try

End Sub

Sub CreateWeldAxis(ByVal thePoint As Point, _
ByVal theDirection As Direction, _
ByVal theName As String)

Dim nullFeatures_Feature As Features.Feature = Nothing

Dim datumAxisBuilder1 As Features.DatumAxisBuilder
datumAxisBuilder1 = workPart.Features.CreateDatumAxisBuilder(nullFeatures_Feature)

datumAxisBuilder1.Type = Features.DatumAxisBuilder.Types.PointAndDir

datumAxisBuilder1.Point = thePoint

datumAxisBuilder1.Vector = theDirection

datumAxisBuilder1.IsAssociative = False

Dim weldAxis As Features.DatumAxisFeature
weldAxis = datumAxisBuilder1.CommitFeature()

datumAxisBuilder1.Destroy()

weldAxis.SetName(theName)

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

'----Other unload options-------
'Unloads the image immediately after execution within NX
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------

End Function

End Module