Enclosed is a Journal to do a File save, Make CGM'S and to Make a PDF.
If the Drawing has multiple sheets the PDF will include all of them. This is also has an overwrite.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Drawings
Imports NXOpen.Annotations
Imports System.Text
Imports System.Windows.Forms
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim BBGpart As Part = theSession.Parts.Work
Dim drawingSheets As DrawingSheet()
Dim BBGSheet As DrawingSheet
DrawingSheets = BBGpart.DrawingSheets.ToArray
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim currentFile as string
Dim strRevision as string
' ----------------------------------------------
' Menu: File->Save
' ----------------------------------------------
Dim partSaveStatus1 As NXOpen.PartSaveStatus
partSaveStatus1 = workPart.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.False)
partSaveStatus1.Dispose()
' ----------------------------------------------
' Export CGM
' ----------------------------------------------
Dim theSheets() As DrawingSheet = workPart.DrawingSheets.ToArray()
If theSheets.Length() < 1 Then
Return
End If
Dim CGMB As CGMBuilder = displayPart.PlotManager.CreateCgmBuilder()
CGMB.Relation = CGMBuilder.RelationOption.Specification
CGMB.DatasetType = "DrawingSheet"
CGMB.NamedReferenceType = "Sheet"
CGMB.Units = CGMBuilder.UnitsOption.English
CGMB.XDimension = 17.0
CGMB.YDimension = 11.0
CGMB.VdcCoordinates = CGMBuilder.Vdc.Real
CGMB.RasterImages = True
CGMB.ImageResolution = CGMBuilder.ImageResolutionOption.High
currentFile = displayPart.GetStringAttribute("DB_PART_NO")
strRevision = displayPart.GetStringAttribute("DB_PART_REV")
Dim dwgSheets(theSheets.GetUpperBound(0)) As NXObject
Dim datasetnames1(theSheets.GetUpperBound(0)) As String
Dim counter As Integer = 0
For Each thisSheet As DrawingSheet In theSheets
dwgSheets(counter) = thisSheet
datasetnames1(counter) = currentFile & "_"& strRevision & "_Sheet_"& (counter +1).ToString
counter += 1
Next
CGMB.SourceBuilder.SetSheets(dwgSheets)
CGMB.SetDatasetNames(datasetnames1)
Dim nXObject1 As NXObject = CGMB.Commit()
CGMB.Destroy()
' ----------------------------------------------
' Menu: File->Export->PDF...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")
Dim printPDFBuilder1 As PrintPDFBuilder
printPDFBuilder1 = BBGpart.PlotManager.CreatePrintPdfbuilder()
printPDFBuilder1.Relation = PrintPDFBuilder.RelationOption.Specification
printPDFBuilder1.DatasetType = "PDF"
printPDFBuilder1.NamedReferenceType = "PDF"
printPDFBuilder1.Scale = 1.0
printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.English
printPDFBuilder1.XDimension = 17.0
printPDFBuilder1.YDimension = 11.0
printPDFBuilder1.Colors = PrintPDFBuilder.Color.BlackOnWhite
printPDFBuilder1.RasterImages = True
printPDFBuilder1.ShadedGeometry = True
printPDFBuilder1.ImageResolution = PrintPDFBuilder.ImageResolutionOption.Medium
printPDFBuilder1.OutputText = PrintPDFBuilder.OutputTextOption.Polylines
printPDFBuilder1.DatasetName = currentFile & "_"& strRevision & "_PDF_1"
Dim partInfo1 As PDM.PartBuilder.PartFileNameData
printPDFBuilder1.Assign()
theSession.SetUndoMarkName(markId1, "Export PDF Dialog")
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Export PDF")
theSession.DeleteUndoMark(markId2, Nothing)
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Export PDF")
printPDFBuilder1.Watermark = ""
Dim mesheets() As NXObject
Dim mesheet As NXObject
For Each BBGSheet In drawingSheets
mesheet = BBGSheet
Next
printPDFBuilder1.SourceBuilder.SetSheets(drawingsheets)
printPDFBuilder1.DatasetName = currentFile & "_"& strRevision & "_PDF_1"
nXObject1 = printPDFBuilder1.Commit()
theSession.DeleteUndoMark(markId3, Nothing)
printPDFBuilder1.Destroy()
theSession.DeleteUndoMark(markId1, Nothing)
End Sub
End Module