|
马上注册,结交更多同行朋友,交流,分享,学习。
您需要 登录 才可以下载或查看,没有帐号?注册
x
小弟刚刚搞了个程序,请各位多多指教.(实属 抛砖引玉)!
'获取当前文件操作导航器内程序视图中的程序组和操作名的树型结构.
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
可惜运行效果图无法上传.
相册使用需要添加两位好友.
小弟初来乍到.不知哪位高手可帮忙. |
|