'获取当前文件操作导航器内程序视图中的程序组和操作名的树型结构.
Public Sub GetOperationList()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lst As ListingWindow
Dim arrOpers() As NXOpen.CAM.Operation
Dim stOpers() As String
Dim i As Integer
Dim theUI As UI = UI.GetUI()
Dim CAM_GRP_COL As CAM.NCGroupCollection
Dim n As Integer
Dim nSpace As Integer
Dim nCouGroup As Integer
Dim nd As New System.Windows.Forms.TreeNode
lst = theSession.ListingWindow
lst.Open()
Try
arrOpers = workPart.CAMSetup.CAMOperationCollection.ToArray
ReDim stOpers(arrOpers.Length - 1)
For i = 0 To arrOpers.Length - 1
stOpers(i) = arrOpers(i).Name.ToString
Next
CAM_GRP_COL = workPart.CAMSetup.CAMGroupCollection
Dim stList(stOpers.Length + 100) As String '最多允许100个文件夹。
n = 0
nSpace = 8
nCouGroup = 0
Tree.Nodes.Clear()
nd.Name = "NC_PROGRAM" : nd.Text = "NC_PROGRAM"
Tree.Nodes.Add(nd)
SortOperNames(lst, CAM_GRP_COL, "NC_PROGRAM", stOpers, n, stList, nSpace, nCouGroup, nd)
Tree.ExpandAll()
Catch ex As Exception
lst.WriteLine(ex.Message)
End Try
End Sub
Private Sub SortOperNames(ByRef lst As ListingWindow, ByVal CAM_GRP_COL As CAM.NCGroupCollection, ByVal stName As String, ByRef stOpers() As String, _
ByRef nIndex As Integer, ByRef stList() As String, ByRef nSpace As Integer, ByRef nCouGroup As Integer, ByRef nd As System.Windows.Forms.TreeNode)
Dim nCGroup1 As CAM.NCGroup = CType(CAM_GRP_COL.FindObject(stName), CAM.NCGroup)
Dim arrGrps() As CAM.CAMObject
Dim i As Integer
Dim j As Integer
Dim NND As Windows.Forms.TreeNode
arrGrps = nCGroup1.GetMembers
For i = 0 To arrGrps.Length - 1
'lst.WriteLine("判断:" + arrGrps(i).Name.ToString)
For j = 0 To stOpers.Length - 1
If arrGrps(i).Name.ToString = stOpers(j) Then
Exit For
End If
Next
If j >= stOpers.Length Then
'lst.WriteLine("是文件夹")
NND = New Windows.Forms.TreeNode
NND.Name = arrGrps(i).Name.ToString : NND.Text = arrGrps(i).Name.ToString
nd.Nodes.Add(NND)
nd = NND
nCouGroup = nCouGroup + 1
stList(nIndex) = Space(nSpace) + arrGrps(i).Name.ToString + "*"
nIndex = nIndex + 1
nSpace = nSpace + 8
SortOperNames(lst, CAM_GRP_COL, arrGrps(i).Name.ToString, stOpers, nIndex, stList, nSpace, nCouGroup, nd)
Else
stList(nIndex) = Space(nSpace) + stOpers(j)
nIndex = nIndex + 1
'lst.WriteLine("是操作")
NND = nd.Nodes.Add(stOpers(j))
NND.Text = stOpers(j)
End If
Next
nSpace = nSpace - 8
nd = nd.Parent
End Sub