Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

JOURNAL HELP TO EXPORT VIEWS TO PDF

Status
Not open for further replies.

STDETMER

Aerospace
Jan 5, 2012
10
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!
 
Replies continue below

Recommended for you

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.

STDETMER said:
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
 
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 !
 
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 [ol 1]
[li]drawings should be "E" size[/li] [li]only views starting with "MBD_" should be exported[/li]
[/ol]
I suspect there will be other changes as well.

Code:
[COLOR=green]'NXJournaling.com[/color]
[COLOR=green]'March 21, 2012[/color]
[COLOR=green]'Journal purpose: export shaded model views to a pdf file[/color]
[COLOR=green]'  the journal creates an "A" or "A4" size sheet for each model view, places[/color]
[COLOR=green]'  the view on the sheet and scales it to fit. The journal then exports all[/color]
[COLOR=green]'  the sheets to the specified pdf file[/color]

[COLOR=blue]Option[/color] [COLOR=blue]Strict[/color] [COLOR=blue]Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] System.IO  
[COLOR=blue]Imports[/color] System.Windows.Forms  
[COLOR=blue]Imports[/color] System.Collections  
[COLOR=blue]Imports[/color] NXOpen  

[COLOR=blue]Module[/color] Export_Shaded_pdf  

    [COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  
    [COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work  
    [COLOR=blue]Dim[/color] ufs [COLOR=blue]As[/color] UF.UFSession [COLOR=blue]=[/color] UF.UFSession.GetUFSession()  

    [COLOR=blue]Dim[/color] pdfSheets [COLOR=blue]As[/color] [COLOR=blue]New[/color] ArrayList  

    [COLOR=blue]Sub[/color] Main()  

        [COLOR=blue]Dim[/color] markId1 [COLOR=blue]As[/color] Session.UndoMarkId  
        markId1 [COLOR=blue]=[/color] theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")  
        theSession.SetUndoMarkName(markId1, "pdf_sheets")  

        [COLOR=blue]Dim[/color] pdfSheet [COLOR=blue]As[/color] Drawings.DrawingSheet  
        [COLOR=blue]Dim[/color] outputFileName(1) [COLOR=blue]As[/color] [COLOR=blue]String[/color]  
        [COLOR=blue]Dim[/color] pdfFile [COLOR=blue]As[/color] [COLOR=blue]String[/color]  

        [COLOR=blue]Dim[/color] wpModelingView [COLOR=blue]As[/color] ModelingView  
        [COLOR=blue]For[/color] [COLOR=blue]Each[/color] wpModelingView [COLOR=blue]In[/color] workPart.ModelingViews  
 [COLOR=green]'create new sheet for view[/color]
            pdfSheet [COLOR=blue]=[/color] CreateSheet()  
            pdfSheet.SetName(wpModelingView.Name)  
 [COLOR=green]'add view to new sheet[/color]
            AddView(wpModelingView, pdfSheet)  
            pdfSheets.Add(pdfSheet)  
        [COLOR=blue]Next[/color]  

        outputFileName(0) [COLOR=blue]=[/color] OutputPath()  
        outputFileName(1) [COLOR=blue]=[/color] Path.GetFileNameWithoutExtension(workPart.FullPath) [COLOR=blue]&[/color] ".pdf"  
        pdfFile [COLOR=blue]=[/color] Path.Combine(outputFileName(0), outputFileName(1))  

        [COLOR=blue]If[/color] My.Computer.FileSystem.FileExists(pdfFile) [COLOR=blue]Then[/color]  
            My.Computer.FileSystem.DeleteFile(pdfFile)  
        End [COLOR=blue]If[/color]  

 [COLOR=green]'output new sheets to pdf[/color]
        [COLOR=blue]Try[/color]  
            [COLOR=blue]Call[/color] CreatePDF(pdfFile)  
        [COLOR=blue]Catch[/color] ex [COLOR=blue]As[/color] UnauthorizedAccessException  
            MessageBox.Show("You [COLOR=blue]do[/color] [COLOR=blue]not[/color] have permission [COLOR=blue]to[/color] write [COLOR=blue]to[/color] this directory", "PDF file creation error", MessageBoxButtons.OK, MessageBoxIcon.Error)  
        [COLOR=blue]Catch[/color] ex [COLOR=blue]As[/color] ApplicationException  
            MessageBox.Show(ex.Message, "PDF file creation error", MessageBoxButtons.OK, MessageBoxIcon.Error)  
        End [COLOR=blue]Try[/color]  

 [COLOR=green]'optional: delete pdf sheets[/color]
        [COLOR=blue]Dim[/color] markId2 [COLOR=blue]As[/color] Session.UndoMarkId  
        markId2 [COLOR=blue]=[/color] theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")  

        [COLOR=blue]Dim[/color] objects1(pdfSheets.Count [COLOR=blue]-[/color] 1) [COLOR=blue]As[/color] NXObject  
        [COLOR=blue]For[/color] i [COLOR=blue]As[/color] [COLOR=blue]Integer[/color] [COLOR=blue]=[/color] 0 [COLOR=blue]To[/color] pdfSheets.Count [COLOR=blue]-[/color] 1  
            objects1(i) [COLOR=blue]=[/color] pdfSheets.Item(i)  
        [COLOR=blue]Next[/color]  
        pdfSheets.Clear()  

        [COLOR=blue]Dim[/color] nErrs1 [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  
        nErrs1 [COLOR=blue]=[/color] theSession.UpdateManager.AddToDeleteList(objects1)  

        [COLOR=blue]Dim[/color] notifyOnDelete2 [COLOR=blue]As[/color] [COLOR=blue]Boolean[/color]  
        notifyOnDelete2 [COLOR=blue]=[/color] theSession.Preferences.Modeling.NotifyOnDelete  

        [COLOR=blue]Dim[/color] nErrs2 [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  
        nErrs2 [COLOR=blue]=[/color] theSession.UpdateManager.DoUpdate(markId2)  


    End [COLOR=blue]Sub[/color]  

    [COLOR=blue]Public[/color] [COLOR=blue]Function[/color] CreateSheet() [COLOR=blue]As[/color] Drawings.DrawingSheet  
 [COLOR=green]' ----------------------------------------------[/color]
 [COLOR=green]'   Menu: Insert->Sheet...[/color]
 [COLOR=green]' ----------------------------------------------[/color]

 [COLOR=green]'Dim markId1 As Session.UndoMarkId[/color]
 [COLOR=green]'markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")[/color]

        [COLOR=blue]Dim[/color] nullDrawings_DrawingSheet [COLOR=blue]As[/color] Drawings.DrawingSheet [COLOR=blue]=[/color] [COLOR=blue]Nothing[/color]  

        [COLOR=blue]Dim[/color] drawingSheetBuilder1 [COLOR=blue]As[/color] Drawings.DrawingSheetBuilder  
        drawingSheetBuilder1 [COLOR=blue]=[/color] workPart.DrawingSheets.DrawingSheetBuilder(nullDrawings_DrawingSheet)  

        drawingSheetBuilder1.Option [COLOR=blue]=[/color] Drawings.DrawingSheetBuilder.SheetOption.StandardSize  
 [COLOR=green]'start with 1:1 scale sheet, view will be scaled to fit later[/color]
        drawingSheetBuilder1.ScaleNumerator [COLOR=blue]=[/color] 1.0  
        drawingSheetBuilder1.ScaleDenominator [COLOR=blue]=[/color] 1.0  

        [COLOR=blue]If[/color] workPart.PartUnits [COLOR=blue]=[/color] Part.Units.Inches [COLOR=blue]Then[/color]  
            drawingSheetBuilder1.Units [COLOR=blue]=[/color] Drawings.DrawingSheetBuilder.SheetUnits.English  
 [COLOR=green]'insert standard letter size sheet[/color]
            drawingSheetBuilder1.Height [COLOR=blue]=[/color] 8.5  
            drawingSheetBuilder1.Length [COLOR=blue]=[/color] 11.0  
[COLOR=blue]Else[/color]  [COLOR=green]'metric unit file[/color]
            drawingSheetBuilder1.Units [COLOR=blue]=[/color] Drawings.DrawingSheetBuilder.SheetUnits.Metric  
 [COLOR=green]'insert standard A4 size sheet[/color]
            drawingSheetBuilder1.Height [COLOR=blue]=[/color] 210  
            drawingSheetBuilder1.Length [COLOR=blue]=[/color] 297  
        End [COLOR=blue]If[/color]  

 [COLOR=green]'sheetLength = drawingSheetBuilder1.Length[/color]
 [COLOR=green]'sheetHeight = drawingSheetBuilder1.Height[/color]

        drawingSheetBuilder1.ProjectionAngle [COLOR=blue]=[/color] Drawings.DrawingSheetBuilder.SheetProjectionAngle.Third  

        [COLOR=blue]Dim[/color] pdfSheet [COLOR=blue]As[/color] Drawings.DrawingSheet  
        pdfSheet [COLOR=blue]=[/color] drawingSheetBuilder1.Commit()  

 [COLOR=green]'theSession.SetUndoMarkName(markId1, "##01Sheet")[/color]

        drawingSheetBuilder1.Destroy()  

        [COLOR=blue]Return[/color] pdfSheet  

    End [COLOR=blue]Function[/color]  

    [COLOR=blue]Public[/color] [COLOR=blue]Sub[/color] AddView(ByVal view [COLOR=blue]As[/color] ModelingView, [COLOR=blue]ByVal[/color] sheet [COLOR=blue]As[/color] Drawings.DrawingSheet)  
 [COLOR=green]' ----------------------------------------------[/color]
 [COLOR=green]'   Menu: Insert->View->Base...[/color]
 [COLOR=green]' ----------------------------------------------[/color]
 [COLOR=green]'Dim markId3 As Session.UndoMarkId[/color]
 [COLOR=green]'markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")[/color]

        sheet.Open()  

        [COLOR=blue]Dim[/color] nullDrawings_BaseView [COLOR=blue]As[/color] Drawings.BaseView [COLOR=blue]=[/color] [COLOR=blue]Nothing[/color]  

        [COLOR=blue]Dim[/color] baseViewBuilder1 [COLOR=blue]As[/color] Drawings.BaseViewBuilder  
        baseViewBuilder1 [COLOR=blue]=[/color] workPart.DraftingViews.CreateBaseViewBuilder(nullDrawings_BaseView)  

        baseViewBuilder1.SelectModelView.SelectedView [COLOR=blue]=[/color] view  

 [COLOR=green]'theSession.SetUndoMarkName(markId3, "Base View Dialog")[/color]

        baseViewBuilder1.Style.ViewStyleBase.Part [COLOR=blue]=[/color] workPart  

        baseViewBuilder1.Style.ViewStyleBase.PartName [COLOR=blue]=[/color] workPart.FullPath  

        [COLOR=blue]Dim[/color] arrangement1 [COLOR=blue]As[/color] Assemblies.Arrangement [COLOR=blue]=[/color] workPart.ComponentAssembly.ActiveArrangement  

        baseViewBuilder1.Style.ViewStyleBase.Arrangement.SelectedArrangement [COLOR=blue]=[/color] arrangement1  

        baseViewBuilder1.Style.ViewStyleShading.RenderingStyle [COLOR=blue]=[/color] Preferences.ShadingRenderingStyleOption.FullyShaded  

 [COLOR=green]'place the view in the center of the sheet[/color]
        [COLOR=blue]Dim[/color] point1 [COLOR=blue]As[/color] Point3d [COLOR=blue]=[/color] [COLOR=blue]New[/color] Point3d(sheet.Length [COLOR=blue]/[/color] 2, sheet.Height [COLOR=blue]/[/color] 2, 0.0)  
        baseViewBuilder1.Placement.Placement.SetValue(Nothing, workPart.Views.WorkView, point1)  

        [COLOR=blue]Dim[/color] baseView1 [COLOR=blue]As[/color] Drawings.BaseView  
        baseView1 [COLOR=blue]=[/color] baseViewBuilder1.Commit()  

 [COLOR=green]'theSession.SetUndoMarkName(markId3, "Base View")[/color]

        [COLOR=blue]Dim[/color] viewSize(3) [COLOR=blue]As[/color] [COLOR=blue]Double[/color]  
 [COLOR=green]'retrieve the size of the view[/color]
        ufs.Draw.AskViewBorders(baseView1.Tag, viewSize)  
        [COLOR=blue]Dim[/color] viewLength [COLOR=blue]As[/color] [COLOR=blue]Double[/color] [COLOR=blue]=[/color] viewSize(2) [COLOR=blue]-[/color] viewSize(0)  
        [COLOR=blue]Dim[/color] viewHeight [COLOR=blue]As[/color] [COLOR=blue]Double[/color] [COLOR=blue]=[/color] viewSize(3) [COLOR=blue]-[/color] viewSize(1)  

 [COLOR=green]'change scale of view so that it fits on 90% of the selected sheet size[/color]
        baseView1.Style.General.Scale [COLOR=blue]=[/color] Math.Min((sheet.Length [COLOR=blue]*[/color] 0.9) [COLOR=blue]/[/color] viewLength, (sheet.Height [COLOR=blue]*[/color] 0.9) [COLOR=blue]/[/color] viewHeight)  

        baseView1.Commit()  

        baseViewBuilder1.Destroy()  

    End [COLOR=blue]Sub[/color]  

    [COLOR=blue]Public[/color] [COLOR=blue]Sub[/color] CreatePDF(ByVal outputFile [COLOR=blue]As[/color] [COLOR=blue]String[/color])  
        [COLOR=blue]Dim[/color] printPDFBuilder1 [COLOR=blue]As[/color] PrintPDFBuilder  

        printPDFBuilder1 [COLOR=blue]=[/color] workPart.PlotManager.CreatePrintPdfbuilder()  
        printPDFBuilder1.Scale [COLOR=blue]=[/color] 1.0  
        printPDFBuilder1.Action [COLOR=blue]=[/color] PrintPDFBuilder.ActionOption.Native  
        printPDFBuilder1.Colors [COLOR=blue]=[/color] PrintPDFBuilder.Color.BlackOnWhite  
        printPDFBuilder1.Size [COLOR=blue]=[/color] PrintPDFBuilder.SizeOption.ScaleFactor  
        printPDFBuilder1.Units [COLOR=blue]=[/color] workPart.PartUnits  
 [COLOR=green]'If units = 0 Then[/color]
 [COLOR=green]'    printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.English[/color]
 [COLOR=green]'Else[/color]
 [COLOR=green]'    printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.Metric[/color]
 [COLOR=green]'End If[/color]
        printPDFBuilder1.XDimension [COLOR=blue]=[/color] pdfSheets.Item(1).Height  
        printPDFBuilder1.YDimension [COLOR=blue]=[/color] pdfSheets.Item(1).Length  
        printPDFBuilder1.OutputText [COLOR=blue]=[/color] PrintPDFBuilder.OutputTextOption.Polylines  
        printPDFBuilder1.RasterImages [COLOR=blue]=[/color] [COLOR=blue]True[/color]  
        printPDFBuilder1.ImageResolution [COLOR=blue]=[/color] PrintPDFBuilder.ImageResolutionOption.Medium  
        printPDFBuilder1.Append [COLOR=blue]=[/color] [COLOR=blue]True[/color]  
        printPDFBuilder1.AddWatermark [COLOR=blue]=[/color] [COLOR=blue]False[/color]  

        [COLOR=blue]Dim[/color] sheets1(pdfSheets.Count [COLOR=blue]-[/color] 1) [COLOR=blue]As[/color] NXObject  
 [COLOR=green]'Dim drawingSheet1 As Drawings.DrawingSheet = CType(dwg, Drawings.DrawingSheet)[/color]
        [COLOR=blue]For[/color] i [COLOR=blue]As[/color] [COLOR=blue]Integer[/color] [COLOR=blue]=[/color] 0 [COLOR=blue]To[/color] pdfSheets.Count [COLOR=blue]-[/color] 1  
            sheets1(i) [COLOR=blue]=[/color] pdfSheets.Item(i)  
        [COLOR=blue]Next[/color]  

 [COLOR=green]'sheets1(0) = drawingSheet1[/color]
        printPDFBuilder1.SourceBuilder.SetSheets(sheets1)  

        printPDFBuilder1.Filename [COLOR=blue]=[/color] outputFile  
 [COLOR=green]'printPDFBuilder1.Filename = "C:\Temp\test.pdf"[/color]

        [COLOR=blue]Dim[/color] nXObject1 [COLOR=blue]As[/color] NXObject  
        nXObject1 [COLOR=blue]=[/color] printPDFBuilder1.Commit()  

        printPDFBuilder1.Destroy()  

    End [COLOR=blue]Sub[/color]  

    [COLOR=blue]Function[/color] OutputPath()  
 [COLOR=green]'Requires:[/color]
 [COLOR=green]'    Imports System.IO[/color]
 [COLOR=green]'    Imports System.Windows.Forms[/color]
 [COLOR=green]'if the user presses OK on the dialog box, the chosen path is returned[/color]
 [COLOR=green]'if the user presses cancel on the dialog box, 0 is returned[/color]

        [COLOR=blue]Dim[/color] strLastPath [COLOR=blue]As[/color] [COLOR=blue]String[/color]  
        [COLOR=blue]Dim[/color] strOutputPath [COLOR=blue]As[/color] [COLOR=blue]String[/color]  

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

        [COLOR=blue]Dim[/color] FolderBrowserDialog1 [COLOR=blue]As[/color] [COLOR=blue]New[/color] FolderBrowserDialog  

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

    End [COLOR=blue]Function[/color]  


    [COLOR=blue]Public[/color] [COLOR=blue]Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As[/color] [COLOR=blue]String[/color]) [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  

 [COLOR=green]'Unloads the image when the NX session terminates[/color]
        GetUnloadOption [COLOR=blue]=[/color] NXOpen.Session.LibraryUnloadOption.AtTermination  

    End [COLOR=blue]Function[/color]  

End [COLOR=blue]Module[/color]


www.nxjournaling.com
 
Thanks! I'll give it a shot. It's nice it has discriptions, maybe I can try to understand how this works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor