Sample NX Open .NET Visual Basic program : edit tolerance of all parts in selected directory
작성자k2ice작성시간09.09.05조회수388 목록 댓글 0Date: 20-JAN-2008
Subject: Sample NX Open .NET Visual Basic program : edit tolerance of all parts in selected directory
Note: GTAC provides programming examples for illustration only, and
assumes that you are familiar with the programming language being
demonstrated and the tools used to create and debug procedures. GTAC
support professionals can help explain the functionality of a particular
procedure, but we will not modify these examples to provide added
functionality or construct procedures to meet your specific needs.
��Option Strict Off
Imports NXOpen
Imports NXOpen.Preferences
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpenUI
Imports System
Imports System.io
Imports System.Environment
Imports System.Windows.Forms
Module edit_tol_of_parts_in_dir
Dim disttol As Double = 0.001
Dim angtol As Double = 0.1
Sub Main()
Dim s As Session = Session.GetSession()
Dim lw As ListingWindow = s.ListingWindow()
Dim foldername As String = ""
lw.Open()
If (select_directory(foldername) <> DialogResult.OK) Then
lw.WriteLine("Input canceled...exit" & vbCrLf)
Return
Else
lw.WriteLine("Selected directory " & foldername & vbCrLf)
End If
disttol = NXInputBox.GetInputNumber("Enter Value:", _
"Distance Tolerance", disttol)
angtol = NXInputBox.GetInputNumber("Enter Value:", _
"Angle Tolerance", angtol)
Dim dir As DirectoryInfo = New DirectoryInfo(foldername)
Dim fsi As FileSystemInfo
lw.WriteLine("Processing Parts in Directory: " _
& Path.GetFullPath(dir.ToString()) & vbCrLf)
For Each fsi In dir.GetFileSystemInfos("*.prt")
Try
If (TypeOf fsi Is FileInfo) Then
Dim f As FileInfo = CType(fsi, FileInfo)
Dim pspec As String = f.FullName
Dim size As Long = f.Length
If (Path.HasExtension(pspec) _
And (Path.GetExtension(pspec).ToLower() = ".prt")) Then
lw.WriteLine(vbCrLf & pspec & " " & size & "Bytes")
Do_it(pspec)
End If
End If
Catch
End Try
Next fsi
End Sub
Sub Do_it(ByVal pspec As String)
Dim s As Session = Session.GetSession()
Dim basePart1 As BasePart
Dim partLoadStatus1 As PartLoadStatus = Nothing
Dim partSaveStatus1 As PartSaveStatus
Dim workPart As Part
Dim lw As ListingWindow = s.ListingWindow()
s.Parts.LoadOptions.ComponentsToLoad = _
LoadOptions.LoadComponents.None
basePart1 = s.Parts.OpenBaseDisplay(pspec, partLoadStatus1)
If (partLoadStatus1.NumberUnloadedParts() = 0) Then
workPart = s.Parts.Work
Dim prefs As PartPreferences = workPart.Preferences
Dim pm As PartModeling = prefs.Modeling
lw.WriteLine(" DistTol=" & pm.DistanceToleranceData _
& " AngTol=" & pm.AngleToleranceData & vbCrLf)
If ((pm.DistanceToleranceData <> disttol) _
Or (pm.AngleToleranceData <> angtol)) Then
lw.WriteLine(" -> Tolerance needs to be changed" & vbCrLf)
pm.DistanceToleranceData = disttol
pm.AngleToleranceData = angtol
partSaveStatus1 = workPart.Save(BasePart.SaveComponents.False, _
BasePart.CloseAfterSave.True)
partSaveStatus1.Dispose()
Else
lw.WriteLine(" -> Tolerance ok" & vbCrLf)
s.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)
End If
End If
partLoadStatus1.Dispose()
End Sub
Public 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:\mypath1\mypath2"
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.Immediately
End Function
End Module
다음검색