Creation Spheres

I am not able to write the following code:
• creating spheres starting from a point cloud;
• each ball with the same color of the dot;
• for each color, assign a text.
Can someone help me?

What version of NX are you on? Also, I'm not sure what you mean by "for each color, assign a text" - do you mean you want to add a note object?



Below is some code that works in NX 8.5. It is very basic, it just creates a sphere on every point in the file. I imagine that you'll want to add some code to limit it to certain points in the file (only those on a given layer, only those in point sets, etc).


Option Strict Off
Imports System
Imports NXOpen
 
Module Module1
 
    Dim theSession As Session = Session.GetSession()
    Dim workPart As Part = theSession.Parts.Work
 
    Sub Main()
 
        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If
 
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()
 
        Const undoMarkName As String = "sphere cloud"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
 
        For Each thePoint As Point In workPart.Points
 
            CreateSphereOnPoint(thePoint, 0.25)
 
        Next
 
        lw.Close()
 
    End Sub
 
    Sub CreateSphereOnPoint(ByVal cenPoint As Point, ByVal diameter As Double)
 
        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()
 
            displayModification1.ApplyToAllFaces = True
            displayModification1.ApplyToOwningParts = False
            displayModification1.NewColor = cenPoint.Color
 
            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
 
End Module

Hello,

I tried to use this journal, but my file is Weld Assistant... I would like to use the same idea but there is a different detail: all the points are green color and the difference is the symbol... I used this code and create sphere green color... Could you help me please?
In Advanced... Tks!

I don't quite understand your request.

Do you want to create something other than spheres?

Do you want spheres, just a different color?

Please explain your requirements.

I have a spot weld file, created in weld assistant. But this spots are in green color, all of them! The difference are the symbols (X or asterisk). I tried using the code above, but created green spheres. I would like to create red sphere for asterisk symbol and green symbol for X symbol. In each spot weld I know has a attributes called NUMBER OF SHEETS WELDED.

When the attribute NUMBER OF SHEETS WELDED = 2 green sphere
When the attribute NUMBER OF SHEETS WELDED = 3 red sphere

Do you understand me?

I believe what the poster is referring to is the weld assistant module has different point symbols. example a 2t(2 thickness weld) is a point symbol with 2 intersecting lines and a 3t(3 thickness weld) is a point symbol with 3 intersecting lines.

I don't have the Weld Assistant license, but I do get a lot of files in that have these types of points.
I too manually create different color 5mm dia spheres for each weld type on these points. This can be time consuming on larger assemblies.

I've never used the weld assistant and it appears that I don't have a license available to start any time soon. Could one of you email me a small sample file with a few different weld type points in it?

info@nxjournaling.com

Thanks!

I've sent a file.
The 'N' represents a weld nut, The 'S' a weld stud, the point a 2t weld, the asterisk a 3t weld.

I sent you by email!

Tks!

Thanks to both of you for the example files. The code below will place a green sphere (color 36 in the default cdf) on a '2 sheet' weld point and a red point (color 186 in the default cdf) on a '3 sheet' weld point.


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
 
Module Module2
 
    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
 
        For Each myPt As Point In workPart.Points
            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)
 
            Catch ex As NXException
                Continue For
            End Try
        Next
 
        lw.Close()
 
 
    End Sub
 
    Sub CreateSphereOnPoint(ByVal cenPoint As Point, ByVal diameter As Double, ByVal color As Integer)
 
        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()
 
            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
 
End Module

Tks for you help!

Works awesome, could potentially save hours of work.

Update to the code above; this version creates a datum axis indicating the weld vector (fixed datum axis). The datum axis and sphere features are named to match the weld point ID. And finally - the weld ID, location, weld vector, and number of sheets welded are reported to the information window.




'report_weld_point_location
 
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