青华模具培训学校

 找回密码
 注册

QQ登录

只需一步,快速开始

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

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

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

( k- A. T9 m5 ]" i/ F' N) uOption Strict Off2 \: f9 P1 z  a/ d# z! r
Imports System
# {0 a2 d1 h# J3 O; zImports System.IO  n! k; {1 F, d1 |2 L
Imports System.Windows.Forms; _% {/ g) T, t/ J3 _/ x
Imports NXOpen
& ^4 Z4 ^% d; |% oImports NXOpen.UF
1 ^! H) R9 v' |0 m. P' ?Imports NXOpen.Utilities) K, `' a1 R0 P9 f

% `: T* S* b8 u* H9 z! kModule TestRenameCamObjects0 P5 q- ?, O( K7 t% i5 ~; |
    Dim theSession    As Session   = Session.GetSession()
3 U# X/ P8 w7 e# o# L" O  K" A/ H9 a    Dim theUFSession  As UFSession = UFSession.GetUFSession()
- {: ?/ o, m0 m8 c5 k# |. l    Dim theUI         As UI        = UI.GetUI()  p( `; y8 j& j% S, X1 i
    Dim TempPath      As String    = Environment.GetEnvironmentVariable("TMP")/ t1 [0 ^: c7 S6 I- t& N8 T  L
    Dim ugRelease     As String    = Nothing8 |' o8 n% [$ F9 N# {. `9 y% ?
    Dim UGFullRelease As String    = Nothing
( w4 O' J( f- U   
1 H7 f* H: U4 ]3 Z) m5 h    Sub Main(Args As String())
% l5 X- u) i1 u! ^( Z! y        theSession.LogFile.WriteLine("Executing ... " & _1 n8 q8 y- k! d$ X  f) i. f: |
            System.Reflection.Assembly.GetExecutingAssembly().Location)
6 `( o; z8 u+ ]  w4 f/ ~        
2 |/ u2 J( V0 D        Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")& O' v! Y0 \( ]+ ~
        Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-US")3 k) t; z9 {6 B/ p# K% d
        . N. S. x' Y/ X) l7 K# e% [4 A
        UGRelease = theSession.GetEnvironmentVariableValue("UGII_VERSION")& P! Q& Z! ~4 b6 E! s
        UGFullRelease = theSession.GetEnvironmentVariableValue("UGII_FULL_VERSION")
; e; C  s* d) e; z* \, ]        
, S& z. ?  V0 g+ v        System.Windows.Forms.Application.EnableVisualStyles()" |7 ]& t, S, O% D. C
        
, R* h0 G% j8 l' s; `  A        Dim MyUndoMark As Session.UndoMarkId = _( O. E8 J' a6 T; B) y) J, H
            theSession.SetUndoMark(Session.MarkVisibility.Visible, "TestRenameCamObjects"), y8 d) J5 C) ~9 |
        6 W4 t/ t8 E  B6 O9 i. `5 |" c) {$ T" l
        ' uncomment the following lines to check for the correct application
6 B6 t  _6 ]( h% y        Dim AppID As Integer = UFConstants.UF_APP_NONE: [7 E. N) e. d* U  e7 L
        theUFSession.UF.AskApplicationModule(AppID)
- Y/ d9 s3 \. M        If AppID <> UFConstants.UF_APP_CAM Then
/ a5 j! M1 t# w) F: z& x. W            theUI.NXMessageBox.Show("Application missmatch", NXMessageBox.DialogType.Error, "No NX CAM session, Exiting!")
" b# N5 y( Q* o0 h/ G7 A$ Y            Exit Sub0 ?' m) b: w1 G+ b" z$ B' k
        End If% k% M1 C- b  {0 H/ H$ k6 I& _2 E
        7 g  f+ b& m7 ~- ]$ E7 a, U
        For i As Integer = 0 To theUI.SelectionManager.GetNumSelectedObjects() - 1; R/ s+ p* T6 h$ L" \+ i2 p' L
            Dim theSelectedObject As TaggedObject = theUI.SelectionManager.GetSelectedTaggedObject(i)8 \' s2 L! B% u. H$ u0 g- Y
            : C# o6 X0 x( D% \) I8 w
            If theSession.Parts.Work.CAMSetup.IsGroup(theSelectedObject) Then! R$ h; ]6 ?, W9 n
                Dim thePartName As String = IO.Path.GetFileNameWithoutExtension(theSession.Parts.Work.FullPath)
- Q; {4 |" o6 ~& d/ s7 x               
# \3 \7 M& \  X7 J                Dim theIndex As String = NXOpenUI.NXInputBox.GetInputString("Enter Index")
; Q/ k! U9 P1 e2 m: x& @* Z                , d& }' x( n: J' \" M) \
                Dim theGroupName As String = Left(thePartName, 12).Replace("-", "_") &&#160;"_"&#160;& theIndex &&#160;"_"&#160;& Right(thePartName, 4)
' n  X$ c$ P& N6 t                & @6 _: `* z* c; L/ {
                Dim theNcGroup As CAM.NCGroup = CType(theSelectedObject, CAM.NCGroup)
' n$ O3 k. u1 S8 {, h                # [8 U3 V$ y& H/ i& S) K! g
                theNcGroup.SetName(theGroupName)6 w* Z  E/ y  z0 Y
               
: m$ f5 A* N; Y3 G! {                Dim theCounter As Integer = 0/ @2 M4 n+ s4 Z  X; w
                . ?4 v, P1 n+ E* {
                For Each theCAMObject As CAM.CAMObject In theNcGroup.GetMembers()- T3 S' M: ?! Q2 _# P* J  {
                    If theSession.Parts.Work.CAMSetup.IsOperation(theCAMObject) Then
* a& _% m' x* D& Z                        theCAMObject.SetName(theCounter.ToString("00") & "_" & theCAMObject.Name)
1 x0 d2 G) D7 L% x                        ( l  u9 ~& M9 z+ C# Q& Z0 B% L
                        theCounter += 1! F3 w9 M1 R- c" {, [( l: C: q
                        
. k: G# r; `: v4 T0 |. N. c( d# f                        If theCounter > 99 Then Exit For0 K; G. o5 g: L) F6 ^
                    End If
% f+ S1 W/ X: |& J& i: {5 ?                Next, a3 C( m; \. A4 d* |; {! p
            End If# C/ X5 u7 |$ H, \/ ]8 z# x3 g: ^
        Next' T6 b! C, z2 r: H$ z
    End Sub
) O/ P  x# ~# @4 i   
) l( v6 N" {  t( v    Public Function GetUnloadOption(ByVal dummy As String) As Integer
; ]6 S; c2 X  J        Return CInt(Session.LibraryUnloadOption.Immediately)
8 k2 T( Z& Q9 {# f    End Function
; w" j$ ]# y8 ?End Module
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-4-8 20:52 , Processed in 0.068718 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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