UG12使用VB脚本批量输出后处理,如何获取程序组所有工序
我想用脚本在UG12中实现1、当选中程序组的时候执行脚本,将逐个输出程序组中的工序并按照工序名称前三个字符+刀具名称对输出的工序进行重命名
2、输出路径为E:\工作文件\Bln\Bln,输出时在该文件夹内建立以选中程序组名称的子文件夹,并将程序组内工序逐个输出至该子文件夹
3、后处理器为YIYI_360,${UGII_CAM_POST_DIR}YIYI_360.tcl,${UGII_CAM_POST_DIR}YIYI_360.def,后处理器所在文件夹为D:\Program Files\Siemens\NX 12.0\MACH\resource\postprocessor
已编写以下代码,但是执行以下.vb程序是报错,求助如何处理
通过网盘分享的文件:push0.vb 链接: push0.vb 提取码: 6pti
语法错误:
第 62 行:未定义类型“CAM.Operations”。
&MACRO MESSAGE_BOX-2Line 62: 未定义类型“CAM.Operations”。
&MACRO MESSAGE_TEXT
&MACRO MENU, 0, UG_HELP_SYSTEM_LOG UG_GATEWAY_MAIN_MENUBAR <RibbonFileBar->BackStageBar->LeftBackStageGroup->rbn_file_tab_help_cascade.csb> ## !
Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports System.Collections.Generic ' 添加此行以引用 List 类型
Module TestRenameCamObjects
Dim theSession As Session = Session.GetSession()
Dim theUFSessionAs UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI()
Dim TempPath As String = Environment.GetEnvironmentVariable("TMP")
Dim UGRelease As String = Nothing
Dim UGFullRelease As String = Nothing
Dim postProcessorPath As String = "D:\Program Files\Siemens\NX 12.0\MACH\resource\postprocessor\YIYI_360.tcl"
Dim postProcessorDefPath As String = "D:\Program Files\Siemens\NX 12.0\MACH\resource\postprocessor\YIYI_360.def"
Dim outputBasePath As String = "E:\工作文件\Bln\Bln"
Sub Main(Args As String())
theSession.LogFile.WriteLine("Executing ... " & _
System.Reflection.Assembly.GetExecutingAssembly().Location)
Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")
Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-US")
UGRelease = theSession.GetEnvironmentVariableValue("UGII_VERSION")
UGFullRelease = theSession.GetEnvironmentVariableValue("UGII_FULL_VERSION")
System.Windows.Forms.Application.EnableVisualStyles()
' 检查是否在CAM环境中
Dim AppID As Integer = UFConstants.UF_APP_NONE
theUFSession.UF.AskApplicationModule(AppID)
If AppID <> UFConstants.UF_APP_CAM Then
theUI.NXMessageBox.Show("Application mismatch", NXMessageBox.DialogType.Error, "No NX CAM session, Exiting!")
Exit Sub
End If
' 获取选中的程序组
Dim selectedGroups As List(Of TaggedObject) = New List(Of TaggedObject)()
For i As Integer = 0 To theUI.SelectionManager.GetNumSelectedObjects() - 1
Dim theSelectedObject As TaggedObject = theUI.SelectionManager.GetSelectedTaggedObject(i)
If theSession.Parts.Work.CAMSetup.IsGroup(theSelectedObject) Then
selectedGroups.Add(theSelectedObject)
End If
Next
' 对选中的程序组进行处理
For Each theSelectedObject As TaggedObject In selectedGroups
Dim theNcGroup As CAM.NCGroup = CType(theSelectedObject, CAM.NCGroup)
Dim groupName As String = theNcGroup.Name
Dim groupOutputPath As String = Path.Combine(outputBasePath, groupName)
' 创建子文件夹
If Not Directory.Exists(groupOutputPath) Then
Directory.CreateDirectory(groupOutputPath)
End If
' 获取程序组中的所有工序
Dim operations As CAM.Operations = theNcGroup.Operations
For Each operation As CAM.Operation In operations
Dim operationName As String = operation.Name
Dim toolName As String = operation.Tool.Name
Dim newOperationName As String = operationName.Substring(0, 3) & toolName
' 重命名工序
operation.SetName(newOperationName)
' 输出工序
Dim postBuilder As CAM.PostBuilder = theSession.Parts.Work.CAMSetup.PostBuilder
postBuilder.PostOperation(operation, postProcessorPath, postProcessorDefPath, groupOutputPath, False)
Next
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return CInt(Session.LibraryUnloadOption.Immediately)
End Function
End Module
Dim operations
For Each operation
62行多了个S,定义和循环的变量名都不一致
页:
[1]