Batch convert JT to UG Part from folder

Hi,

As I said in Subject, can any one help me with a code which browses a folder and process all .JT files in it and converts to .PRT with same name.

Hi,

Below is the code to convert all "jt" files in a single folder (not sub folders) to Ug part files.

Option Strict Off
Imports System
Imports NXOpen
Imports System.Windows.Forms
Imports System.IO

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()

Dim FolderBrowserDialog1 As New FolderBrowserDialog
FolderBrowserDialog1.ShowDialog()

Dim path as string = FolderBrowserDialog1.Selectedpath().toString()
Dim files() as string = Directory.GetFiles(path, "*.jt", SearchOption.TopDirectoryOnly)

For each file as string in files
Dim basePart1 As NXOpen.BasePart
Dim partLoadStatus1 As NXOpen.PartLoadStatus
basePart1 = theSession.Parts.OpenBaseDisplay(file, partLoadStatus1)
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
partLoadStatus1.Dispose()
Dim partSaveStatus1 As NXOpen.PartSaveStatus
partSaveStatus1 = workPart.SaveAs(file.Replace(".jt",""))
partSaveStatus1.Dispose()

theSession.Parts.CloseAll(NXOpen.BasePart.CloseModified.CloseModified, Nothing)
workPart = Nothing
displayPart = Nothing

Next

End Sub
End Module

GopinadhGvs

It's processing all the JT files in Directory but not saving in same location, don't know where it's saving the files

-[]-

Try changing this line:

partSaveStatus1 = workPart.SaveAs(file.Replace(".jt",""))

to this:

partSaveStatus1 = workPart.SaveAs(file.Replace(".jt",".prt"))

Hi,

I tried this solution,its really handy but it creates 2 prt files out of one jt file. Could you please advise?

Cheer,
Adi

I tested on NX 9.0.3.4 and only got 1 prt file per jt. What version of NX are you running? Are your jt files of individual parts or assemblies? The jt files that I tested on were of individual parts, not assemblies.

Hi,

Thanks for the quick reponse. I am using NX NX 9.0.2.5 and the JT files I was converting is a simple assembly and its child parts. My ultimate goal is to upload JT files to Teamcenter, so my initial approach is to convert JTs to NX (with assembly information - which is working very fine apart from 2 NX parts for 1 JT file) and then upload it those to TC. Any advise from yourside on any other approach?

Regards,
Adi

Do you have any control over how the JT files are created? It seems that when exporting JT files from NX, there are a few different options on how to organize the JT files. The "as a single file" option seems to be the one you want. The other options may create individual files for the components. If a component is used multiple times in the assmebly, you may end up with multiple parts.

The following code will check to see if a part with the same name already exists before doing the "save-as", but the resulting assembly may not be what you want.

Option Strict Off
Imports System
Imports NXOpen
Imports System.Windows.Forms
Imports System.IO

Module Module85
Sub Main(ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()

Dim FolderBrowserDialog1 As New FolderBrowserDialog
FolderBrowserDialog1.ShowDialog()

Dim path As String = FolderBrowserDialog1.SelectedPath().ToString()
Dim files() As String = Directory.GetFiles(path, "*.jt", SearchOption.TopDirectoryOnly)

For Each file As String In files
Dim basePart1 As NXOpen.BasePart
Dim partLoadStatus1 As NXOpen.PartLoadStatus
basePart1 = theSession.Parts.OpenBaseDisplay(file, partLoadStatus1)
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
partLoadStatus1.Dispose()
Dim newFileName As String = file.Replace(".jt", ".prt")

If System.IO.File.Exists(newFileName) Then
Continue For
End If

Dim partSaveStatus1 As NXOpen.PartSaveStatus
partSaveStatus1 = workPart.SaveAs(file.Replace(".jt", ".prt"))
partSaveStatus1.Dispose()

theSession.Parts.CloseAll(NXOpen.BasePart.CloseModified.CloseModified, Nothing)
workPart = Nothing
displayPart = Nothing

Next

End Sub
End Module

Hi,

I am not sure how but this journal also created 2 JT files, I think its not the code but the way JT files are created.One prt file is named as Text1.prt and the other one as Text1_jt.prt.Upon loading the assembly, NX picks up Text1_jt.prt as a sub component.I am lost now and monolithic JT is not an option, I was wondering if there is a way to bulk convert JT to step instead?

Appreciate your help,
Adi

Hi,
I have figured out the problem and sorted the issue.Now, is there a way I could run this sub routine from command prompt? I tried different options but get error -
fatal error
run_journal: failed to initialize UFUN 949903

Please advise.

Cheers,
Adi

Fixed it..I missed Imports System.IO in my journal running out of a perl script. Thanks for the journal.

Cheers,
Adi