青华模具培训学校

 找回密码
 注册

QQ登录

只需一步,快速开始

青华模具培训学院
查看: 718|回复: 0

[转载] NX二次开发之程序组及操作重命名

[复制链接]
发表于 2020-10-10 09:48 | 显示全部楼层 |阅读模式

9 V8 }" S+ N: T0 [& ?, o0 oOption Strict Off
/ v) j1 D! a9 N2 _/ x  l1 OImports System
0 r' `6 Z- F2 ~7 W1 F3 `. g( WImports System.IO% V9 n1 \9 n( A
Imports System.Windows.Forms: W7 y/ k- U; B: d
Imports NXOpen
$ ?9 @0 P: b) Q) h+ gImports NXOpen.UF
6 k( ^* i% t" M) eImports NXOpen.Utilities. I: F4 D1 t* Q9 J  N
9 s+ G5 Q# O: k/ C
Module TestRenameCamObjects
) |# W# R$ `& l' ^; i+ N% I    Dim theSession    As Session   = Session.GetSession()2 {5 |( R0 n( K$ Q
    Dim theUFSession  As UFSession = UFSession.GetUFSession()7 o! [; E& ^' d5 b
    Dim theUI         As UI        = UI.GetUI()+ c0 q5 Z, v0 h# V
    Dim TempPath      As String    = Environment.GetEnvironmentVariable("TMP")$ f) P4 X! {" U
    Dim ugRelease     As String    = Nothing
& M+ a$ ~( h$ h    Dim UGFullRelease As String    = Nothing
. M. A7 Y$ U6 m9 N4 A* [    ) H) t6 ?/ n! e( r+ U
    Sub Main(Args As String())+ u& q7 i2 [# ^: l" }: C" @" s: g
        theSession.LogFile.WriteLine("Executing ... " & _
0 t5 K/ W; E1 t. d* P            System.Reflection.Assembly.GetExecutingAssembly().Location)
  |& W9 U: U* q( v/ Z& ?        $ a0 n; p  e3 y+ g
        Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")3 p7 n; E, X8 U) o! ?' o
        Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-US")
# E; V0 ]* W3 K% G        
, d0 I2 W) P& t% ~; b, ^$ K9 b        UGRelease = theSession.GetEnvironmentVariableValue("UGII_VERSION"); i7 U; p. }8 W+ ~; B, V- F6 O( v
        UGFullRelease = theSession.GetEnvironmentVariableValue("UGII_FULL_VERSION")
: J3 a6 e8 [& F/ N        , T0 F: u+ W. v5 z6 v
        System.Windows.Forms.Application.EnableVisualStyles()
; B+ M+ H1 V* ]        % e9 F* n7 V2 f. }7 q5 }0 r
        Dim MyUndoMark As Session.UndoMarkId = _
8 w# M" z* V( _* ]) A" l. a            theSession.SetUndoMark(Session.MarkVisibility.Visible, "TestRenameCamObjects")
7 H! ], e0 f) T( }# o2 K        
9 w- w  n$ t  `" H8 M; W+ B6 a        ' uncomment the following lines to check for the correct application/ Z) @* C5 T, q- \' R
        Dim AppID As Integer = UFConstants.UF_APP_NONE  ]' ^0 }8 S6 ]% f6 D, ]1 G( Q2 B
        theUFSession.UF.AskApplicationModule(AppID)
8 k8 w; o# c  y! I+ P  n1 [        If AppID <> UFConstants.UF_APP_CAM Then- V2 J. \5 I3 M2 h  M2 v
            theUI.NXMessageBox.Show("Application missmatch", NXMessageBox.DialogType.Error, "No NX CAM session, Exiting!")
1 h: U( u. J' Y9 U. U8 _- f! x            Exit Sub
8 G/ c. A  z/ r6 ^        End If
) s. m1 N$ _1 {  k9 o# |        / [, f$ W  k8 l9 n' l( j
        For i As Integer = 0 To theUI.SelectionManager.GetNumSelectedObjects() - 1, s, E3 n1 R- P/ _+ h+ M
            Dim theSelectedObject As TaggedObject = theUI.SelectionManager.GetSelectedTaggedObject(i)
4 s) [% N- s: b8 n* \* Q( O            # f# `5 O8 D" W$ h$ o1 I
            If theSession.Parts.Work.CAMSetup.IsGroup(theSelectedObject) Then0 U1 F; U! y% L! B9 y. ?: b
                Dim thePartName As String = IO.Path.GetFileNameWithoutExtension(theSession.Parts.Work.FullPath)
/ X7 H4 @. \; E; i4 S9 }                ) U' N( p9 F4 {0 w9 f, S. g
                Dim theIndex As String = NXOpenUI.NXInputBox.GetInputString("Enter Index")
# Q! G6 o: i" _               
9 j% O, o, C' G6 J- j: q+ Z. G                Dim theGroupName As String = Left(thePartName, 12).Replace("-", "_") &&#160;"_"&#160;& theIndex &&#160;"_"&#160;& Right(thePartName, 4)
. j3 A7 B; t" v$ @  ^# G6 u$ O               
2 d4 @7 V" m% e8 w                Dim theNcGroup As CAM.NCGroup = CType(theSelectedObject, CAM.NCGroup)
0 E& R0 N' K/ l; J* p               
* Y2 V5 s5 S4 G0 j" v) m6 g                theNcGroup.SetName(theGroupName)
; l7 ?% _; F3 x* B, e                $ E4 `( m; {, C* _8 t
                Dim theCounter As Integer = 0
' \0 v- l& L6 e( t. s7 d2 s+ T                6 t$ J, l9 m0 r% x! |1 o$ l( I% M
                For Each theCAMObject As CAM.CAMObject In theNcGroup.GetMembers()0 K' F$ n0 h. X' X
                    If theSession.Parts.Work.CAMSetup.IsOperation(theCAMObject) Then) b5 S5 w* L, B/ i; U
                        theCAMObject.SetName(theCounter.ToString("00") & "_" & theCAMObject.Name)+ C7 }% i. }  S4 j( _
                        
' ~9 P0 m! M% U                        theCounter += 17 D# X8 k" P' i
                        3 K8 [1 F; n$ p! J) H# L
                        If theCounter > 99 Then Exit For
, S  l/ ?" B, h- g3 B3 y3 `. W$ y                    End If
) u$ ^0 z" r5 H$ f0 w( D                Next
/ l2 P' J+ X% T4 S            End If; M) k* o! a8 L4 b) }( t- ~
        Next* F) }8 c2 v, l- M, L8 J
    End Sub: e. s9 G$ |( r9 i
   
2 e# N7 s+ g; m. p  j$ B. i    Public Function GetUnloadOption(ByVal dummy As String) As Integer; f" H; L' j0 X8 l
        Return CInt(Session.LibraryUnloadOption.Immediately)
1 B5 ^2 c$ k/ d2 A( I6 ]7 {- i9 Q    End Function& ], e. U: J3 ^" F; F
End Module
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|关于我们|sitemap|小黑屋|Archiver|手机版|UG网-UG技术论坛-青华数控模具培训学校 ( 粤ICP备15108561号 )

GMT+8, 2024-6-26 19:48 , Processed in 0.050879 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表