青华模具培训学校

 找回密码
 注册

QQ登录

只需一步,快速开始

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

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

[复制链接]
发表于 2020-10-10 09:48 | 显示全部楼层 |阅读模式
( f6 B# j9 [$ t+ m
Option Strict Off
0 }6 P8 _; ^& t7 P* TImports System( ]% ^6 ~1 y& a. i# Q
Imports System.IO5 Y, E& p1 a! |" ?5 S; r
Imports System.Windows.Forms& F3 p( L+ P1 X9 c
Imports NXOpen
" Y9 E$ D- F( \2 }# g) uImports NXOpen.UF
% d& [( H0 x8 x1 _" dImports NXOpen.Utilities
* b' ?4 u5 V. u$ A6 V: m4 n
) W* o, ?# Y  N7 L- Q% m' V# ~& X# Z0 mModule TestRenameCamObjects, `" I' ^& T4 |+ ~
    Dim theSession    As Session   = Session.GetSession()
6 Z* a1 c: I) `) r* N    Dim theUFSession  As UFSession = UFSession.GetUFSession()2 c, O1 z4 c) C/ O+ V# ^, y8 T! p. |
    Dim theUI         As UI        = UI.GetUI()
7 G1 ~7 ]7 |) h- T7 |( T. N! U    Dim TempPath      As String    = Environment.GetEnvironmentVariable("TMP")( X7 e* x% ^. T  p  t0 ?4 u- Y6 y" |  [
    Dim ugRelease     As String    = Nothing, J7 a  i4 l$ v0 ~& s7 b0 r% F
    Dim UGFullRelease As String    = Nothing
2 |+ O) ^, }% n2 [, S! m% U2 N   
- W+ z$ j% m6 q3 y8 \8 N, f    Sub Main(Args As String()); }/ N( ~3 g2 }. g$ n, a
        theSession.LogFile.WriteLine("Executing ... " & _
1 w$ K" E0 `6 m" R            System.Reflection.Assembly.GetExecutingAssembly().Location)
" |) `* o" W9 {7 L7 U        . U% `( ^7 W/ D7 Y
        Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")1 J8 y; n9 z9 {' v
        Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-US")
: K: D5 q4 l0 V$ D, a        9 K6 k. Y7 B5 d% Z
        UGRelease = theSession.GetEnvironmentVariableValue("UGII_VERSION")/ ~+ i7 l0 y8 c6 ~/ R# J
        UGFullRelease = theSession.GetEnvironmentVariableValue("UGII_FULL_VERSION")% Y  `* k- Q! D3 M7 x
        7 o* H, S* ?" R+ G7 B- T
        System.Windows.Forms.Application.EnableVisualStyles()
8 ?# V/ @( N0 s8 U; J, z        . s- v/ A& T; v% j; X
        Dim MyUndoMark As Session.UndoMarkId = _
' l/ w1 v) H4 L( C) r; t            theSession.SetUndoMark(Session.MarkVisibility.Visible, "TestRenameCamObjects")
/ k- K5 ?. ]+ i        , ^3 l( I& t! X4 L  Y7 z) g, A
        ' uncomment the following lines to check for the correct application
3 l0 {/ X( G* r# S        Dim AppID As Integer = UFConstants.UF_APP_NONE
& Z4 F' @, `8 N2 e; S        theUFSession.UF.AskApplicationModule(AppID)
, ^5 G) [. Y/ Q9 l+ `        If AppID <> UFConstants.UF_APP_CAM Then- H* C& @/ V" w8 |6 W* ~$ b
            theUI.NXMessageBox.Show("Application missmatch", NXMessageBox.DialogType.Error, "No NX CAM session, Exiting!")
  y7 ~: i2 k: s2 T            Exit Sub& V. y9 \& Q+ v1 ^
        End If
9 f8 T: x' s' u% {& A        
  f2 W1 p- I6 |        For i As Integer = 0 To theUI.SelectionManager.GetNumSelectedObjects() - 1
! \6 J: F+ P2 Y4 P            Dim theSelectedObject As TaggedObject = theUI.SelectionManager.GetSelectedTaggedObject(i)8 |) l8 Z6 k  q* g' [
            
0 T  ^2 U# o) y6 h            If theSession.Parts.Work.CAMSetup.IsGroup(theSelectedObject) Then/ z# e! O5 l! Z% J& J6 r0 [
                Dim thePartName As String = IO.Path.GetFileNameWithoutExtension(theSession.Parts.Work.FullPath)% ]8 k% o" O0 s" I. {* F
               
. z; F' g( N1 X" i/ k. n2 [                Dim theIndex As String = NXOpenUI.NXInputBox.GetInputString("Enter Index")4 n7 n( Y- s6 v% ]
                ! R2 \4 ~6 @, u4 O1 m8 t
                Dim theGroupName As String = Left(thePartName, 12).Replace("-", "_") &&#160;"_"&#160;& theIndex &&#160;"_"&#160;& Right(thePartName, 4)
2 S! c# K' n5 h, D) C               
& x- q7 V$ q; U6 G. L9 B8 Z                Dim theNcGroup As CAM.NCGroup = CType(theSelectedObject, CAM.NCGroup)
, c1 c& n6 }7 l6 Y, @                & B* E2 z; R' Z% K/ f! g
                theNcGroup.SetName(theGroupName)
) j9 E- p7 S1 I0 m; F2 k                & {; M  f9 ]8 q) Z2 ?; o: I+ m
                Dim theCounter As Integer = 08 F6 T7 M. \7 Z# W) f
               
0 [8 t* ?! z0 k# P" n                For Each theCAMObject As CAM.CAMObject In theNcGroup.GetMembers()
1 I" D1 k7 K$ A3 }5 j# W4 b                    If theSession.Parts.Work.CAMSetup.IsOperation(theCAMObject) Then3 X3 |5 s5 A. N
                        theCAMObject.SetName(theCounter.ToString("00") & "_" & theCAMObject.Name)- |7 R3 ?; j  ]2 I" G
                        ; b& p' H8 i8 }; I! f3 r
                        theCounter += 1
8 t2 N6 ~7 X2 `+ w4 t                        
$ N- j; l, F2 I. J                        If theCounter > 99 Then Exit For
! `! ~2 v2 j5 B                    End If
# a+ [' C* k! v  }. B. l                Next
- q$ p; J* O2 M/ M5 o            End If
# T* `- [+ `/ I        Next
: Q4 p. S/ X0 m% o1 K( {    End Sub
5 B: h7 K# h2 n1 s+ `1 s" z! p   
: k- h' R  Q4 f+ f" U; ^2 H    Public Function GetUnloadOption(ByVal dummy As String) As Integer
& W1 y3 G" Z9 ~) l4 m        Return CInt(Session.LibraryUnloadOption.Immediately)
1 P  \" K8 H1 c    End Function
8 _- u/ x- ^9 ^: p  M# Q) }  W: ?End Module
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-10-11 14:27 , Processed in 0.048984 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

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