PRT to STEP (214), IGES & JT Journal

Hello,

I've searched around for examples but came up short with what can relate to what i'm looking for, so please excuse me if I am posting something that has already been posted.

I am new to journaling and the last time I used VB was in 2007, but I am currently learning HTML5 and i will either relearn VB or learn Python next. I'm also learning powershell right now. Any advice would be great, thanks!

As for my overall question. Ideally, i would like to right click on a PRT (later on learn to right click STEP & IGES to create JT's and even script in CATIA V5) and run a script. For now, I think I can settle with dragging a dropping a PRT into an NX window, then running a journal that will export a STEP, IGES and JT file into the file location of the PRT that was just opened.

My current attempt of recording and playing a script will run all of the export process', but will continue to use the same output file names that were used when recording the journal. I also have all of the export files being put into a temp folder at the moment, that i will later cut and paste into the correct folder, which is where the PRT is located. This way I can work on other tasks while files convert. We make STEP and IGES formats when sending out quotes, as many companies do not have NX...

This is my current journal. Any tips on editing this to output the name of the PRT file that is currently open? I enjoy learning this stuff!!! But I do feel a little overwhelmed..... This script currently outputs into a temp folder, which i am fine with. But i would love for it to output where the PRT is located. Thank you SOOOO much in advance!

' NX 9.0.2.5
' Journal created by rconrad on Wed Sep 30 16:27:02 2015 Eastern Daylight Time
'
Option Strict Off
Imports System
Imports NXOpen

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

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: File->Export->STEP214...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim step214Creator1 As Step214Creator
step214Creator1 = theSession.DexManager.CreateStep214Creator()

step214Creator1.ExportFrom = Step214Creator.ExportFromOption.ExistingPart

step214Creator1.OutputFile = "K:\Data\DOWNLOAD\GM\09-29-15\84038755\test1\84038755.geo_fin001.001999.stp"

step214Creator1.SettingsFile = "C:\Progra~1\Siemens\NX9~1.0\step214ug\ugstep214.def"

step214Creator1.ObjectTypes.Curves = True

step214Creator1.ObjectTypes.Surfaces = True

step214Creator1.ObjectTypes.Solids = True

step214Creator1.ObjectTypes.Csys = True

step214Creator1.ObjectTypes.ProductData = True

step214Creator1.ObjectTypes.PmiData = True

step214Creator1.InputFile = "\\cmcfs02\Estimating\Data\2012\12GM163\25R\23504308.geo_fin001.001999.prt"

step214Creator1.OutputFile = "K:\Data\DOWNLOAD\GM\09-29-15\84038755\test1\23504308.geo_fin001.001999.stp"

theSession.SetUndoMarkName(markId1, "Export to STEP214 Options Dialog")

step214Creator1.OutputFile = "K:\Data\DOWNLOAD\Temp\23504308.geo_fin001.001999.stp"

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Export to STEP214 Options")

theSession.DeleteUndoMark(markId2, Nothing)

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Export to STEP214 Options")

step214Creator1.FileSaveFlag = False

step214Creator1.LayerMask = "1-256"

Dim nXObject1 As NXObject
nXObject1 = step214Creator1.Commit()

theSession.DeleteUndoMark(markId3, Nothing)

theSession.SetUndoMarkName(markId1, "Export to STEP214 Options")

step214Creator1.Destroy()

theSession.CleanUpFacetedFacesAndEdges()

' ----------------------------------------------
' Menu: File->Export->IGES...
' ----------------------------------------------
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim igesCreator1 As IgesCreator
igesCreator1 = theSession.DexManager.CreateIgesCreator()

igesCreator1.ExportModelData = True

igesCreator1.ExportDrawings = True

igesCreator1.MapTabCylToBSurf = True

igesCreator1.BcurveTol = 0.0508

igesCreator1.IdenticalPointResolution = 0.001

igesCreator1.MaxThreeDMdlSpace = 10000.0

igesCreator1.ObjectTypes.Curves = True

igesCreator1.ObjectTypes.Surfaces = True

igesCreator1.ObjectTypes.Annotations = True

igesCreator1.ObjectTypes.Structures = True

igesCreator1.ObjectTypes.Solids = True

igesCreator1.ExportFrom = IgesCreator.ExportFromOption.ExistingPart

igesCreator1.OutputFile = "K:\Data\DOWNLOAD\GM\09-29-15\84038755\test1\84038755.geo_fin001.001999.igs"

igesCreator1.SettingsFile = "C:\Progra~1\Siemens\NX9~1.0\iges\igesexport.def"

igesCreator1.ObjectTypes.Csys = True

igesCreator1.MaxLineThickness = 2.0

igesCreator1.SysDefmaxThreeDMdlSpace = True

igesCreator1.SysDefidenticalPointResolution = True

igesCreator1.InputFile = "\\cmcfs02\Estimating\Data\2012\12GM163\25R\23504308.geo_fin001.001999.prt"

igesCreator1.InputFile = "\\cmcfs02\Estimating\Data\2012\12GM163\25R\23504308.geo_fin001.001999.prt"

igesCreator1.OutputFile = "K:\Data\DOWNLOAD\GM\09-29-15\84038755\test1\23504308.geo_fin001.001999.igs"

theSession.SetUndoMarkName(markId4, "Export to IGES Options Dialog")

igesCreator1.OutputFile = "K:\Data\DOWNLOAD\Temp\23504308.geo_fin001.001999.igs"

Dim markId5 As Session.UndoMarkId
markId5 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Export to IGES Options")

theSession.DeleteUndoMark(markId5, Nothing)

Dim markId6 As Session.UndoMarkId
markId6 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Export to IGES Options")

igesCreator1.FileSaveFlag = False

igesCreator1.LayerMask = "1-256"

igesCreator1.DrawingList = ""

igesCreator1.ViewList = "Top,Front,Right,Back,Bottom,Left,Isometric,Trimetric,User Defined"

Dim nXObject2 As NXObject
nXObject2 = igesCreator1.Commit()

theSession.DeleteUndoMark(markId6, Nothing)

theSession.SetUndoMarkName(markId4, "Export to IGES Options")

igesCreator1.Destroy()

theSession.CleanUpFacetedFacesAndEdges()

' ----------------------------------------------
' Menu: File->Export->JT...
' ----------------------------------------------
Dim markId7 As Session.UndoMarkId
markId7 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim jtCreator1 As JtCreator
jtCreator1 = theSession.PvtransManager.CreateJtCreator()

jtCreator1.IncludePmi = JtCreator.PmiOption.PartAndAsm

jtCreator1.ConfigFile = "J:\General\Drawing Templates\my_tessUG7.config"

jtCreator1.AutolowLod = True

jtCreator1.WireFrame = True

jtCreator1.MergeSheets = True

jtCreator1.MergeSolids = True

jtCreator1.PreciseGeom = True

theSession.SetUndoMarkName(markId7, "Export JT Dialog")

Dim listCreator1 As ListCreator
listCreator1 = jtCreator1.NewLevel()

listCreator1.Chordal = 0.001

listCreator1.Angular = 20.0

listCreator1.TessOption = ListCreator.TessellationOption.Defined

jtCreator1.LodList.Append(listCreator1)

Dim listCreator2 As ListCreator
listCreator2 = jtCreator1.NewLevel()

listCreator2.Chordal = 0.001

listCreator2.Angular = 20.0

listCreator2.TessOption = ListCreator.TessellationOption.Defined

jtCreator1.LodList.Append(listCreator2)

Dim listCreator3 As ListCreator
listCreator3 = jtCreator1.NewLevel()

listCreator3.Chordal = 0.001

listCreator3.Angular = 20.0

listCreator3.TessOption = ListCreator.TessellationOption.Defined

jtCreator1.LodList.Append(listCreator3)

listCreator1.Simplify = 1.0

listCreator2.Chordal = 0.004

listCreator2.Angular = 0.0

listCreator2.Simplify = 0.4

listCreator2.AdvCompression = 0.5

listCreator3.Chordal = 0.01

listCreator3.Angular = 0.0

listCreator3.Simplify = 0.1

listCreator3.AdvCompression = 1.0

Dim markId8 As Session.UndoMarkId
markId8 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Export JT")

theSession.DeleteUndoMark(markId8, Nothing)

Dim markId9 As Session.UndoMarkId
markId9 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Export JT")

jtCreator1.OutputJtFile = "K:\Data\DOWNLOAD\Temp\Viewing Files\23504308.geo_fin001.001999.jt"

Dim nXObject3 As NXObject
nXObject3 = jtCreator1.Commit()

theSession.DeleteUndoMark(markId9, Nothing)

theSession.SetUndoMarkName(markId7, "Export JT")

jtCreator1.Destroy()

theSession.CleanUpFacetedFacesAndEdges()

' ----------------------------------------------
' Menu: File->Close->All Parts
' ----------------------------------------------
theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)

workPart = Nothing
displayPart = Nothing
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

I suggest breaking the problem up into smaller pieces. First, let's figure out how we can find the path of the current part; that's easy, the part object has a .FullPath property that will return the path to the file.

Next, how do we export a file to the same location as the original file? We can do some string manipulation on the path returned from the .FullPath property to get the export file name. The following code will remove the last 3 characters in the part name (the "prt" of the file extension) and replace it with "stp".

Dim stepExportFileName As String = displayPart.FullPath.Substring(0, displayPart.FullPath.Length - 3) & "stp"

The code below combines the above steps along with some of your recorded code (the step export part). I've turned the "export step" portion of the code into its own subroutine so that it can be called multiple times from Sub Main if desired. I used a "With / End With" block to visually clean up some of the code, but this isn't functionally necessary. The code will export the current display part to STEP format in the same folder as the part. Similar subroutines can be made for the IGES and JT export from the recorded code.

Option Strict Off
Imports System
Imports NXOpen

Module Module3

Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Sub Main(ByVal args() As String)

lw.Open()

If IsNothing(theSession.Parts.BaseDisplay) Then
'active part required
lw.WriteLine("active part required, journal exiting")
Return
End If

'export current display part to STEP
Dim stepExportFileName As String = displayPart.FullPath.Substring(0, displayPart.FullPath.Length - 3) & "stp"
Try
ExportStep(displayPart, stepExportFileName)

Catch ex As Exception
lw.WriteLine("Error: " & ex.Message)
End Try

'lw.WriteLine("display part: " & displayPart.FullPath)
'lw.WriteLine("output file name: " & stepExportFileName)

theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)

workPart = Nothing
displayPart = Nothing

End Sub

Sub ExportStep(ByVal partToExport As Part, ByVal exportFileName As String)

Dim STEP214UG_DIR As String = theSession.GetEnvironmentVariableValue("STEP214UG_DIR")
Dim step214File As String
step214File = IO.Path.Combine(STEP214UG_DIR, "ugstep214.def")

If Not IO.File.Exists(step214File) Then
Throw New Exception("ugstep214.def file not found")
Return
Else
'lw.WriteLine("STEP214 definition file found at: " & step214File)
End If

Dim step214Creator1 As Step214Creator
step214Creator1 = theSession.DexManager.CreateStep214Creator()

With step214Creator1
.ExportFrom = Step214Creator.ExportFromOption.ExistingPart
.SettingsFile = step214File
.ObjectTypes.Curves = True
.ObjectTypes.Surfaces = True
.ObjectTypes.Solids = True
.ObjectTypes.Csys = True
.ObjectTypes.ProductData = True
.ObjectTypes.PmiData = True
.InputFile = partToExport.FullPath
.OutputFile = exportFileName
.FileSaveFlag = False
.LayerMask = "1-256"

End With

Dim nXObject1 As NXObject
nXObject1 = step214Creator1.Commit()

step214Creator1.Destroy()

End Sub

End Module

Thank you very much, that worked great for the STP file! However, I still want to learn the how and why it all worked. But i assume that will take a lot more learning code? I'm going through your Tutorials section right now.

I assume that i can simply replace the step214creator code with similar code for IGS and JT? I would like to automatically create a new folder for JT's called "Viewing Files".

What program do you use to edit the code like that?

How do you know what can be moved or deleted when "cleaning up" the code?

Thank you again for helping me with this code!! I don't expect you to write the whole thing for me, but I will have a lot of questions while learning this. Learning more coding will definitely help me get things done more quickly at work!

"I assume that i can simply replace the step214creator code with similar code for IGS and JT?"

I'd suggest starting with the code that the journal recorder gave you. That's what I did with the STEP export code. I turned it into a subroutine, then cleaned it up a bit; but it is based on the code that you posted from your recorded journal.

"How do you know what can be moved or deleted when "cleaning up" the code?"

I suggest starting by breaking the problem into small chunks and making liberal use of the journal recorder. In this case (export STEP, IGES, and JT files), I'd suggest recording a journal of just the STEP export. Comment out any code that looks unrelated to the desired task and re-run the journal. If it still works, the commented code can be removed entirely if you so desire. If the edited code does not work, reactivate the previously commented lines and try to figure out why they are needed. Once the STEP export works, you can move on to IGES or JT. When they all work, you can combine them into a single journal.

"What program do you use to edit the code like that?"

I'm currently using VB.NET express 2010. You can find more information along with links in the "resources" page (in the main menu on the left side of this web page).

I opened up notepad++ on my computer and pasted your code into it. Then i pasted mine into notepad on a second screen. More of the code started making more sense as to why it was there, a little bit... I don't expect this to be an overnight learning curve, but this is actually really fun to do. This is kind of like working with metal, coding allows you to do anything you want, where as working with wood and a finished OS has its limits. :-) I will definitely be using your page a lot, thank you setting up all of this information in one spot!

Everything appeared to look OK to me, but when I run the journal in NX, I get “Journal Compile Errors”
Line 12:’Public Sub Main(args() As String)’ has multiple definitions with identical signatures.

Option Strict Off
Imports System
Imports NXOpen

Module Module3

Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Sub Main(ByVal args() As String)

lw.Open()

If IsNothing(theSession.Parts.BaseDisplay) Then
'active part required
lw.WriteLine("active part required, journal exiting")
Return
End If

'export current display part to STEP
Dim stepExportFileName As String = displayPart.FullPath.Substring(0, displayPart.FullPath.Length - 3) & "stp"
Try
ExportStep(displayPart, stepExportFileName)

Catch ex As Exception
lw.WriteLine("Error: " & ex.Message)
End Try

'lw.WriteLine("display part: " & displayPart.FullPath)
'lw.WriteLine("output file name: " & stepExportFileName)

theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)

workPart = Nothing
displayPart = Nothing

End Sub

Sub ExportStep(ByVal partToExport As Part, ByVal exportFileName As String)

Dim STEP214UG_DIR As String = theSession.GetEnvironmentVariableValue("STEP214UG_DIR")
Dim step214File As String
step214File = IO.Path.Combine(STEP214UG_DIR, "ugstep214.def")

If Not IO.File.Exists(step214File) Then
Throw New Exception("ugstep214.def file not found")
Return
Else
'lw.WriteLine("STEP214 definition file found at: " & step214File)
End If

Dim step214Creator1 As Step214Creator
step214Creator1 = theSession.DexManager.CreateStep214Creator()

With step214Creator1
.ExportFrom = Step214Creator.ExportFromOption.ExistingPart
.SettingsFile = step214File
.ObjectTypes.Curves = True
.ObjectTypes.Surfaces = True
.ObjectTypes.Solids = True
.ObjectTypes.Csys = True
.ObjectTypes.ProductData = True
.ObjectTypes.PmiData = True
.InputFile = partToExport.FullPath
.OutputFile = exportFileName
.FileSaveFlag = False
.LayerMask = "1-256"

End With

Dim nXObject1 As NXObject
nXObject1 = step214Creator1.Commit()

step214Creator1.Destroy()

End Sub

Sub Main(ByVal args() As String)

lw.Open()

If IsNothing(theSession.Parts.BaseDisplay) Then
'active part required
lw.WriteLine("active part required, journal exiting")
Return
End If

'export current display part to IGES
Dim igesExportFileName As String = displayPart.FullPath.Substring(0, displayPart.FullPath.Length - 3) & "igs"
Try
ExportIges(displayPart, igesExportFileName)

Catch ex As Exception
lw.WriteLine("Error: " & ex.Message)
End Try

'lw.WriteLine("display part: " & displayPart.FullPath)
'lw.WriteLine("output file name: " & igesExportFileName)

theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)

workPart = Nothing
displayPart = Nothing

End Sub

Sub ExportIges(ByVal partToExport As Part, ByVal exportFileName As String)

Dim IGESUG_DIR As String = theSession.GetEnvironmentVariableValue("IGESUG_DIR")
Dim igesFile As String
igesFile = IO.Path.Combine(IGESUG_DIR, "C:\Progra~1\Siemens\NX9~1.0\iges\igesexport.def")

If Not IO.File.Exists(igesFile) Then
Throw New Exception("igesexport.def file not found")
Return
Else
'lw.WriteLine("IGES definition file found at: " & igesFile)
End If

Dim igesCreator1 As IgesCreator
igesCreator1 = theSession.DexManager.CreateIgesCreator()

With igesCreator1
.ExportFrom = IgesCreator.ExportFromOption.ExistingPart
.SettingsFile = igesFile
.ExportModelData = True
.ExportDrawings = True
.MapTabCylToBSurf = True
.BcurveTol = 0.0508
.IdenticalPointResolution = 0.001
.MaxThreeDMdlSpace = 10000.0
.ObjectTypes.Curves = True
.ObjectTypes.Surfaces = True
.ObjectTypes.Annotations = True
.ObjectTypes.Structures = True
.ObjectTypes.Solids = True
.InputFile = partToExport.FullPath
.OutputFile = exportFileName
.ObjectTypes.Csys = True
.MaxLineThickness = 2.0
.SysDefmaxThreeDMdlSpace = True
.SysDefidenticalPointResolution = True
.FileSaveFlag = False
.LayerMask = "1-256"
.DrawingList = ""
.ViewList = "Top,Front,Right,Back,Bottom,Left,Isometric,Trimetric,User Defined"

End With

Dim nXObject2 As NXObject
nXObject2 = igesCreator1.Commit()

igesCreator1.Destroy()

theSession.CleanUpFacetedFacesAndEdges()

End Sub

End Module

The subroutine named "Main" is the one that gets executed when the journal is run. Only one Main subroutine is allowed in the journal. I like to think of Sub Main as an effective manager, one that gets the required information then divvies out the tasks to subordinates (functions and subroutines). When you combine multiple journals into one, the code in each Sub Main needs to be combined into a single Main subroutine.

In your case, sub Main might look like this:

Sub Main(ByVal args() As String)

lw.Open()

If IsNothing(theSession.Parts.BaseDisplay) Then
'active part required
lw.WriteLine("active part required, journal exiting")
Return
End If

'export current display part to STEP
Dim stepExportFileName As String = displayPart.FullPath.Substring(0, displayPart.FullPath.Length - 3) & "stp"
Try
ExportStep(displayPart, stepExportFileName)

Catch ex As Exception
lw.WriteLine("Error: " & ex.Message)
End Try

'export current display part to IGES
Dim igesExportFileName As String = displayPart.FullPath.Substring(0, displayPart.FullPath.Length - 3) & "igs"
Try
ExportIges(displayPart, igesExportFileName)

Catch ex As Exception
lw.WriteLine("Error: " & ex.Message)
End Try

'lw.WriteLine("display part: " & displayPart.FullPath)
'lw.WriteLine("output file name: " & stepExportFileName)

theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)

workPart = Nothing
displayPart = Nothing

End Sub

Other subroutines and initialization code not shown for clarity, but would be required, of course.

I see, that makes more sense now. How do you get your code into that organized looking box? Just incase my attempt right now doesn't look correct....

Why does your code show:

'lw.WriteLine("display part: " & displayPart.FullPath)
'lw.WriteLine("output file name: " & stepExportFileName)

theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)

workPart = Nothing
displayPart = Nothing

End Sub

rather than "igesExportFileName"? I tried running the journal both ways and the stp file turned out the same each time.

Also, i am only able to get a stp file to export, not an iges. I must be close, right? But i think you are correct, I need to work on each piece at a time.

This is my latest attempt to try the journal code, again with an error, but this time in a notepad popup window.
Error: Value cannot be null.
Parameter name: path1

Option Strict Off
Imports System
Imports NXOpen

Module Module3

Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Sub Main(ByVal args() As String)

lw.Open()

If IsNothing(theSession.Parts.BaseDisplay) Then
'active part required
lw.WriteLine("active part required, journal exiting")
Return
End If

'export current display part to STEP
Dim stepExportFileName As String = displayPart.FullPath.Substring(0, displayPart.FullPath.Length - 3) & "stp"
Try
ExportStep(displayPart, stepExportFileName)

Catch ex As Exception
lw.WriteLine("Error: " & ex.Message)
End Try

'lw.WriteLine("display part: " & displayPart.FullPath)
'lw.WriteLine("output file name: " & igesExportFileName)

'export current display part to IGES
Dim igesExportFileName As String = displayPart.FullPath.Substring(0, displayPart.FullPath.Length - 3) & "igs"
Try
ExportIges(displayPart, igesExportFileName)

Catch ex As Exception
lw.WriteLine("Error: " & ex.Message)
End Try

theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)

workPart = Nothing
displayPart = Nothing

End Sub

Sub ExportStep(ByVal partToExport As Part, ByVal exportFileName As String)

Dim STEP214UG_DIR As String = theSession.GetEnvironmentVariableValue("STEP214UG_DIR")
Dim step214File As String
step214File = IO.Path.Combine(STEP214UG_DIR, "ugstep214.def")

If Not IO.File.Exists(step214File) Then
Throw New Exception("ugstep214.def file not found")
Return
Else
'lw.WriteLine("STEP214 definition file found at: " & step214File)
End If

Dim step214Creator1 As Step214Creator
step214Creator1 = theSession.DexManager.CreateStep214Creator()

With step214Creator1
.ExportFrom = Step214Creator.ExportFromOption.ExistingPart
.SettingsFile = step214File
.ObjectTypes.Curves = True
.ObjectTypes.Surfaces = True
.ObjectTypes.Solids = True
.ObjectTypes.Csys = True
.ObjectTypes.ProductData = True
.ObjectTypes.PmiData = True
.InputFile = partToExport.FullPath
.OutputFile = exportFileName
.FileSaveFlag = False
.LayerMask = "1-256"

End With

Dim nXObject1 As NXObject
nXObject1 = step214Creator1.Commit()

step214Creator1.Destroy()

End Sub

Sub ExportIges(ByVal partToExport As Part, ByVal exportFileName As String)

Dim IGESUG_DIR As String = theSession.GetEnvironmentVariableValue("IGESUG_DIR")
Dim igesFile As String
igesFile = IO.Path.Combine(IGESUG_DIR, "C:\Progra~1\Siemens\NX9~1.0\iges\igesexport.def")

If Not IO.File.Exists(igesFile) Then
Throw New Exception("igesexport.def file not found")
Return
Else
'lw.WriteLine("IGES definition file found at: " & igesFile)
End If

Dim igesCreator1 As IgesCreator
igesCreator1 = theSession.DexManager.CreateIgesCreator()

With igesCreator1
.ExportFrom = IgesCreator.ExportFromOption.ExistingPart
.SettingsFile = igesFile
.ExportModelData = True
.ExportDrawings = True
.MapTabCylToBSurf = True
.BcurveTol = 0.0508
.IdenticalPointResolution = 0.001
.MaxThreeDMdlSpace = 10000.0
.ObjectTypes.Curves = True
.ObjectTypes.Surfaces = True
.ObjectTypes.Annotations = True
.ObjectTypes.Structures = True
.ObjectTypes.Solids = True
.InputFile = partToExport.FullPath
.OutputFile = exportFileName
.ObjectTypes.Csys = True
.MaxLineThickness = 2.0
.SysDefmaxThreeDMdlSpace = True
.SysDefidenticalPointResolution = True
.FileSaveFlag = False
.LayerMask = "1-256"
.DrawingList = ""
.ViewList = "Top,Front,Right,Back,Bottom,Left,Isometric,Trimetric,User Defined"

End With

Dim nXObject2 As NXObject
nXObject2 = igesCreator1.Commit()

igesCreator1.Destroy()

theSession.CleanUpFacetedFacesAndEdges()

End Sub

End Module

"Why does your code show..."

In VB.net, the lines of code that start with a single apostrophe are comments and do not get executed. I initially used the lw.writeline commands to print out the values of the variables to make sure I was getting the output that I intended. After I verified the output, I commented out the lines so I would not see the output each time the journal ran. I decided to keep the lines as comments (instead of deleting them completely) in case I needed them in the future, or in case you wanted to verify the output yourself.

The "value cannot be null" error comes about because the IGES directory environment variable is spelled incorrectly. A null value is being returned from the .GetEnvironmentVariableValue command and the error occurs in the IO.Path.Combine command. Since the call to the ExportIges subroutine is wrapped in a Try block (in Sub Main), the error is caught and handled (by showing the error message in the information window) by your code. Since there is an error early in the subroutine, the rest of the code in the sub doesn't run.

Strictly speaking, you don't need to use the .GetEnvironmentVariableValue command; you can simply hardcode the path to your igesexport.def file. However, using the environment variable has its advantages; mainly, it always uses the current value of the IGES export folder to find the igesexport.def file. This means that when you upgrade your version of NX, you don't have to remember to edit this journal and update the path information. Also, anyone else downloading this code for their own use can run it and the journal will find the file no matter where the igesexport.def file is located.

The correct spelling of the environment variable name is "IGES_DIR". If you change the first few lines of ExportIges subroutine to:

Dim IGES_DIR As String = theSession.GetEnvironmentVariableValue("IGES_DIR")
Dim igesFile As String
igesFile = IO.Path.Combine(IGES_DIR, "igesexport.def")

it should work. To find these environment variables that you can use, look in the file "{NX install directory}\UGII\ugii_env_ug.dat" (it is a plain text file). Search for "IGES" and the environment variable will be among the first results. Don't make changes to the ugii_env_ug.dat file unless you are sure about what you are doing!

You are awesome! Thank you for taking the time to help me out with this! I'll play around with this some more and see what I can come up with.

Hey, the PRT to STP and IGS journal is working great!

I am still trying to learn why some of the coding is where it is, but i'm slowly piecing it all together.

1. For instance, in the step file part of the code, which is listed first, it shows this:
Dim nXObject1 As NXObject
nXObject1 = step214Creator1.Commit ()

Then for iges lower down in the code:
Dim nXObject2 As NXObject
nXObject2 = igesCreator1.Commit ()

Does that mean when i add the JT code, it would look like this:
Dim nXObject3 As NXObject
nXObject3 = jtCreator1.Commit ()

Or should all of the nXObject callouts be at nXObject1?

2. When I create a JT file, i make a subfolder where the PRT file that is being used, is created. The subfolder is called "Viewing Files".
Would this work:
ExportJT(displayPart, Viewing Files\JTExportFileName) work?
I'm not sure how to make it create at new folder using the code to use the current PRT name and location...

3. I am having trouble finding the directory term used for JT. STEP was STEP214UG_DIR and IGES was IGES_DIR.
When looking at the first run journal recording for exporting JT data, it shows TessOption and TessellationOption a lot...

4. Also shown a lot in the first run through journal recording is:
Dim listCreator1 As ListCreator
listCreator1 = jtCreator1.NewLevel ()
But it has Sub it looks like for listCreator1, listCreator2 and listCreator3. Can i combine them, or put them into separate subs?
Maybe listCreator substitutes .ObjectTypes. that is used with STEP and IGES?

Sorry for more questions, but thank you for all of your help so far!

1. When a variable is declared in a subroutine (or function), that variable is only available within that subroutine; when the subroutine ends, the variable goes out of scope and can no longer be used. One implication of this is that you can reuse variable names in separate subroutines. If you have separate subroutines for "ExportStep", "ExportIges", and "ExportJt", you can use the variable name "nxObject1" in each of them if you so wish.

This concept is known as the "scope" or "lifetime" of a variable. Variables declared at the module level are available throughout the life of the program; any subroutine can use and change the variable value. Initially this may sound like a good thing, but if there is a bug in the code, you must inspect ALL THE CODE IN THE MODULE to see where the error comes in. It is considered best practice to keep the variable scope as short as possible. This makes debugging and maintenance easier.

That said, I checked the API reference and nothing is returned for the .Commit method of the Step, Iges, or JT exporter. What this means is that we don't need to keep a reference to the output because there isn't any output we are interested in. We can change this:

Dim nXObject1 As NXObject
nXObject1 = step214Creator1.Commit ()

to simply this:

step214Creator1.Commit ()

and likewise for the Iges and Jt exporter.

2. You can use the .NET functions to create a new directory. The code would look something like:

System.IO.Directory.CreateDirectory("C:\path\to\your\directory")

3. I don't know if there is an environment variable pointing to the JT config file. I'd suggest keeping the path hardcoded for now (the same as what the journal recorder used).

4. Keep all three in the same sub, but don't combine them. They define settings for the different "level of detail" views saved with the JT file.

How can I use the above code to convert a *.prt assembly file to a single JT file? what are the variables to be changed. Can anyone help? Thank you in advance.