Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Combine 2 Journals

Status
Not open for further replies.

designnewz

Automotive
Jan 11, 2014
52
Below are 2 Journals to be Run In NX9. Can someone help me to combine[/b].

Journal #1 Journal Number 1 puts a PDF in Teamcenter

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 = strOutputFolder & "\"

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 = "D:\home"
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



Journal #2 Journal Number 2 puts a PDF out in your Local drive

Option Strict Off
Imports System
Imports System.Collections.Generic

Imports NXOpen
Imports NXOpen.Drawings
Imports NXOpen.PDM
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.UI

Module IR_8957521

Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()

Dim workPart As Part = theSession.Parts.Work

Sub Main()

Dim encodedName As String = ""
theUFSession.Part.AskPartName(workPart.Tag, encodedName)
'Echo("Part Name: " & encodedName)
Dim psStat As PartSaveStatus = workPart.Save(BasePart.SaveComponents.False,
BasePart.CloseAfterSave.False)
' decode the part name
' ====================

Dim pNum As String = ""
Dim pRev As String = ""
Dim pfType As String = ""
Dim pfName As String = ""
theUFSession.Ugmgr.DecodePartFileName(encodedName, pNum, pRev, pfType, pfName)
'Echo(pNum)
'Echo(pRev)
'Echo(pfType)
'Echo(pfName)

'Echo("Part name: " & encodedName)

' Create candidate name for the PDF
' =================================

Dim pdfName As String = pNum & "_" & pRev & "_" & "PDF"
'Echo("pdfName: " & pdfName)

' Ask user to verify the name for the PDF
' =======================================

pdfName = NXInputBox.GetInputString("Verify or Change PDF Name:", _
"***** PDF NAME *****", pdfName)

' Get rid of existing PDF
' =======================

MsgBox("If " & pdfName & " exists, please delete it before proceeding.",
MsgBoxStyle.OkOnly)

' Get all of the sheets in the part
' =================================

Dim sheetList() As DrawingSheet = workPart.DrawingSheets.ToArray()
Dim sheetCount As Integer = sheetList.Length()
Echo("Count of Drawing Sheets: " & sheetCount)

If sheetCount.Equals(0) Then
MsgBox("There are no Drawing Sheets.", MsgBoxStyle.Critical)
Return
End If

' Create the builder
' ==================

Dim printPDFBuilder1 As PrintPDFBuilder
printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder()

' Set the other builder options
' =============================

printPDFBuilder1.Colors = PrintPDFBuilder.Color.BlackOnWhite
printPDFBuilder1.Relation = PrintPDFBuilder.RelationOption.Specification
printPDFBuilder1.DatasetType = "PDF"
printPDFBuilder1.NamedReferenceType = "PDF"

printPDFBuilder1.Scale = 1.0
'printPDFBuilder1.Size = PrintPDFBuilder.SizeOption.ScaleFactor
printPDFBuilder1.OutputText = PrintPDFBuilder.OutputTextOption.Polylines
printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.English

printPDFBuilder1.RasterImages = True
printPDFBuilder1.Watermark = ""
printPDFBuilder1.DatasetName = pdfName

printPDFBuilder1.XDimension = sheetList(0).Length
printPDFBuilder1.YDimension = sheetList(0).Height

printPDFBuilder1.Action = PrintPDFBuilder.ActionOption.New

printPDFBuilder1.DatasetType = "PDF"
printPDFBuilder1.NamedReferenceType = "PDF_Reference"

Echo("Sheet # 0 Validate? " & printPDFBuilder1.Validate().ToString())

' Make a new PDF from the first sheet
' ===================================

Dim sheets1(0) As DrawingSheet
sheets1(0) = sheetList(0)
printPDFBuilder1.SourceBuilder.SetSheets(sheets1)

Dim nXObject1 As NXObject
nXObject1 = printPDFBuilder1.Commit()

printPDFBuilder1.Destroy()

If sheetCount.Equals(1) Then
Return
End If

' Append the rest of the sheets
' =============================
For inx As Integer = 1 To sheetCount - 1

printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder()

' Set the other builder options
' =============================

printPDFBuilder1.Colors = PrintPDFBuilder.Color.BlackOnWhite
printPDFBuilder1.Relation = PrintPDFBuilder.RelationOption.Specification
printPDFBuilder1.DatasetType = "PDF"
printPDFBuilder1.NamedReferenceType = "PDF"

printPDFBuilder1.Scale = 1.0
'printPDFBuilder1.Size = PrintPDFBuilder.SizeOption.ScaleFactor
printPDFBuilder1.OutputText = PrintPDFBuilder.OutputTextOption.Polylines
printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.English

printPDFBuilder1.RasterImages = True
printPDFBuilder1.Watermark = ""
printPDFBuilder1.DatasetName = pdfName

printPDFBuilder1.XDimension = sheetList(inx).Length
printPDFBuilder1.YDimension = sheetList(inx).Height

printPDFBuilder1.Action = PrintPDFBuilder.ActionOption.Append

printPDFBuilder1.DatasetType = "PDF"
printPDFBuilder1.NamedReferenceType = "PDF_Reference"

sheets1(0) = sheetList(inx)
printPDFBuilder1.SourceBuilder.SetSheets(sheets1)

Echo("Sheet # " & inx & " Validate? " & printPDFBuilder1.Validate().ToString())
nXObject1 = printPDFBuilder1.Commit()

printPDFBuilder1.Destroy()

Next

End Sub

Sub Echo(ByVal output As String)

theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module
 
Replies continue below

Recommended for you

Hello,

What this new journal have to do?

With best regards
Michael
 
Journal #1 puts a PDF in Teamcenter
Journal #2 puts a PDF out on your Local Drive under a folder or any folder you want.

I want to run these two Journals as one...Objective: Turn two BUTTONS into One Button.
 
Hello,

What I see in code is that You changed the order - 1st puts PDF in folder and the 2nd in TC. I'm not familiar with TC, because we don't use it. Could You send some movie how this process runs? What I see in 1st journal - it can detect, if you're in TC or native. Also in the 2nd You have: encodedName, pNum, pRev, pfType, pfName are they important?

Please run this code, and write yours results.
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 theUFSession As UFSession = UFSession.GetUFSession()
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 partUnits As Integer


'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


	If IsTcEng Then

	 msgbox("Teamcenter: yes")

	Else 'running in native mode

	 msgbox("Teamcenter: no")

	End If


End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
[indent]Return Session.LibraryUnloadOption.Immediately[/indent]
End Function

End Module


With best regards
Michael
 
Hi

This is an as is combine
So if the original journals works so this will work


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

 Imports System.Collections.Generic
 Imports NXOpen.Drawings
 Imports NXOpen.PDM
 Imports NXOpenUI
 Imports NXOpen.UI



 Module NXJournal

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

 Dim theUFSession As UFSession = UFSession.GetUFSession()

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

 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 = strOutputFolder & "\"

 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



'j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2




 Dim encodedName As String = ""
 theUFSession.Part.AskPartName(workPart.Tag, encodedName)
 'Echo("Part Name: " & encodedName)
 Dim psStat As PartSaveStatus = workPart.Save(BasePart.SaveComponents.False,
 BasePart.CloseAfterSave.False)
 ' decode the part name
 ' ====================

 Dim pNum As String = ""
 Dim pRev As String = ""
 Dim pfType As String = ""
 Dim pfName As String = ""
 theUFSession.Ugmgr.DecodePartFileName(encodedName, pNum, pRev, pfType, pfName)
 'Echo(pNum)
 'Echo(pRev)
 'Echo(pfType)
 'Echo(pfName)

 'Echo("Part name: " & encodedName)

 ' Create candidate name for the PDF
 ' =================================

 Dim pdfName As String = pNum & "_" & pRev & "_" & "PDF"
 'Echo("pdfName: " & pdfName)

 ' Ask user to verify the name for the PDF
 ' =======================================

 pdfName = NXInputBox.GetInputString("Verify or Change PDF Name:", _
 "***** PDF NAME *****", pdfName)

 ' Get rid of existing PDF
 ' =======================

 MsgBox("If " & pdfName & " exists, please delete it before proceeding.",
 MsgBoxStyle.OkOnly)

 ' Get all of the sheets in the part
 ' =================================

 Dim sheetList() As DrawingSheet = workPart.DrawingSheets.ToArray()
 Dim sheetCount As Integer = sheetList.Length()
 Echo("Count of Drawing Sheets: " & sheetCount)

 If sheetCount.Equals(0) Then
 MsgBox("There are no Drawing Sheets.", MsgBoxStyle.Critical)
 Return
 End If

 ' Create the builder
 ' ==================

 Dim printPDFBuilder2 As PrintPDFBuilder
 printPDFBuilder2 = workPart.PlotManager.CreatePrintPdfbuilder()

 ' Set the other builder options
 ' =============================

 printPDFBuilder2.Colors = PrintPDFBuilder.Color.BlackOnWhite
 printPDFBuilder2.Relation = PrintPDFBuilder.RelationOption.Specification
 printPDFBuilder2.DatasetType = "PDF"
 printPDFBuilder2.NamedReferenceType = "PDF"

 printPDFBuilder2.Scale = 1.0
 'printPDFBuilder2.Size = PrintPDFBuilder.SizeOption.ScaleFactor
 printPDFBuilder2.OutputText = PrintPDFBuilder.OutputTextOption.Polylines
 printPDFBuilder2.Units = PrintPDFBuilder.UnitsOption.English

 printPDFBuilder2.RasterImages = True
 printPDFBuilder2.Watermark = ""
 printPDFBuilder2.DatasetName = pdfName

 printPDFBuilder2.XDimension = sheetList(0).Length
 printPDFBuilder2.YDimension = sheetList(0).Height

 printPDFBuilder2.Action = PrintPDFBuilder.ActionOption.New

 printPDFBuilder2.DatasetType = "PDF"
 printPDFBuilder2.NamedReferenceType = "PDF_Reference"

 Echo("Sheet # 0 Validate? " & printPDFBuilder2.Validate().ToString())

 ' Make a new PDF from the first sheet
 ' ===================================

 Dim j2_sheets1(0) As DrawingSheet
 j2_sheets1(0) = sheetList(0)
 printPDFBuilder2.SourceBuilder.SetSheets(j2_sheets1)

 Dim j2_nXObject1 As NXObject
 j2_nXObject1 = printPDFBuilder2.Commit()

 printPDFBuilder2.Destroy()

 If sheetCount.Equals(1) Then
 Return
 End If

 ' Append the rest of the sheets
 ' =============================
 For inx As Integer = 1 To sheetCount - 1

 printPDFBuilder2 = workPart.PlotManager.CreatePrintPdfbuilder()

 ' Set the other builder options
 ' =============================

 printPDFBuilder2.Colors = PrintPDFBuilder.Color.BlackOnWhite
 printPDFBuilder2.Relation = PrintPDFBuilder.RelationOption.Specification
 printPDFBuilder2.DatasetType = "PDF"
 printPDFBuilder2.NamedReferenceType = "PDF"

 printPDFBuilder2.Scale = 1.0
 'printPDFBuilder2.Size = PrintPDFBuilder.SizeOption.ScaleFactor
 printPDFBuilder2.OutputText = PrintPDFBuilder.OutputTextOption.Polylines
 printPDFBuilder2.Units = PrintPDFBuilder.UnitsOption.English

 printPDFBuilder2.RasterImages = True
 printPDFBuilder2.Watermark = ""
 printPDFBuilder2.DatasetName = pdfName

 printPDFBuilder2.XDimension = sheetList(inx).Length
 printPDFBuilder2.YDimension = sheetList(inx).Height

 printPDFBuilder2.Action = PrintPDFBuilder.ActionOption.Append

 printPDFBuilder2.DatasetType = "PDF"
 printPDFBuilder2.NamedReferenceType = "PDF_Reference"

 j2_sheets1(0) = sheetList(inx)
 printPDFBuilder2.SourceBuilder.SetSheets(j2_sheets1)

 Echo("Sheet # " & inx & " Validate? " & printPDFBuilder2.Validate().ToString())
 j2_nXObject1 = printPDFBuilder2.Commit()

 printPDFBuilder2.Destroy()

 Next



'j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2j2









 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 = "D:\home"
 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
 '**********************************************************

 Sub Echo(ByVal output As String)

 theSession.ListingWindow.Open()
 theSession.ListingWindow.WriteLine(output)
 theSession.LogFile.WriteLine(output)

 End Sub

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


 End Module
 
Minor changes.
no changes in journal 1 full as is
only variables names changes in journal 2

 
Please I'm curious to know
if the journal run with/without errors.

Because I haven't nxmanager to test!it.
In native its run OK.
 
Didn't You have a problem with this line:

Code:
 theUFSession.Ugmgr.DecodePartFileName(encodedName, pNum, pRev, pfType, pfName)

because I've got an error, about TC.

With best regards
Michael
 
Hi Michael

No, because this line as is and the original 2 journals run OK.

If you run it in native you get error in this line.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor