Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

please help to export parasolid batch 1

Status
Not open for further replies.

ppap eroni

Mechanical
Feb 22, 2023
8
hi good day
i get this code at old thread.
but it is not working on my nx.
when i run this journal,it says "Line 204: 'Forms' is not a member of 'Windows'."
please check atteched file.
and please understand that my english may not be smooth because I am Korean.
thanks you.

my system
windows 10
nx 1973.4341
 
 https://files.engineering.com/getfile.aspx?folder=5f24d553-c058-451f-a161-313b31743041&file=psBatchExport.vb
Replies continue below

Recommended for you

I'm not sure where I got this from, there is no author in the header. I did not write it.
it cycles through a folder and exports what's shown to Parasolid files.

it works on my PC, NX2027 and windows10

Code:
'
' When you build Add Reference.. System.Windows.Forms   
'
'OR
'
'Run it from journal
'
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.IO
Imports System.Windows.Forms

Module export_all_bodies_in_selected_directory_to_parasolid

    Dim startfolder As String = ""
    Public s As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = s.ListingWindow()

    Sub Main()

        Dim foldername As String = startfolder

        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
        traverse_directory(foldername)

    End Sub
    Sub traverse_directory(ByVal foldername As String)

        Dim dir As DirectoryInfo = New DirectoryInfo(foldername)
        Dim fsi As FileSystemInfo

        For Each fsi In dir.GetFileSystemInfos()
            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 (f.Extension.ToLower() = ".prt") Then
                        lw.WriteLine(vbCrLf & pspec & " " & size & "Bytes")

                        OpenAndSave(pspec)
                    End If
                ElseIf (TypeOf fsi Is DirectoryInfo) Then
                    traverse_directory(fsi.FullName)
                End If
            Catch
            End Try
        Next fsi

    End Sub
    Sub OpenAndSave(ByVal pspec As String)

        Dim basePart1 As BasePart
        Dim partLoadStatus1 As PartLoadStatus = Nothing
        Dim partSaveStatus1 As PartSaveStatus = Nothing
        s.Parts.LoadOptions.ComponentsToLoad = LoadOptions.LoadComponents.None
        basePart1 = s.Parts.OpenBaseDisplay(pspec, partLoadStatus1)

        Dim inx As Integer = 0
        Dim dispPart As Part = s.Parts.Display
        Dim bodies As BodyCollection = dispPart.Bodies
        Dim bodyCount As Integer = bodies.ToArray.Length
        Dim tagList(bodyCount - 1) As NXOpen.Tag
        Dim pspec1 As String = pspec.Replace(".prt", ".x_t")

        Do
            tagList(inx) = dispPart.Bodies.ToArray(inx).Tag
            inx = inx + 1
        Loop Until inx = bodyCount

        ufs.Ps.ExportData(tagList, pspec1)

        If (partLoadStatus1.NumberUnloadedParts() = 0) Then
            partSaveStatus1 = basePart1.Save(BasePart.SaveComponents.False, BasePart.CloseAfterSave.True)
            partSaveStatus1.Dispose()
        Else
            reportLoadStatus(partLoadStatus1)
            s.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)
        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
        fbd.SelectedPath = foldername
        result = fbd.ShowDialog()
        foldername = fbd.SelectedPath
        fbd.Dispose()
        Return result

    End Function

    Public Function reportLoadStatus(ByVal loadStatus As PartLoadStatus) As Integer
        lw.Open()
        Dim counter As Integer = 0
        lw.WriteLine("Count of parts that failed to load: " & _
                      loadStatus.NumberUnloadedParts.ToString())
        lw.WriteLine("===========================================")

        Do
            Dim file As String = loadStatus.GetPartName(counter)
            Dim failure As String = loadStatus.GetStatusDescription(counter)
            Dim statusCode As Integer = loadStatus.GetStatus(counter)
            lw.WriteLine("File: " & file)
            lw.WriteLine("Code: " & statusCode)
            lw.WriteLine("Status: " & failure)
            lw.WriteLine(vbCrLf)
            counter += 1
        Loop Until counter = loadStatus.NumberUnloadedParts

        Return counter
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function

End Module
 
Rob_N, thank you so much.
Thanks to you, I can reduce a lot of mistakes and save time. It replaces the prt file in the specified path with an x_t file.
It's working well. It's great!
 
Rob_N, thank you.
When I used it, the partner company said they couldn't open the latest parasolid version.
Can I lower it to V25.0 (NX8.5) or V27.0 (NX10) version?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor