Control PDF export file name

I have been using this automated PDF vb for a while now but the program uses the file name as the PDF output name and I need to have a truncated name that is derived from the file name not the exact file name. I am open to any suggestions. Below is the code I have now.

current output format = IPD25289-01_REV-B_DWG
desired output format = DRWG attribute /-01-rev/ REVISION Attribute
constant text in middle

;I know I have these two attributes
strDrawing = workPart.GetStringAttribute("DRWG")
strRevision = workPart.GetStringAttribute("REVISION")

Option Strict Off
Imports System
Imports System.IO
Imports System.Collections
Imports System.Windows.Forms
Imports System.Windows.Forms.MessageBox
Imports NXOpen
Imports NXOpen.UF

Module NXJournal

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

'**********************************************************

Sub Main

Dim dwgs As Drawings.DrawingSheetCollection
dwgs = workPart.DrawingSheets
Dim sheet As Drawings.DrawingSheet
Dim i As Integer
Dim pdfFile As String
Dim currentPath As String
Dim currentFile As String
Dim exportFile As String
Dim partUnits As Integer
Dim strOutputFolder As String
Dim strRevision As String
Dim rspFileExists
Dim rspAdvancePrint

'determine if we are running under TC or native
Dim IsTcEng As Boolean = False
Dim UFSes As UFSession = UFSession.GetUFSession()
UFSes.UF.IsUgmanagerActive(IsTcEng)

partUnits = displayPart.PartUnits
'0 = inch
'1 = metric

If IsTcEng Then
currentFile = workPart.GetStringAttribute("DB_PART_NO")
strRevision = workPart.GetStringAttribute("DB_PART_REV")

Else 'running in native mode
'currentFile = GetFilePath() & GetFileName() & ".prt"
currentPath = GetFilePath()
currentFile = GetFileName()

Try
strRevision = workPart.GetStringAttribute("REVISION")
strRevision = Trim(strRevision)
Catch ex As Exception
strRevision = ""
End Try
End If
exportFile = currentFile

'strOutputFolder = OutputPath()
'if we don't have a valid directory (ie the user pressed 'cancel') exit the journal
'If Not Directory.Exists(strOutputFolder) Then
' Exit Sub
'End If
strOutputFolder = "N:\LIBRARY\STANDARD DRAWINGS\Standard Drawings\IPD\"

'rspAdvancePrint = MessageBox.Show("Add advance print watermark?", "Add Watermark?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

Dim shts As New ArrayList()
For Each sheet in dwgs
shts.Add(sheet.Name)
Next
shts.Sort()

i = 0
Dim sht As String
For Each sht in shts

For Each sheet in dwgs
If sheet.name = sht Then
i = i + 1

If rspAdvancePrint = vbyes Then
pdfFile = strOutputFolder & exportFile & "_advance" & ".pdf"
Else
If strRevision <> "" Then
pdfFile = strOutputFolder & exportFile & "_" & strRevision & ".pdf"
Else
pdfFile = strOutputFolder & exportFile & ".pdf"
End If
End If

'the pdf export uses 'append file', if we are on sheet 1 make sure the user wants to overwrite
'if the drawing is multisheet, don't ask on subsequent sheets
If i = 1 Then
If File.Exists(pdfFile) Then
rspFileExists = msgbox("The file: '" & pdfFile & "' already exists; overwrite?", vbyesno + vbquestion)
If rspFileExists = vbYes Then
Try
File.Delete(pdfFile)
Catch ex As Exception
msgbox(ex.message & vbcrlf & "Journal exiting", vbcritical + vbokonly, "Error")
Exit Sub
End Try
Else
'msgbox("journal exiting", vbokonly)
Exit Sub
End If
End If
End If

'update any views that are out of date
theSession.Parts.Work.DraftingViews.UpdateViews(Drawings.DraftingViewCollection.ViewUpdateOption.OutOfDate, sheet)

Try
ExportPDF(sheet, pdfFile, partUnits, rspAdvancePrint)
Catch ex As exception
msgbox("Error occurred in PDF export" & vbcrlf & ex.message & vbcrlf & "journal exiting", vbcritical + vbokonly, "Error")
Exit Sub
End Try
Exit For
End If
Next

Next

If i = 0 Then
MessageBox.Show("This part has no drawing sheets to export", "PDF export failure", MessageBoxButtons.ok, MessageBoxIcon.Warning)
Else
MessageBox.Show("Exported: " & i & " sheet(s) to pdf file" & vbcrlf & pdfFile, "PDF export success", MessageBoxButtons.ok, MessageBoxIcon.Information)
End If

End Sub
'**********************************************************

Function GetFileName()
Dim strPath As String
Dim strPart As String
Dim pos As Integer

'get the full file path
strPath = displayPart.fullpath
'get the part file name
pos = InStrRev(strPath, "\")
strPart = Mid(strPath, pos + 1)

strPath = Left(strPath, pos)
'strip off the ".prt" extension
strPart = Left(strPart, Len(strPart) - 4)

GetFileName = strPart
End Function
'**********************************************************

Function GetFilePath()
Dim strPath As String
Dim strPart As String
Dim pos As Integer

'get the full file path
strPath = displayPart.fullpath
'get the part file name
pos = InStrRev(strPath, "\")
strPart = Mid(strPath, pos + 1)

strPath = Left(strPath, pos)
'strip off the ".prt" extension
strPart = Left(strPart, Len(strPart) - 4)

GetFilePath = strPath
End Function
'**********************************************************

Function OutputPath()
'Requires:
' Imports System.IO
' Imports System.Windows.Forms
'if the user presses OK on the dialog box, the chosen path is returned
'if the user presses cancel on the dialog box, 0 is returned

Dim strLastPath As String
Dim strOutputPath As String

'Key will show up in HKEY_CURRENT_USER\Software\VB and VBA Program Settings
Try
'Get the last path used from the registry
strLastPath = GetSetting("NX journal", "Export pdf", "ExportPath")
'msgbox("Last Path: " & strLastPath)
Catch e As ArgumentException
Catch e As Exception
msgbox (e.GetType.ToString)
Finally
End Try

Dim FolderBrowserDialog1 As New FolderBrowserDialog

' Then use the following code to create the Dialog window
' Change the .SelectedPath property to the default location
With FolderBrowserDialog1
' Desktop is the root folder in the dialog.
.RootFolder = Environment.SpecialFolder.Desktop
' Select the D:\home directory on entry.
If Directory.Exists(strLastPath) Then
.SelectedPath = strLastPath
Else
.SelectedPath = "C:\UGDefault"
End If
' Prompt the user with a custom message.
.Description = "Select the directory to export .pdf file"
If .ShowDialog = DialogResult.OK Then
' Display the selected folder if the user clicked on the OK button.
OutputPath = .SelectedPath
' save the output folder path in the registry for use on next run
SaveSetting("NX journal", "Export pdf", "ExportPath", .SelectedPath)
Else
'user pressed 'cancel', exit the subroutine
OutputPath = 0
'exit sub
End If
End With

End Function
'**********************************************************

Sub ExportPDF(dwg As Drawings.DrawingSheet, outputFile As String, units As Integer, advancePrint As Integer)

Dim printPDFBuilder1 As PrintPDFBuilder

printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder()
printPDFBuilder1.Scale = 1.0
printPDFBuilder1.Action = PrintPDFBuilder.ActionOption.Native
printPDFBuilder1.Colors = PrintPDFBuilder.Color.BlackOnWhite
printPDFBuilder1.Size = PrintPDFBuilder.SizeOption.ScaleFactor
If units = 0 Then
printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.English
Else
printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.Metric
End If
printPDFBuilder1.XDimension = dwg.height
printPDFBuilder1.YDimension = dwg.length
printPDFBuilder1.OutputText = PrintPDFBuilder.OutputTextOption.Polylines
printPDFBuilder1.RasterImages = True
printPDFBuilder1.ImageResolution = PrintPDFBuilder.ImageResolutionOption.Medium
printPDFBuilder1.Append = True
If advancePrint = vbyes Then
printPDFBuilder1.AddWatermark = True
printPDFBuilder1.Watermark = "ADVANCE PRINT NOT TO BE USED FOR PRODUCTION " & Today
Else
printPDFBuilder1.AddWatermark = False
printPDFBuilder1.Watermark = ""
End If

Dim sheets1(0) As NXObject
Dim drawingSheet1 As Drawings.DrawingSheet = CType(dwg, Drawings.DrawingSheet)

sheets1(0) = drawingSheet1
printPDFBuilder1.SourceBuilder.SetSheets(sheets1)

printPDFBuilder1.Filename = outputFile

Dim nXObject1 As NXObject
nXObject1 = printPDFBuilder1.Commit()

printPDFBuilder1.Destroy()

End Sub
'**********************************************************

End Module

I managed to add my attributes and one constant. Here is the code that works.

Option Strict Off
Imports System
Imports System.IO
Imports System.Collections
Imports System.Windows.Forms
Imports System.Windows.Forms.MessageBox
Imports NXOpen
Imports NXOpen.UF

Module NXJournal

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

'**********************************************************

Sub Main

Dim dwgs As Drawings.DrawingSheetCollection
dwgs = workPart.DrawingSheets
Dim sheet As Drawings.DrawingSheet
Dim i As Integer
Dim pdfFile As String
Dim currentPath As String
Dim currentFile As String
Dim exportFile As String
Dim partUnits As Integer
Dim strOutputFolder As String
Dim strRevision As String
Dim rspFileExists
Dim rspAdvancePrint
Dim strDrawing As String
Dim strConstant

'determine if we are running under TC or native
Dim IsTcEng As Boolean = False
Dim UFSes As UFSession = UFSession.GetUFSession()
UFSes.UF.IsUgmanagerActive(IsTcEng)

partUnits = displayPart.PartUnits
'0 = inch
'1 = metric

If IsTcEng Then
currentFile = workPart.GetStringAttribute("DB_PART_NO")
strRevision = workPart.GetStringAttribute("DB_PART_REV")

Else 'running in native mode
'currentFile = GetFilePath() & GetFileName() & ".prt"
currentPath = GetFilePath()
currentFile = GetFileName()

Try
strDrawing = workPart.GetStringAttribute("DRWG")
strRevision = workPart.GetStringAttribute("REVISION")
'strConstant = "-01-rev"
strConstant = "-01"

Catch ex As Exception
strRevision = ""
End Try
End If
exportFile = currentFile
'exportFile = (strDrawing + strConstant + strRevision)
exportFile = (strDrawing + strConstant)

'strOutputFolder = OutputPath()
'if we don't have a valid directory (ie the user pressed 'cancel') exit the journal
'If Not Directory.Exists(strOutputFolder) Then
' Exit Sub
'End If
strOutputFolder = "N:\LIBRARY\STANDARD DRAWINGS\Standard Drawings\IPD\"

'rspAdvancePrint = MessageBox.Show("Add advance print watermark?", "Add Watermark?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

Dim shts As New ArrayList()
For Each sheet In dwgs
shts.Add(sheet.Name)
Next
shts.Sort()

i = 0
Dim sht As String
For Each sht In shts

For Each sheet In dwgs
If sheet.name = sht Then
i = i + 1

If rspAdvancePrint = vbyes Then
pdfFile = strOutputFolder & exportFile & "_advance" & ".pdf"
Else
If strRevision <> "" Then
pdfFile = strOutputFolder & exportFile & ".pdf"
Else
pdfFile = strOutputFolder & exportFile & ".pdf"
End If
End If

'the pdf export uses 'append file', if we are on sheet 1 make sure the user wants to overwrite
'if the drawing is multisheet, don't ask on subsequent sheets
If i = 1 Then
If File.Exists(pdfFile) Then
rspFileExists = msgbox("The file: '" & pdfFile & "' already exists; overwrite?", vbyesno + vbquestion)
If rspFileExists = vbYes Then
Try
File.Delete(pdfFile)
Catch ex As Exception
msgbox(ex.message & vbcrlf & "Journal exiting", vbcritical + vbokonly, "Error")
Exit Sub
End Try
Else
'msgbox("journal exiting", vbokonly)
Exit Sub
End If
End If
End If

'update any views that are out of date
theSession.Parts.Work.DraftingViews.UpdateViews(Drawings.DraftingViewCollection.ViewUpdateOption.OutOfDate, sheet)

Try
ExportPDF(sheet, pdfFile, partUnits, rspAdvancePrint)
Catch ex As exception
msgbox("Error occurred in PDF export" & vbcrlf & ex.message & vbcrlf & "journal exiting", vbcritical + vbokonly, "Error")
Exit Sub
End Try
Exit For
End If
Next

Next

If i = 0 Then
MessageBox.Show("This part has no drawing sheets to export", "PDF export failure", MessageBoxButtons.ok, MessageBoxIcon.Warning)
Else
MessageBox.Show("Exported: " & i & " sheet(s) to pdf file" & vbcrlf & pdfFile, "PDF export success", MessageBoxButtons.ok, MessageBoxIcon.Information)
End If

End Sub
'**********************************************************

Function GetFileName()
Dim strPath As String
Dim strPart As String
Dim pos As Integer

'get the full file path
strPath = displayPart.fullpath
'get the part file name
pos = InStrRev(strPath, "\")
strPart = Mid(strPath, pos + 1)

strPath = Left(strPath, pos)
'strip off the ".prt" extension
strPart = Left(strPart, Len(strPart) - 4)

GetFileName = strPart
End Function
'**********************************************************

Function GetFilePath()
Dim strPath As String
Dim strPart As String
Dim pos As Integer

'get the full file path
strPath = displayPart.fullpath
'get the part file name
pos = InStrRev(strPath, "\")
strPart = Mid(strPath, pos + 1)

strPath = Left(strPath, pos)
'strip off the ".prt" extension
strPart = Left(strPart, Len(strPart) - 4)

GetFilePath = strPath
End Function
'**********************************************************

Function OutputPath()
'Requires:
' Imports System.IO
' Imports System.Windows.Forms
'if the user presses OK on the dialog box, the chosen path is returned
'if the user presses cancel on the dialog box, 0 is returned

Dim strLastPath As String
Dim strOutputPath As String

'Key will show up in HKEY_CURRENT_USER\Software\VB and VBA Program Settings
Try
'Get the last path used from the registry
strLastPath = GetSetting("NX journal", "Export pdf", "ExportPath")
'msgbox("Last Path: " & strLastPath)
Catch e As ArgumentException
Catch e As Exception
msgbox (e.GetType.ToString)
Finally
End Try

Dim FolderBrowserDialog1 As New FolderBrowserDialog

' Then use the following code to create the Dialog window
' Change the .SelectedPath property to the default location
With FolderBrowserDialog1
' Desktop is the root folder in the dialog.
.RootFolder = Environment.SpecialFolder.Desktop
' Select the D:\home directory on entry.
If Directory.Exists(strLastPath) Then
.SelectedPath = strLastPath
Else
.SelectedPath = "C:\UGDefault"
End If
' Prompt the user with a custom message.
.Description = "Select the directory to export .pdf file"
If .ShowDialog = DialogResult.OK Then
' Display the selected folder if the user clicked on the OK button.
OutputPath = .SelectedPath
' save the output folder path in the registry for use on next run
SaveSetting("NX journal", "Export pdf", "ExportPath", .SelectedPath)
Else
'user pressed 'cancel', exit the subroutine
OutputPath = 0
'exit sub
End If
End With

End Function
'**********************************************************

Sub ExportPDF(dwg As Drawings.DrawingSheet, outputFile As String, units As Integer, advancePrint As Integer)

Dim printPDFBuilder1 As PrintPDFBuilder

printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder()
printPDFBuilder1.Scale = 1.0
printPDFBuilder1.Action = PrintPDFBuilder.ActionOption.Native
printPDFBuilder1.Colors = PrintPDFBuilder.Color.BlackOnWhite
printPDFBuilder1.Size = PrintPDFBuilder.SizeOption.ScaleFactor
If units = 0 Then
printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.English
Else
printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.Metric
End If
printPDFBuilder1.XDimension = dwg.height
printPDFBuilder1.YDimension = dwg.length
printPDFBuilder1.OutputText = PrintPDFBuilder.OutputTextOption.Polylines
printPDFBuilder1.RasterImages = True
printPDFBuilder1.ImageResolution = PrintPDFBuilder.ImageResolutionOption.Medium
printPDFBuilder1.Append = True
If advancePrint = vbyes Then
printPDFBuilder1.AddWatermark = True
printPDFBuilder1.Watermark = "ADVANCE PRINT NOT TO BE USED FOR PRODUCTION " & Today
Else
printPDFBuilder1.AddWatermark = False
printPDFBuilder1.Watermark = ""
End If

Dim sheets1(0) As NXObject
Dim drawingSheet1 As Drawings.DrawingSheet = CType(dwg, Drawings.DrawingSheet)

sheets1(0) = drawingSheet1
printPDFBuilder1.SourceBuilder.SetSheets(sheets1)

printPDFBuilder1.Filename = outputFile

Dim nXObject1 As NXObject
nXObject1 = printPDFBuilder1.Commit()

printPDFBuilder1.Destroy()

End Sub
'**********************************************************

End Module

Paul Fillion

Thanks big guy, I was able to figure this one out somehow I posted the code for others. I really have an if situation here though. If the rev is a dash - I do not need the constant text and my constant text changes to strConstant = "-01" instead of 'strConstant = "-01-rev"

If
strRevision = workPart.GetStringAttribute("REVISION")= (-) =exportFile = (strDrawing + strConstant)

If
strRevision = workPart.GetStringAttribute("REVISION")= (A or Above) = exportFile = (strDrawing + strConstant + strRevision)

Paul Fillion

Maybe something like this?

Const midText As String = "-01"

If strRevision = "-" Then
exportFile = strDrawing & midText
Else
exportFile = strDrawing & midText & "-rev" & strRevision
End If

Let me see if I have this right; you want the file name format to be:
[DRWG attribute value]-01-rev[REVISION attribute value]
Is this correct?

If so, try the following -
Look for the line of code: "exportFile = currentFile"
and replace it with:

strDrawing = workPart.GetStringAttribute("DRWG")
strRevision = workPart.GetStringAttribute("REVISION")

'exportFile = currentFile
exportFile = strDrawing & "-01-rev" & strRevision & ".pdf"

You might want to wrap the .GetStringAttribute calls in a Try/Catch block, just in case.

Also, comment out the following code:

If rspAdvancePrint = vbyes Then
pdfFile = strOutputFolder & exportFile & "_advance" & ".pdf"
Else
If strRevision <> "" Then
pdfFile = strOutputFolder & exportFile & "_" & strRevision & ".pdf"
Else
pdfFile = strOutputFolder & exportFile & ".pdf"
End If
End If

Yes your idea worked like clock work. Here is the updated code

Option Strict Off
Imports System
Imports System.IO
Imports System.Collections
Imports System.Windows.Forms
Imports System.Windows.Forms.MessageBox
Imports NXOpen
Imports NXOpen.UF

Module NXJournal

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

'**********************************************************

Sub Main

Dim dwgs As Drawings.DrawingSheetCollection
dwgs = workPart.DrawingSheets
Dim sheet As Drawings.DrawingSheet
Dim i As Integer
Dim pdfFile As String
Dim currentPath As String
Dim currentFile As String
Dim exportFile As String
Dim partUnits As Integer
Dim strOutputFolder As String
Dim strRevision As String
Dim rspFileExists
Dim rspAdvancePrint
Dim strDrawing As String
Dim strConstant
Const midText As String = "-01"

'determine if we are running under TC or native
Dim IsTcEng As Boolean = False
Dim UFSes As UFSession = UFSession.GetUFSession()
UFSes.UF.IsUgmanagerActive(IsTcEng)

partUnits = displayPart.PartUnits
'0 = inch
'1 = metric

If IsTcEng Then
currentFile = workPart.GetStringAttribute("DB_PART_NO")
strRevision = workPart.GetStringAttribute("DB_PART_REV")

Else 'running in native mode
'currentFile = GetFilePath() & GetFileName() & ".prt"
currentPath = GetFilePath()
currentFile = GetFileName()

Try
strDrawing = workPart.GetStringAttribute("DRWG")
strRevision = workPart.GetStringAttribute("REVISION")

If strRevision = "-" Then
exportFile = strDrawing & midText
Else
exportFile = strDrawing & midText & "-rev" & strRevision
End If

Catch ex As Exception
strRevision = ""
End Try
End If

strOutputFolder = "N:\LIBRARY\STANDARD DRAWINGS\Standard Drawings\IPD\"

'rspAdvancePrint = MessageBox.Show("Add advance print watermark?", "Add Watermark?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

Dim shts As New ArrayList()
For Each sheet In dwgs
shts.Add(sheet.Name)
Next
shts.Sort()

i = 0
Dim sht As String
For Each sht In shts

For Each sheet In dwgs
If sheet.name = sht Then
i = i + 1

If rspAdvancePrint = vbyes Then
pdfFile = strOutputFolder & exportFile & "_advance" & ".pdf"
Else
If strRevision <> "" Then
pdfFile = strOutputFolder & exportFile & ".pdf"
Else
pdfFile = strOutputFolder & exportFile & ".pdf"
End If
End If

'the pdf export uses 'append file', if we are on sheet 1 make sure the user wants to overwrite
'if the drawing is multisheet, don't ask on subsequent sheets
If i = 1 Then
If File.Exists(pdfFile) Then
rspFileExists = msgbox("The file: '" & pdfFile & "' already exists; overwrite?", vbyesno + vbquestion)
If rspFileExists = vbYes Then
Try
File.Delete(pdfFile)
Catch ex As Exception
msgbox(ex.message & vbcrlf & "Journal exiting", vbcritical + vbokonly, "Error")
Exit Sub
End Try
Else
'msgbox("journal exiting", vbokonly)
Exit Sub
End If
End If
End If

'update any views that are out of date
theSession.Parts.Work.DraftingViews.UpdateViews(Drawings.DraftingViewCollection.ViewUpdateOption.OutOfDate, sheet)

Try
ExportPDF(sheet, pdfFile, partUnits, rspAdvancePrint)
Catch ex As exception
msgbox("Error occurred in PDF export" & vbcrlf & ex.message & vbcrlf & "journal exiting", vbcritical + vbokonly, "Error")
Exit Sub
End Try
Exit For
End If
Next

Next

If i = 0 Then
MessageBox.Show("This part has no drawing sheets to export", "PDF export failure", MessageBoxButtons.ok, MessageBoxIcon.Warning)
Else
MessageBox.Show("Exported: " & i & " sheet(s) to pdf file" & vbcrlf & pdfFile, "PDF export success", MessageBoxButtons.ok, MessageBoxIcon.Information)
End If

End Sub
'**********************************************************

Function GetFileName()
Dim strPath As String
Dim strPart As String
Dim pos As Integer

'get the full file path
strPath = displayPart.fullpath
'get the part file name
pos = InStrRev(strPath, "\")
strPart = Mid(strPath, pos + 1)

strPath = Left(strPath, pos)
'strip off the ".prt" extension
strPart = Left(strPart, Len(strPart) - 4)

GetFileName = strPart
End Function
'**********************************************************

Function GetFilePath()
Dim strPath As String
Dim strPart As String
Dim pos As Integer

'get the full file path
strPath = displayPart.fullpath
'get the part file name
pos = InStrRev(strPath, "\")
strPart = Mid(strPath, pos + 1)

strPath = Left(strPath, pos)
'strip off the ".prt" extension
strPart = Left(strPart, Len(strPart) - 4)

GetFilePath = strPath
End Function
'**********************************************************

Function OutputPath()
'Requires:
' Imports System.IO
' Imports System.Windows.Forms
'if the user presses OK on the dialog box, the chosen path is returned
'if the user presses cancel on the dialog box, 0 is returned

Dim strLastPath As String
Dim strOutputPath As String

'Key will show up in HKEY_CURRENT_USER\Software\VB and VBA Program Settings
Try
'Get the last path used from the registry
strLastPath = GetSetting("NX journal", "Export pdf", "ExportPath")
'msgbox("Last Path: " & strLastPath)
Catch e As ArgumentException
Catch e As Exception
msgbox (e.GetType.ToString)
Finally
End Try

Dim FolderBrowserDialog1 As New FolderBrowserDialog

' Then use the following code to create the Dialog window
' Change the .SelectedPath property to the default location
With FolderBrowserDialog1
' Desktop is the root folder in the dialog.
.RootFolder = Environment.SpecialFolder.Desktop
' Select the D:\home directory on entry.
If Directory.Exists(strLastPath) Then
.SelectedPath = strLastPath
Else
.SelectedPath = "C:\UGDefault"
End If
' Prompt the user with a custom message.
.Description = "Select the directory to export .pdf file"
If .ShowDialog = DialogResult.OK Then
' Display the selected folder if the user clicked on the OK button.
OutputPath = .SelectedPath
' save the output folder path in the registry for use on next run
SaveSetting("NX journal", "Export pdf", "ExportPath", .SelectedPath)
Else
'user pressed 'cancel', exit the subroutine
OutputPath = 0
'exit sub
End If
End With

End Function
'**********************************************************

Sub ExportPDF(dwg As Drawings.DrawingSheet, outputFile As String, units As Integer, advancePrint As Integer)

Dim printPDFBuilder1 As PrintPDFBuilder

printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder()
printPDFBuilder1.Scale = 1.0
printPDFBuilder1.Action = PrintPDFBuilder.ActionOption.Native
printPDFBuilder1.Colors = PrintPDFBuilder.Color.BlackOnWhite
printPDFBuilder1.Size = PrintPDFBuilder.SizeOption.ScaleFactor
If units = 0 Then
printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.English
Else
printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.Metric
End If
printPDFBuilder1.XDimension = dwg.height
printPDFBuilder1.YDimension = dwg.length
printPDFBuilder1.OutputText = PrintPDFBuilder.OutputTextOption.Polylines
printPDFBuilder1.RasterImages = True
printPDFBuilder1.ImageResolution = PrintPDFBuilder.ImageResolutionOption.Medium
printPDFBuilder1.Append = True
If advancePrint = vbyes Then
printPDFBuilder1.AddWatermark = True
printPDFBuilder1.Watermark = "ADVANCE PRINT NOT TO BE USED FOR PRODUCTION " & Today
Else
printPDFBuilder1.AddWatermark = False
printPDFBuilder1.Watermark = ""
End If

Dim sheets1(0) As NXObject
Dim drawingSheet1 As Drawings.DrawingSheet = CType(dwg, Drawings.DrawingSheet)

sheets1(0) = drawingSheet1
printPDFBuilder1.SourceBuilder.SetSheets(sheets1)

printPDFBuilder1.Filename = outputFile

Dim nXObject1 As NXObject
nXObject1 = printPDFBuilder1.Commit()

printPDFBuilder1.Destroy()

End Sub
'**********************************************************

End Module

Paul Fillion

Hello! I used this pattern for export PDF in TCeng. If i set DatasetName like "SomeName/A", the reference PDF file in the dataset "SomeName/A" has next name: "SomeNameSA.pdf". NX transforms "/A" in "SA" automaticaly. I want that reference file could have next name: "SomeName.pdf". Are there any ways to solve this problem?