青华模具培训学校

 找回密码
 注册

QQ登录

只需一步,快速开始

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

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

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

7 I# H. l2 v0 q( ~2 r+ KOption Strict Off% T+ K9 H$ E" S- d
Imports System1 V+ E# r3 K. u. I5 m5 j$ y
Imports System.IO* i7 P- V+ `9 r1 e
Imports System.Windows.Forms
! J1 L0 o2 U8 \0 Q2 }Imports NXOpen
6 W& N" z8 h: E# y3 B( CImports NXOpen.UF
' }. h0 F9 m1 [4 ~: F4 ~) AImports NXOpen.Utilities- ~* L& ^2 x* ^7 C& H

( v! V* T8 y; d- bModule TestRenameCamObjects9 @' Z4 ^5 ?! E8 S1 H
    Dim theSession    As Session   = Session.GetSession()3 \( W3 F/ q: ]4 i2 {# X
    Dim theUFSession  As UFSession = UFSession.GetUFSession()
1 _) b/ k: ]8 w$ k    Dim theUI         As UI        = UI.GetUI()6 h2 [! c6 {5 O( K; y& a- K9 V# U
    Dim TempPath      As String    = Environment.GetEnvironmentVariable("TMP")# o( r, }: H  b+ w3 u4 H; ~
    Dim ugRelease     As String    = Nothing
  u# e: O+ q9 [$ k; T$ G    Dim UGFullRelease As String    = Nothing
6 [5 E1 O8 b* Z' V" ~; Y    ! e* V; P9 a+ E
    Sub Main(Args As String())
. ]' ?* b) V, _& C8 A4 J0 a7 y        theSession.LogFile.WriteLine("Executing ... " & _4 g# k( O/ j' J  y7 o/ ^" n
            System.Reflection.Assembly.GetExecutingAssembly().Location)( A0 r$ ^) o6 A! K9 Y0 k- {: D, T
        9 z4 E& k9 J, I
        Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")
* v; v, Q6 K. w7 A- J        Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-US")9 G, ]: @5 W* s( ~- O5 H7 O! H
        9 O" O  I/ {5 C; S
        UGRelease = theSession.GetEnvironmentVariableValue("UGII_VERSION"), G5 _6 p5 k0 _- w/ [5 e8 b
        UGFullRelease = theSession.GetEnvironmentVariableValue("UGII_FULL_VERSION")
$ }. z- D" R& F, T        1 i/ l3 G5 F7 d1 `" }
        System.Windows.Forms.Application.EnableVisualStyles()
0 q& g. E# g1 ?6 K3 {2 ^; s' D2 Z7 ?        
1 P- A5 w8 o% ]1 `        Dim MyUndoMark As Session.UndoMarkId = _6 K5 g$ \' e3 F1 r+ t4 F8 w5 ^( g1 k
            theSession.SetUndoMark(Session.MarkVisibility.Visible, "TestRenameCamObjects")
+ a; }; M2 z. K# M" k' R        1 ^- y& T# b% A7 P  u, o) U
        ' uncomment the following lines to check for the correct application
& f0 P2 K/ N- E# E        Dim AppID As Integer = UFConstants.UF_APP_NONE1 H( \: M+ R& H  Q; d; a
        theUFSession.UF.AskApplicationModule(AppID)
* J( B! t$ N9 W' f) l& K        If AppID <> UFConstants.UF_APP_CAM Then
" L5 u; \: A( K8 U" _+ v- Y. U            theUI.NXMessageBox.Show("Application missmatch", NXMessageBox.DialogType.Error, "No NX CAM session, Exiting!")
+ y  A; B& n3 F- x            Exit Sub- c& q/ O! s$ I% z0 Z! j
        End If
- `0 Y) C/ W9 p* P$ s        * W* d" F( `7 \/ e
        For i As Integer = 0 To theUI.SelectionManager.GetNumSelectedObjects() - 1$ w" Y) ^6 F4 P/ ~6 d4 t$ `6 O
            Dim theSelectedObject As TaggedObject = theUI.SelectionManager.GetSelectedTaggedObject(i)
- j2 R/ i7 k* A. U& Z; \6 W            
8 ~# E" ?- o" S            If theSession.Parts.Work.CAMSetup.IsGroup(theSelectedObject) Then
% o7 o# v& }/ y* M  G; ]                Dim thePartName As String = IO.Path.GetFileNameWithoutExtension(theSession.Parts.Work.FullPath)) F7 Z; u0 Z. o8 f9 j
               
5 H8 b/ G7 f% B* d' E& \! n; O                Dim theIndex As String = NXOpenUI.NXInputBox.GetInputString("Enter Index")% D5 @; D" b2 u1 y
                " i/ g. l8 \8 N( M! S  D5 W1 m4 B
                Dim theGroupName As String = Left(thePartName, 12).Replace("-", "_") &&#160;"_"&#160;& theIndex &&#160;"_"&#160;& Right(thePartName, 4)
+ ?8 V8 G6 Z" m( d                  [9 i% Z1 J/ N# l+ {
                Dim theNcGroup As CAM.NCGroup = CType(theSelectedObject, CAM.NCGroup)1 ~+ a$ V9 C7 o9 [
               
. T; c2 i5 M0 Z# i' T( p1 N9 u* S                theNcGroup.SetName(theGroupName)( g" r* R3 [  h; _) H  W; h
                ) r" Y# M$ X6 W3 S$ l
                Dim theCounter As Integer = 0/ q2 ?. D; |6 |# ]; a9 q
                & t0 d1 i' R$ l9 z5 J6 ^7 R
                For Each theCAMObject As CAM.CAMObject In theNcGroup.GetMembers()
% i( l) V& T. K                    If theSession.Parts.Work.CAMSetup.IsOperation(theCAMObject) Then
0 D; q7 M: C* U. o; L" M                        theCAMObject.SetName(theCounter.ToString("00") & "_" & theCAMObject.Name)
* U* {! P( ?! \4 u                        
! c* l" Y0 A. d: W; W0 @                        theCounter += 1
, G0 t! m+ x6 i                        
. v! |5 }0 P6 h) Z! d/ }                        If theCounter > 99 Then Exit For9 M+ O0 l% a; y# g4 [) [+ p! g
                    End If
' R& f4 x  ]4 ?9 g# q                Next
+ l2 [9 Z& T0 M4 e+ M, I: x            End If
! W# j  N9 E- C7 q4 k        Next
% q8 A0 B2 @4 H# Z    End Sub
, W9 X" j' V, l) Q! w: x' V    & {& \' w2 {/ [9 e. y
    Public Function GetUnloadOption(ByVal dummy As String) As Integer9 V( {9 C( ^& g' n8 \& V+ n4 X3 ~5 O
        Return CInt(Session.LibraryUnloadOption.Immediately)
6 D* ~" o2 _6 J    End Function
  X5 b7 g, [9 b+ C& B7 OEnd Module
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-10-11 14:25 , Processed in 0.048290 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

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