|
|
这个问题我通过AI编程解决了,对我工作来说方便了一些,以下是代码,附件为文件
- Imports System.Collections.Generic
- Imports System
- Imports NXOpen
- Imports System.IO
- Module NXJournal
- Sub Main(ByVal args() As String)
- Dim theSession As Session = Session.GetSession()
- Dim workPart As Part = theSession.Parts.Work
- Dim theUI As UI = UI.GetUI()
- ' 获取选定对象
- ' 获取程序组和工序
- ' 获取选定程序组
- ' 获取选中的程序组
- Dim selectedGroups As New List(Of CAM.NCGroup)
- For i As Integer = 0 To theUI.SelectionManager.GetNumSelectedObjects() - 1
- Dim selectedObject = theUI.SelectionManager.GetSelectedTaggedObject(i)
- If TypeOf selectedObject Is CAM.NCGroup Then
- selectedGroups.Add(CType(selectedObject, CAM.NCGroup))
- End If
- Next
- ' 获取首个程序组及其工序
- If selectedGroups.Count = 0 Then
- theUI.NXMessageBox.Show("选择错误", NXMessageBox.DialogType.Error, "请至少选择一个程序组")
- Exit Sub
- End If
- Dim ncGroup As CAM.NCGroup = selectedGroups(0)
- ' 0=首道工序,1=第二道工序,2=第三道工序,3=第四道工序
- For i As Integer = 0 To 3
- Dim operation As CAM.Operation = CType(ncGroup.GetMembers().GetValue(i), CAM.Operation)
- ' 构造路径参数
- ' 获取加工参数
- ' 参数定义
- Dim programGroupName As String = ncGroup.Name
- Dim operationName As String = operation.Name
-
- ' 创建输出目录
- ' 创建输出路径
- Dim outputDir As String = String.Format("{0}{1}\", "E:\工作文件\Bln\Bln\", programGroupName)
- If Not IO.Directory.Exists(outputDir) Then
- IO.Directory.CreateDirectory(outputDir)
- End If
- ' 后处理设置
- workPart.CAMSetup.PostprocessWithPostModeSetting(
- {operation},
- "YIYI_360",
- String.Format("{0}{1}_{2}.nc", outputDir, programGroupName, operationName),
- CAM.CAMSetup.OutputUnits.PostDefined,
- CAM.CAMSetup.PostprocessSettingsOutputWarning.PostDefined,
- CAM.CAMSetup.PostprocessSettingsReviewTool.PostDefined,
- CAM.CAMSetup.PostprocessSettingsPostMode.Normal
- )
- Next
- End Sub
- End Module
复制代码
如程序组下有多个工序,可以修改第31行的内容,个数从0开始计数,5个工序就改为 To 4
可以通过百度网盘直接下载文件 push https://pan.baidu.com/s/16VlAJ4RG2-DvhDHcnIn0qQ?pwd=ugnx 提取码: ugnx |
|