青华模具培训学校

 找回密码
 注册

QQ登录

只需一步,快速开始

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

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

[复制链接]
发表于 2020-10-10 09:48 | 显示全部楼层 |阅读模式
  N( F2 I# {5 \
Option Strict Off1 Y  j. T9 N( L. E% a3 p
Imports System
  _* C+ E! U5 }# F4 ]& i% a5 ZImports System.IO$ ?! B$ [3 A5 c5 C% N0 ]7 f
Imports System.Windows.Forms) I! y* Y" b% e" u
Imports NXOpen7 H: F- n/ L: X
Imports NXOpen.UF( y- z8 Q, M; A. N$ A3 P
Imports NXOpen.Utilities: q4 G- n+ \5 v- m# o7 ^* R( g
  D0 H6 \/ a5 h" i4 W7 @
Module TestRenameCamObjects
8 J- i  i- U4 W3 o0 n: s4 t8 d( h/ I    Dim theSession    As Session   = Session.GetSession()
8 n; Z2 X( L' X9 `0 k* t0 T: U! Q    Dim theUFSession  As UFSession = UFSession.GetUFSession()) `. Y2 E  p9 [( k7 W/ F9 K' g% U0 N
    Dim theUI         As UI        = UI.GetUI()' o; d  k6 T! D$ E: x7 i
    Dim TempPath      As String    = Environment.GetEnvironmentVariable("TMP")( b( g; c. _  Q) b
    Dim ugRelease     As String    = Nothing
0 S6 i( g# {0 Z6 S/ P2 a8 f    Dim UGFullRelease As String    = Nothing$ g# J! d; v+ K# W
    . Z1 J6 A( Z$ @; l* H
    Sub Main(Args As String())& F4 {1 V. L' a5 |
        theSession.LogFile.WriteLine("Executing ... " & _
3 S+ C" N' V' A; N! G: ]            System.Reflection.Assembly.GetExecutingAssembly().Location)
9 k3 B/ [$ x* W8 ~1 b" V        1 b' c% E5 [% z  o5 R4 f
        Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")
- ^6 S! a* _, j2 }$ U        Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-US")) c% j) K; t. [1 `
        
5 E6 P/ U: ^6 o% g5 Y  H        UGRelease = theSession.GetEnvironmentVariableValue("UGII_VERSION")' N' n6 k% K' _3 m9 T7 v/ o
        UGFullRelease = theSession.GetEnvironmentVariableValue("UGII_FULL_VERSION")
: J% n7 _* l8 \* s% B, b        5 \+ j0 T& h7 y3 t! d. O4 u
        System.Windows.Forms.Application.EnableVisualStyles()* K; S0 T2 {' \  u8 E: y# Q. K  v
        & b: b, t/ s$ R2 Z' w
        Dim MyUndoMark As Session.UndoMarkId = _
' j% H. |" M3 \5 {. b5 m            theSession.SetUndoMark(Session.MarkVisibility.Visible, "TestRenameCamObjects")
/ b5 H7 ^8 \7 c# f* k! X% f2 L        " k2 i/ F; b3 n# u6 _
        ' uncomment the following lines to check for the correct application4 [' _( L7 z# j& \& L  W' q
        Dim AppID As Integer = UFConstants.UF_APP_NONE% U% P+ }' e& r4 L$ d& j
        theUFSession.UF.AskApplicationModule(AppID)
: `+ I, o7 E, B        If AppID <> UFConstants.UF_APP_CAM Then) @8 q5 a2 \: t% t7 x/ a$ H
            theUI.NXMessageBox.Show("Application missmatch", NXMessageBox.DialogType.Error, "No NX CAM session, Exiting!")
2 U" G) J: J6 J3 H2 Y            Exit Sub
0 T! _; R9 _1 K& C9 K& k        End If
  |' i; Q! W- Y$ C        1 `# u1 Z2 z; j( G8 M
        For i As Integer = 0 To theUI.SelectionManager.GetNumSelectedObjects() - 1' x% A8 |  F7 T. s7 ?' A( h' {$ B
            Dim theSelectedObject As TaggedObject = theUI.SelectionManager.GetSelectedTaggedObject(i)
" ^4 h; u( F0 k# U: F. b5 S! r- [            
2 e8 |- S3 g; I            If theSession.Parts.Work.CAMSetup.IsGroup(theSelectedObject) Then. V- s) d0 b& j
                Dim thePartName As String = IO.Path.GetFileNameWithoutExtension(theSession.Parts.Work.FullPath)
; o* G3 t+ _4 G" T2 K( Q7 U+ c               
) D' v5 D/ W( N, M, F+ k                Dim theIndex As String = NXOpenUI.NXInputBox.GetInputString("Enter Index")
. v0 c& s1 Y) Z                * J% W5 F: h5 N, |1 B' Z' S
                Dim theGroupName As String = Left(thePartName, 12).Replace("-", "_") &&#160;"_"&#160;& theIndex &&#160;"_"&#160;& Right(thePartName, 4)
, u- `6 U5 f' _               
0 O, q+ I! t7 M5 Y7 \                Dim theNcGroup As CAM.NCGroup = CType(theSelectedObject, CAM.NCGroup)
, D7 ]! A& d. w& q- l               
7 Y% `' L& A4 e2 b2 g" F. e. l+ b                theNcGroup.SetName(theGroupName)
$ z( O1 |6 A# e4 G: w                & m( T# ?* c  m7 M
                Dim theCounter As Integer = 0
( @) \5 X0 s5 U' d* i               
* W8 O: X( h- }! k7 r: i  e1 C: S                For Each theCAMObject As CAM.CAMObject In theNcGroup.GetMembers()& m% S$ L& `  n* f, z
                    If theSession.Parts.Work.CAMSetup.IsOperation(theCAMObject) Then
* H. b  F2 Y0 Y                        theCAMObject.SetName(theCounter.ToString("00") & "_" & theCAMObject.Name)
- m2 b6 \+ }: W                        2 b/ k/ l. h8 h
                        theCounter += 1
" t7 k; {4 N% m! g& h                        7 t1 g, s3 H+ K) q3 A8 @) M
                        If theCounter > 99 Then Exit For  O2 [  h6 l5 ~) ?1 \0 p5 T# j
                    End If7 u6 L4 N8 l6 Q$ \# U3 \! d
                Next
' J0 Q/ _% M( u+ z* w! U* a            End If
/ V/ n5 f$ \7 U0 {1 x( X2 Q        Next; n8 w$ t1 P& y! _0 y  m
    End Sub
) `; ?2 G$ X, H- Q/ e    $ p* }: y# p; j0 y, |( ^% I& A! y
    Public Function GetUnloadOption(ByVal dummy As String) As Integer( T; B' P% n/ q1 {1 j
        Return CInt(Session.LibraryUnloadOption.Immediately)' o* p; K/ @* }- X
    End Function2 G7 Z8 A( N1 r; [8 b( {7 E8 c
End Module
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-9 20:50 , Processed in 0.135695 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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