|
|
admin
发表于 2019-4-17 07:54:25
C#的 没有用NX 函数 - a- a2 p! d: Q
1 e" J2 S6 r# T8 [: V: _* M9 w
+ G, K0 y5 o& e3 e; S# ]3 D+ e
[mw_shl_code=csharp,true] Public Class list_all_parts_in_directory4 o0 j5 a' s a
. W8 p4 B) R: y5 Z* z. ]/ G' V Public Shared Sub Main() N' E! Z, t( D7 }0 d- y
5 C% z @8 D) s5 S* l, x Dim theSession As Session = Session.GetSession() w. n" [. S3 f7 f- o
Dim lw As ListingWindow = theSession.ListingWindow()
6 P9 d5 n/ ~. ^1 O' B8 f
* c, N" Q) o6 Q- D" Z% W2 @ Dim foldername As String = ""
/ b& D1 j1 E2 i0 e lw.Open()& T' f, h/ S8 T6 R, C; @
If (select_directory(foldername) <> DialogResult.OK) Then
, p$ ?/ L- w, p$ N( t: O lw.WriteLine("Input canceled...exit" & vbCrLf)5 h. J$ q8 Y, x; M1 \0 G
Return H: D4 x [; x, k; G
End If
, p! }8 i! ~+ c/ ~
2 D+ t6 R H* K+ Z4 k8 I+ x$ @' H Dim dir As DirectoryInfo = New DirectoryInfo(foldername)8 ~( J1 ~4 W' s- V, Z' O( a L
Dim fsi As FileSystemInfo
3 E! v3 X$ Z' p6 c# j
, q- C% l8 i* f5 E5 N. C+ t lw.Open()+ e" W4 [; E; _) x, t: l1 g
lw.WriteLine("Parts in directory: " _
) U9 h1 i5 _7 {! x/ i: i# ^! u & Path.GetFullPath(dir.ToString()) & vbCrLf)
. m2 C4 N$ K. j( X2 J( v1 F
; q6 x1 C# b) B4 f- ] For Each fsi In dir.GetFileSystemInfos()) |7 G3 W# m1 ]% j v9 T4 _
If (TypeOf fsi Is FileInfo And fsi.Extension.Contains("prt")) Then
$ I0 f) k5 O6 Z: E/ @ Dim f As FileInfo = CType(fsi, FileInfo): e, Y k2 s' d" [
Dim size As Long = f.Length
5 v% s! F/ \) W0 B. \7 T. X: d lw.WriteLine(f.Name & " " & size & "Bytes" & vbCrLf)
- `( o. |9 C. d! E4 e3 e0 z End If8 |* \' q5 v+ a7 Q. b" |7 E0 W
Next fsi
6 \6 S5 ^" J, b: S. |& j6 B. n
' ^; t1 |! D3 J5 x& z End Sub
4 F! K( W+ f3 Y) D t; E m ?4 G* j: m& d+ H+ J, Y
Public Shared Function select_directory(ByRef foldername) As System.Windows.Forms.DialogResult
9 Q$ d6 s6 T1 w& X, N% K
+ ]+ x" ?/ H/ b8 Z9 Z( ] Dim fbd As FolderBrowserDialog: L e! R! U$ R9 [8 B- E
Dim result As System.Windows.Forms.DialogResult+ L- G# R- B' J8 h6 ]% f
) H$ H. Q& k g fbd = New System.Windows.Forms.FolderBrowserDialog()' _" f& [! n0 J) X' Y( S# J
fbd.Description = "Select directory to check"
: |4 q% m6 k0 B3 r. K fbd.ShowNewFolderButton = False
0 \# _! G4 {0 J# y5 O) `6 n ' start browsing at Desktop folder, uncomment for any other default directory
2 N9 D0 A# j# G4 C, i+ w ' fbd.SelectedPath = GetEnvironmentVariable("UGII_BASE_DIR")1 s; [" P( F: ?+ e8 ~ o. r6 C
' fbd.SelectedPath = GetEnvironmentVariable("UGII_BASE_DIR") + "\Moldwizard"8 t E u4 b0 w3 R }% p
' fbd.SelectedPath = "c:\aaa\bbb"
" g7 O! e! n0 { result = fbd.ShowDialog()
1 m. {0 r1 @- t! A4 X; @2 B3 F foldername = fbd.SelectedPath) v" r7 X% c) A% z$ o( j
fbd.Dispose()
3 V( S* i- h8 ?" b& n& q Return result
+ C+ s9 k5 A2 F+ c- x' P/ q
. H# y) l' {: S& i End Function
- w. [# }# e% k% l
+ c/ M6 }1 I. b! D0 e. m; b Public Function GetUnloadOption(ByVal dummy As String) As Integer
8 \ ~! V* w, |3 f( A GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
2 P, G9 n: k) p% z" d End Function
3 Y( }) W- h0 B8 U( A6 A/ n' x x W
End Class[/mw_shl_code]
3 F# t* q: Q, X |
|