ufun 获取文件夹下所有prt文件名
ufun 获取文件夹下所有prt文件名 C#的没有用NX 函数Public Class list_all_parts_in_directory
Public Shared Sub Main()
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow()
Dim foldername As String = ""
lw.Open()
If (select_directory(foldername) <> DialogResult.OK) Then
lw.WriteLine("Input canceled...exit" & vbCrLf)
Return
End If
Dim dir As DirectoryInfo = New DirectoryInfo(foldername)
Dim fsi As FileSystemInfo
lw.Open()
lw.WriteLine("Parts in directory: " _
& Path.GetFullPath(dir.ToString()) & vbCrLf)
For Each fsi In dir.GetFileSystemInfos()
If (TypeOf fsi Is FileInfo And fsi.Extension.Contains("prt")) Then
Dim f As FileInfo = CType(fsi, FileInfo)
Dim size As Long = f.Length
lw.WriteLine(f.Name & " " & size & "Bytes" & vbCrLf)
End If
Next fsi
End Sub
Public Shared Function select_directory(ByRef foldername) As System.Windows.Forms.DialogResult
Dim fbd As FolderBrowserDialog
Dim result As System.Windows.Forms.DialogResult
fbd = New System.Windows.Forms.FolderBrowserDialog()
fbd.Description = "Select directory to check"
fbd.ShowNewFolderButton = False
' start browsing at Desktop folder, uncomment for any other default directory
' fbd.SelectedPath = GetEnvironmentVariable("UGII_BASE_DIR")
' fbd.SelectedPath = GetEnvironmentVariable("UGII_BASE_DIR") + "\Moldwizard"
' fbd.SelectedPath = "c:\aaa\bbb"
result = fbd.ShowDialog()
foldername = fbd.SelectedPath
fbd.Dispose()
Return result
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Class
ufun 的 方法
int
cnt = 0,
resp;
tag_t
part;
char
dirspec = { "" },
fname,
part_name;
UF_PART_load_status_t
status;
if (UF_CALL(UF_initialize())) return 1;
while (printf("Enter directory path:\n") && gets(dirspec) &&
strlen(dirspec))
{
uc4508(dirspec, (1<<13)|(1<<11), 0, "*.prt");
while ((resp = uc4518()) == 0)
{
UF_CALL(uc4600(fname));
UF_CALL(uc4575(dirspec, 2, fname, part_name));
ECHO( "%d.%s\n", ++cnt, part_name);
UF_CALL(UF_PART_open(part_name, &part, &status));
if (status.n_parts > 0) report_load_status(&status);
if (!status.failed)
{
do_it();
UF_PART_close_all();
}
}
UF_CALL(uc4548());
ECHO("\nProcessed %d parts.\n", cnt);
}
页:
[1]