第八个例子:怎样用VB.NET在UG中选择曲线和边?
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Module select_curves_or_edges
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Sub Main()
Dim curves() As NXOpen.Tag
Dim num_curves As Integer
Dim n As String = vbCrLf
num_curves = select_curves_or_edges("Select Curves or Edges:", curves)
If (num_curves) > 0 Then
ufs.Ui.OpenListingWindow()
ufs.Ui.WriteListingWindow("Selected count: " & num_curves.ToString & n)
End If
End Sub
Function select_curves_or_edges(ByVal prompt As String, _
ByRef curves() As NXOpen.Tag) As Integer
Dim cnt As Integer = 0
Dim response As Integer
Dim inx As Integer = 0
Dim mask_crvs As UFUi.SelInitFnT = AddressOf mask_for_curves
ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Try
ufs.Ui.SelectWithClassDialog(prompt, "Curves:", _
UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, _
mask_crvs, Nothing, response, cnt, curves)
Finally
ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
End Try
For inx = 0 To curves.Length - 1
ufs.Disp.SetHighlight(curves(inx), 0)
Next
Return cnt
End Function
Function mask_for_curves(ByVal select_ As IntPtr, _
ByVal userdata As IntPtr) As Integer
Dim num_triples As Integer = 6
Dim mask_triples(5) As UFUi.Mask
mask_triples(0).object_type = UFConstants.UF_line_type
mask_triples(0).object_subtype = 0
mask_triples(0).solid_type = 0
mask_triples(1).object_type = UFConstants.UF_circle_type
mask_triples(1).object_subtype = 0
mask_triples(1).solid_type = 0
mask_triples(2).object_type = UFConstants.UF_conic_type
mask_triples(2).object_subtype = 0
mask_triples(2).solid_type = 0
mask_triples(3).object_type = UFConstants.UF_spline_type
mask_triples(3).object_subtype = 0
mask_triples(3).solid_type = 0
mask_triples(4).object_type = UFConstants.UF_point_type
mask_triples(4).object_subtype = 0
mask_triples(4).solid_type = 0
mask_triples(5).object_type = UFConstants.UF_solid_type
mask_triples(5).object_subtype = 0
mask_triples(5).solid_type = UFConstants.UF_UI_SEL_FEATURE_ANY_EDGE
ufs.Ui.SetSelMask(select_, _
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
num_triples, mask_triples)
Return UFConstants.UF_UI_SEL_SUCCESS
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module |