Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Module TestRenameCamObjects
Dim theSession As Session = Session.GetSession()
Dim theUFSession As 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
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()
Dim MyUndoMark As Session.UndoMarkId = _
theSession.SetUndoMark(Session.MarkVisibility.Visible, "TestRenameCamObjects")
' uncomment the following lines to check for the correct application
Dim AppID As Integer = UFConstants.UF_APP_NONE
theUFSession.UF.AskApplicationModule(AppID)
If AppID <> UFConstants.UF_APP_CAM Then
theUI.NXMessageBox.Show("Application missmatch", NXMessageBox.DialogType.Error, "No NX CAM session, Exiting!")
Exit Sub
End If
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
Dim thePartName As String = IO.Path.GetFileNameWithoutExtension(theSession.Parts.Work.FullPath)
Dim theIndex As String = NXOpenUI.NXInputBox.GetInputString("Enter Index")
Dim theGroupName As String = Left(thePartName, 12).Replace("-", "_") & "_" & theIndex & "_" & Right(thePartName, 4)
Dim theNcGroup As CAM.NCGroup = CType(theSelectedObject, CAM.NCGroup)
theNcGroup.SetName(theGroupName)
Dim theCounter As Integer = 0
For Each theCAMObject As CAM.CAMObject In theNcGroup.GetMembers()
If theSession.Parts.Work.CAMSetup.IsOperation(theCAMObject) Then
theCAMObject.SetName(theCounter.ToString("00") & "_" & theCAMObject.Name)
theCounter += 1
If theCounter > 99 Then Exit For
End If
Next
End If
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return CInt(Session.LibraryUnloadOption.Immediately)
End Function
End Module
NX二次开发之程序组及操作重命名
最新推荐文章于 2026-03-20 00:29:59 发布
本示例展示了如何使用 Visual Basic .NET 和 NXOpen API 在 Siemens NX CAM 环境中批量重命名组和操作对象。代码通过获取当前工作部件名称,并提示用户输入索引值来生成新的对象名称。

5979

被折叠的 条评论
为什么被折叠?



