Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX9 - Export Entire Assembly to a single PDF? 3

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
949
0
0
US
Someone needs to export his entire assembly to a PDF file, but they want it all to end up on one PDF file. We can do these one at a time and append them but that will take forever. Is there a way to batch PDF an assembly to one PDF file?

As stated in the title, this is NX9.
Our model and drafting is in the same files, if that makes a difference.
This is an assembly with the details as separate part files and brought in as components.


Thankyou for any help anyone can offer.
 
Replies continue below

Recommended for you

PDFs of the model or drawings?
With some programming/scripting you could possibly cycle through al of the component files in the drafting application and print the PDFs, but the would be individual files. These could then be combined by the script.


"Wildfires are dangerous, hard to control, and economically catastrophic."

Ben Loosli
 
They definitely need the drawings from the drafting side.

As for the rest of what you said, it made little sense to me. Sorry.
 
Manually select all required sheets before exporting to PDF, hope this what you are looking for. Later you may built script to automate the process.
 
switch to drafting go to file->Export->PDF in first window select required sheets or you can arrange sheet sequence in which order you want. make sure select required sheets after arranging. Select file browser and locate the file. All sheets will be in one file
 
Thanks for the help and I do appreciate it, but I think either my needs are not understood or I am misunderstanding something in the answers.

This looks like it does the PDF for the assembly drawings. However, on this occasion, our customer wants everything on one PDF. Including the details drafting sheets. So if an assembly has 6 make details in it, we will needs the assembly drafting sheets, the BOMs, and the drafting sheets for all 6 details to show up in one PDF.
 
I You wanna export all sheets of drawing You have to select all of them. Look at my attached picture. In this example I have 2 sheets, and I selected them.

picture_ep8tq8.png


You can always use journal to do the job for You.
Here is my personalized journal to export PDF. It create folder "PDF" in place where part file is.

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
 
'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()
strOutputFolder = CurrentPath + "PDF"

'if we don't have a valid directory (ie the user pressed 'cancel') exit the journal

If (Not System.IO.Directory.Exists(strOutputFolder)) Then
		System.IO.Directory.CreateDirectory(strOutputFolder)
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
'**********************************************************
 
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




With best regards
Michael
 
Niedzviedz, what you picture describes will only give me the sheets in the main assembly. It will not create a PDF of all of the detail components as well and add them as part of the same PDF. I am not good enough with code to read your code and know what it will do, but I have to assume that if you are misunderstanding what I want in the picture, the code would not be any different. If an assembly has a clamp detail, two block details and a bracket detail, along with 10 standard components, I need the PDF to have the drawing sheets from the assembly as well as the drawing sheets for the four details in the one PDF.

Ivan, .... If only this world was set up where my bosses would buy every program I wanted from them. :eek:)

Cowski, I will look at the link.

Again, I do thank all of you for your time and help. :)
 
Hey cowski

Your code did the job with one problem, and I am not sure how easy that would be to fix. I had the guy who needed it run this journal on a small assembly to test it and it worked, but the sheets were out of order. The assemblies drawing sheets were together but they were out of order, then the detail sheets were out of order as well.

However, I do want to be clear that this job has lost its importance at this time because the gentleman who needed this ran PDFs the normal way for the assembly, then did the details individually and appended them to the assembly PDF. I was trying to find a way to make the job easier but he went ahead and did it the hard way because it is not the usual job for us. So if you were to address the code putting the sheets out of order, it would be more for just fixing the problem than for what is needed at this time. I just wanted to let you know so you don't spend time on it thinking it was still needed.

But if you ever do get free time in the future and dig into it. I wouldn't mind having that in case anything else comes up in the future like this job. lol Just no hurry on it.
 
Status
Not open for further replies.
Back
Top