Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UI
Module Module13
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUi As UI = UI.GetUI
Dim workPart As Part = theSession.Parts.Work
Dim rnd1 As New Random()
Dim max As Integer
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim myPoints As New List(Of Point)
If SelectPoints("Select points", myPoints) = Selection.Response.Cancel Then
Return
End If
MsgBox("number of points selected: " & myPoints.Count.ToString & ControlChars.NewLine & _
"That's not enough, let's add 100 more")
If workPart.PartUnits = Part.Units.Inches Then
max = 10
Else 'metric file
max = 250
End If
'create Point3d using the constructor
Dim myPt1 As New Point3d(0, 0, 0)
For i As Integer = 0 To 99
'change values of myPt1 using random numbers
myPt1.X = rnd1.Next(-max, max) + rnd1.NextDouble
myPt1.Y = rnd1.Next(-max, max) + rnd1.NextDouble
myPt1.Z = rnd1.Next(-max, max) + rnd1.NextDouble
Dim newPt As Point
newPt = workPart.Points.CreatePoint(myPt1)
newPt.SetVisibility(SmartObject.VisibilityOption.Visible)
myPoints.Add(newPt)
Next
For Each tempPt As Point In myPoints
tempPt.Highlight()
Next
workPart.Views.WorkView.UpdateDisplay()
MsgBox("The list, 'myPoints', now contains: " & myPoints.Count.ToString & " points")
For Each tempPt As Point In myPoints
tempPt.Unhighlight()
Next
'if you need the point objects in an array (some NXOpen API functions only accept an array),
'use myPoints.ToArray - this will return an array of the objects that are in the list
End Sub
Function SelectPoints(ByVal prompt As String, ByRef thePoints As List(Of Point)) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select points"
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 = NXOpen.UF.UFConstants.UF_point_type
.Subtype = NXOpen.UF.UFConstants.UF_all_subtype
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 tempObj As Point In selObj
thePoints.Add(tempObj)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module