青华模具培训学校

 找回密码
 注册

QQ登录

只需一步,快速开始

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

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

[复制链接]
发表于 2020-10-10 09:48 | 显示全部楼层 |阅读模式
5 E6 [9 ^  q; [7 V
Option Strict Off
$ k9 a$ j7 D2 Y0 J6 S2 [5 AImports System& [% s0 t- A% M( \
Imports System.IO
$ \5 |- I# u. f- TImports System.Windows.Forms
1 P0 p4 O1 y1 Z0 Q) f$ IImports NXOpen
9 B( i6 y7 ]4 `* a; fImports NXOpen.UF
$ d' y% {4 q% n8 O4 i/ r6 dImports NXOpen.Utilities1 ~# g. d2 [: {$ T
4 O5 D. h! l2 G1 j8 J9 q" h
Module TestRenameCamObjects: l" ~, v0 c+ L, c5 v4 R
    Dim theSession    As Session   = Session.GetSession()
$ `4 G) N* u; q# s4 A# K5 r    Dim theUFSession  As UFSession = UFSession.GetUFSession()# N  J* t9 q: N
    Dim theUI         As UI        = UI.GetUI()1 ?2 N' d7 _  w4 N5 ~
    Dim TempPath      As String    = Environment.GetEnvironmentVariable("TMP")
  |- \& Z$ V/ c7 X+ ~    Dim ugRelease     As String    = Nothing
( [$ X( u. |9 C0 U$ i" ?; l3 I# i    Dim UGFullRelease As String    = Nothing
/ i% P, O  {$ ^/ E7 i" Z   
; l2 ?! f( U/ c9 E% c1 t# w) D    Sub Main(Args As String())& C, @1 G% G0 Q5 |" E  x% [! h
        theSession.LogFile.WriteLine("Executing ... " & _
# P( L$ Q1 M5 M            System.Reflection.Assembly.GetExecutingAssembly().Location)
4 J4 f- i$ d* H+ P! s        ' G# U; t9 z' {: D) P6 _6 |
        Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")8 f) [4 c4 I4 w- M
        Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-US")
/ o6 h6 y4 w" }+ v        
& Y2 E0 J$ W- D+ z8 L, F8 a3 R        UGRelease = theSession.GetEnvironmentVariableValue("UGII_VERSION")
) G6 g' X( o6 m7 y' i        UGFullRelease = theSession.GetEnvironmentVariableValue("UGII_FULL_VERSION")# q0 |* Z+ L" E
        
1 I  Z/ a% P8 y        System.Windows.Forms.Application.EnableVisualStyles()
- m6 T' ?9 _$ \6 G  `3 N( @        7 `& ^9 ]9 M' `8 X& e
        Dim MyUndoMark As Session.UndoMarkId = _3 J0 I5 D# V) Z. |# J( {
            theSession.SetUndoMark(Session.MarkVisibility.Visible, "TestRenameCamObjects")0 k! k6 A' J) k: S, L+ l
        ) l- C9 ]1 ^. f. G6 I: s% S0 S% P
        ' uncomment the following lines to check for the correct application
1 j- z  n- h% t) C        Dim AppID As Integer = UFConstants.UF_APP_NONE
: M' b, V/ O8 @+ V  H1 n  K. k        theUFSession.UF.AskApplicationModule(AppID)
' v2 M8 n& q4 e$ r# Q7 m        If AppID <> UFConstants.UF_APP_CAM Then
. b( M( e  h, _4 b: p: t            theUI.NXMessageBox.Show("Application missmatch", NXMessageBox.DialogType.Error, "No NX CAM session, Exiting!")7 m1 b* O  t$ ^9 K" j/ y( u
            Exit Sub4 C1 M; X  V9 h4 L" j; \7 L
        End If
' s$ k2 g& @! j* A0 a$ G        8 p$ I) ~) m; _3 U0 ]
        For i As Integer = 0 To theUI.SelectionManager.GetNumSelectedObjects() - 12 I8 q* w/ L; v# d+ Z! ]
            Dim theSelectedObject As TaggedObject = theUI.SelectionManager.GetSelectedTaggedObject(i)9 Y; [! d/ }% N' L' r  S
            
0 Z2 x2 o( `# H            If theSession.Parts.Work.CAMSetup.IsGroup(theSelectedObject) Then& ~" P' @: C7 ~& K9 V% I% p! a
                Dim thePartName As String = IO.Path.GetFileNameWithoutExtension(theSession.Parts.Work.FullPath), z! n6 F; q( W) n+ }( G8 K
               
  @/ O% K1 U9 Z8 O                Dim theIndex As String = NXOpenUI.NXInputBox.GetInputString("Enter Index")9 L! x7 q9 w% q' s) ?
               
& q/ w: U7 F4 V. O# |% ]- m                Dim theGroupName As String = Left(thePartName, 12).Replace("-", "_") &&#160;"_"&#160;& theIndex &&#160;"_"&#160;& Right(thePartName, 4)
( m, {1 {6 A! }- R/ f6 D                + e9 D1 }8 P4 \2 K
                Dim theNcGroup As CAM.NCGroup = CType(theSelectedObject, CAM.NCGroup)/ R' b2 w* k8 M% D
                % e1 T5 D# \) d) P6 p
                theNcGroup.SetName(theGroupName)
7 H9 Q9 a) J& n+ U" d                ) E9 w7 k1 K6 I6 s8 p% ?/ C
                Dim theCounter As Integer = 0( v. |$ N4 V4 Q0 @
                : T8 F. O& S9 A& w; C0 `" F1 t
                For Each theCAMObject As CAM.CAMObject In theNcGroup.GetMembers()
6 C7 \1 s& |' C5 p5 N- |8 S6 e                    If theSession.Parts.Work.CAMSetup.IsOperation(theCAMObject) Then
) I+ ^6 v+ a7 T* S                        theCAMObject.SetName(theCounter.ToString("00") & "_" & theCAMObject.Name)1 i$ f4 Y/ X/ p0 b
                        
& y! t7 Y/ a0 q                        theCounter += 1
& v) w3 j0 J% G                        
. F" J8 ?' T; W8 r' m  o5 b                        If theCounter > 99 Then Exit For
* {  U5 f, L' ?- V, n# A6 |; p                    End If
& F+ H6 m: E) y* J                Next
. Z* d% Q1 ]3 y. b) q0 v, Q            End If5 B3 S( g2 @9 `! Y1 A" \
        Next
* M8 V3 P0 |# y0 b" |$ o5 V7 `    End Sub
6 K' p9 I! P8 \  ~+ J8 v   
3 r7 m& t8 r$ n1 Z    Public Function GetUnloadOption(ByVal dummy As String) As Integer
* y1 |4 @8 P; q  b        Return CInt(Session.LibraryUnloadOption.Immediately)+ Z4 q% ]3 i3 |4 X5 D, r
    End Function0 ?; l$ k$ \- S8 ?1 s. |7 ?% p7 U
End Module
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-3-6 20:44 , Processed in 0.053424 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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