NX二次开发之程序组及操作重命名

本示例展示了如何使用 Visual Basic .NET 和 NXOpen API 在 Siemens NX CAM 环境中批量重命名组和操作对象。代码通过获取当前工作部件名称,并提示用户输入索引值来生成新的对象名称。
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值