×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

JOURNAL HELP TO EXPORT VIEWS TO PDF

JOURNAL HELP TO EXPORT VIEWS TO PDF

JOURNAL HELP TO EXPORT VIEWS TO PDF

(OP)
I have recorded a journal to export a model view to append to a pdf, I used the record feature because I have no programing experiance. We are creating views in modeling with PMI definition, the format that we use to name the views is MBD_01_Discription ( all views start with MBD_ then a 2 digit number starting at 01 and up, then _with a discription of the view). We have a drawing view in tha model that we have a format on, this we export as a pdf, then go to each view and export as an appended pdf. I would like to have a journal export append a pdf of all of the MBD_XX views in order. the quantity of numbered views varies per part, but never more than 100 views.

Thanks!

RE: JOURNAL HELP TO EXPORT VIEWS TO PDF

I was working on a journal a few months ago that exported all the saved views to a pdf file. It might be fairly easy to adapt that one to your needs, but I'm not sure I understand the workflow.

Quote (STDETMER)

We have a drawing view in the model that we have a format on, this we export as a pdf, then go to each view and export as an appended pdf.

The first view is of your format (drawing title block)? Other views after that are appended, so they get their own sheet in the pdf file. Only the first view has the format? Do you need a certain sheet size and/or view scale for the views?

www.nxjournaling.com

RE: JOURNAL HELP TO EXPORT VIEWS TO PDF

(OP)
Yes the first page is a drawing sheet (E-size) in the model (like a mono-detail) with the company format, because the format contains attributes that are used when the files are issued and input into the Digital workbench ( a network database ) But the journal really doesn't need to export the drawing sheet, We save the PDF of the drawing sheet formatted as the drawing number.
the tedious part is going to each view and appending it to the pdf. we export each view set at E-size 43x33 to match the first drawing sheet. i've changed my customer defaults so the views retain its size as saved, so I dont have to restore the view every time I open it.

Hope that makes sence.

Thanks !

RE: JOURNAL HELP TO EXPORT VIEWS TO PDF

Below is the journal I mentioned. In its current form it creates an "A" (or A4) size sheet for each model view then exports all of them to a pdf file. Try it out on a file that only has a few custom views and let me know if you think this is something that can be modified to your use or is headed the wrong direction entirely. I already know that
  1. drawings should be "E" size
  2. only views starting with "MBD_" should be exported
I suspect there will be other changes as well.

CODE

'NXJournaling.com 'March 21, 2012 'Journal purpose: export shaded model views to a pdf file ' the journal creates an "A" or "A4" size sheet for each model view, places ' the view on the sheet and scales it to fit. The journal then exports all ' the sheets to the specified pdf file Option Strict Off Imports System Imports System.IO Imports System.Windows.Forms Imports System.Collections Imports NXOpen Module Export_Shaded_pdf Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Dim ufs As UF.UFSession = UF.UFSession.GetUFSession() Dim pdfSheets As New ArrayList Sub Main() Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start") theSession.SetUndoMarkName(markId1, "pdf_sheets") Dim pdfSheet As Drawings.DrawingSheet Dim outputFileName(1) As String Dim pdfFile As String Dim wpModelingView As ModelingView For Each wpModelingView In workPart.ModelingViews 'create new sheet for view pdfSheet = CreateSheet() pdfSheet.SetName(wpModelingView.Name) 'add view to new sheet AddView(wpModelingView, pdfSheet) pdfSheets.Add(pdfSheet) Next outputFileName(0) = OutputPath() outputFileName(1) = Path.GetFileNameWithoutExtension(workPart.FullPath) & ".pdf" pdfFile = Path.Combine(outputFileName(0), outputFileName(1)) If My.Computer.FileSystem.FileExists(pdfFile) Then My.Computer.FileSystem.DeleteFile(pdfFile) End If 'output new sheets to pdf Try Call CreatePDF(pdfFile) Catch ex As UnauthorizedAccessException MessageBox.Show("You do not have permission to write to this directory", "PDF file creation error", MessageBoxButtons.OK, MessageBoxIcon.Error) Catch ex As ApplicationException MessageBox.Show(ex.Message, "PDF file creation error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try 'optional: delete pdf sheets Dim markId2 As Session.UndoMarkId markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete") Dim objects1(pdfSheets.Count - 1) As NXObject For i As Integer = 0 To pdfSheets.Count - 1 objects1(i) = pdfSheets.Item(i) Next pdfSheets.Clear() Dim nErrs1 As Integer nErrs1 = theSession.UpdateManager.AddToDeleteList(objects1) Dim notifyOnDelete2 As Boolean notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete Dim nErrs2 As Integer nErrs2 = theSession.UpdateManager.DoUpdate(markId2) End Sub Public Function CreateSheet() As Drawings.DrawingSheet ' ---------------------------------------------- ' Menu: Insert->Sheet... ' ---------------------------------------------- 'Dim markId1 As Session.UndoMarkId 'markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start") Dim nullDrawings_DrawingSheet As Drawings.DrawingSheet = Nothing Dim drawingSheetBuilder1 As Drawings.DrawingSheetBuilder drawingSheetBuilder1 = workPart.DrawingSheets.DrawingSheetBuilder(nullDrawings_DrawingSheet) drawingSheetBuilder1.Option = Drawings.DrawingSheetBuilder.SheetOption.StandardSize 'start with 1:1 scale sheet, view will be scaled to fit later drawingSheetBuilder1.ScaleNumerator = 1.0 drawingSheetBuilder1.ScaleDenominator = 1.0 If workPart.PartUnits = Part.Units.Inches Then drawingSheetBuilder1.Units = Drawings.DrawingSheetBuilder.SheetUnits.English 'insert standard letter size sheet drawingSheetBuilder1.Height = 8.5 drawingSheetBuilder1.Length = 11.0 Else 'metric unit file drawingSheetBuilder1.Units = Drawings.DrawingSheetBuilder.SheetUnits.Metric 'insert standard A4 size sheet drawingSheetBuilder1.Height = 210 drawingSheetBuilder1.Length = 297 End If 'sheetLength = drawingSheetBuilder1.Length 'sheetHeight = drawingSheetBuilder1.Height drawingSheetBuilder1.ProjectionAngle = Drawings.DrawingSheetBuilder.SheetProjectionAngle.Third Dim pdfSheet As Drawings.DrawingSheet pdfSheet = drawingSheetBuilder1.Commit() 'theSession.SetUndoMarkName(markId1, "##01Sheet") drawingSheetBuilder1.Destroy() Return pdfSheet End Function Public Sub AddView(ByVal view As ModelingView, ByVal sheet As Drawings.DrawingSheet) ' ---------------------------------------------- ' Menu: Insert->View->Base... ' ---------------------------------------------- 'Dim markId3 As Session.UndoMarkId 'markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start") sheet.Open() Dim nullDrawings_BaseView As Drawings.BaseView = Nothing Dim baseViewBuilder1 As Drawings.BaseViewBuilder baseViewBuilder1 = workPart.DraftingViews.CreateBaseViewBuilder(nullDrawings_BaseView) baseViewBuilder1.SelectModelView.SelectedView = view 'theSession.SetUndoMarkName(markId3, "Base View Dialog") baseViewBuilder1.Style.ViewStyleBase.Part = workPart baseViewBuilder1.Style.ViewStyleBase.PartName = workPart.FullPath Dim arrangement1 As Assemblies.Arrangement = workPart.ComponentAssembly.ActiveArrangement baseViewBuilder1.Style.ViewStyleBase.Arrangement.SelectedArrangement = arrangement1 baseViewBuilder1.Style.ViewStyleShading.RenderingStyle = Preferences.ShadingRenderingStyleOption.FullyShaded 'place the view in the center of the sheet Dim point1 As Point3d = New Point3d(sheet.Length / 2, sheet.Height / 2, 0.0) baseViewBuilder1.Placement.Placement.SetValue(Nothing, workPart.Views.WorkView, point1) Dim baseView1 As Drawings.BaseView baseView1 = baseViewBuilder1.Commit() 'theSession.SetUndoMarkName(markId3, "Base View") Dim viewSize(3) As Double 'retrieve the size of the view ufs.Draw.AskViewBorders(baseView1.Tag, viewSize) Dim viewLength As Double = viewSize(2) - viewSize(0) Dim viewHeight As Double = viewSize(3) - viewSize(1) 'change scale of view so that it fits on 90% of the selected sheet size baseView1.Style.General.Scale = Math.Min((sheet.Length * 0.9) / viewLength, (sheet.Height * 0.9) / viewHeight) baseView1.Commit() baseViewBuilder1.Destroy() End Sub Public Sub CreatePDF(ByVal outputFile As String) 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 printPDFBuilder1.Units = workPart.PartUnits 'If units = 0 Then ' printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.English 'Else ' printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.Metric 'End If printPDFBuilder1.XDimension = pdfSheets.Item(1).Height printPDFBuilder1.YDimension = pdfSheets.Item(1).Length printPDFBuilder1.OutputText = PrintPDFBuilder.OutputTextOption.Polylines printPDFBuilder1.RasterImages = True printPDFBuilder1.ImageResolution = PrintPDFBuilder.ImageResolutionOption.Medium printPDFBuilder1.Append = True printPDFBuilder1.AddWatermark = False Dim sheets1(pdfSheets.Count - 1) As NXObject 'Dim drawingSheet1 As Drawings.DrawingSheet = CType(dwg, Drawings.DrawingSheet) For i As Integer = 0 To pdfSheets.Count - 1 sheets1(i) = pdfSheets.Item(i) Next 'sheets1(0) = drawingSheet1 printPDFBuilder1.SourceBuilder.SetSheets(sheets1) printPDFBuilder1.Filename = outputFile 'printPDFBuilder1.Filename = "C:\Temp\test.pdf" Dim nXObject1 As NXObject nXObject1 = printPDFBuilder1.Commit() printPDFBuilder1.Destroy() End Sub 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 = Environment.SpecialFolder.MyDocuments 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 End If End With End Function Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination End Function End Module

www.nxjournaling.com

RE: JOURNAL HELP TO EXPORT VIEWS TO PDF

(OP)
Thanks! I'll give it a shot. It's nice it has discriptions, maybe I can try to understand how this works.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources