Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

2d exchange dxf journal

Status
Not open for further replies.

moog2

Mechanical
Jan 16, 2007
441
I have a good DXF/CGM export journal kindly supplied by Cowski, but now i have to use the 2D exchange export for some companies.
Does anyone have a journal to export all drawing sheets to a selected folder, using the 2d exchange.... (NX8 currently, but soon NX9)
Any help appreciated
 
Replies continue below

Recommended for you

Use the OOTB from NX converters.

Thank you...

Using NX 8 and PDM RuleDesigner
 
they're not user freindly, i want a button on my drafting toolbar, i can hit after i've done the drawing.
 
Can you record a journal while using the 2D exchange? If code is recorded during the process, it should give us a good head start.

www.nxjournaling.com
 
oops, forgot to check the thread...
sure, here's what i recorded...

' NX 8.0.3.4
' Journal created by paulhorton on Tue Nov 11 14:55:27 2014 E. Australia Standard Time
'
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main

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

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: File->Export->2D Exchange...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim nXTo2dCreator1 As NXTo2dCreator
nXTo2dCreator1 = theSession.DexManager.CreateNxto2dCreator()

nXTo2dCreator1.AutoCADRevision = NXTo2dCreator.AutoCADRevisionOption.R2007

nXTo2dCreator1.MaxSystem3DModelSpace = True

nXTo2dCreator1.MaxSystemPointRes = True

nXTo2dCreator1.SpCurveTolerance = 0.0508

nXTo2dCreator1.MaxUser3DModelSpace = 10000.0

nXTo2dCreator1.MaxUserPointRes = 0.001

nXTo2dCreator1.OutputFileType = NXTo2dCreator.OutputAsOption.DWGFile

nXTo2dCreator1.Nxto2dSettingsFile = "C:\Program Files\Siemens\NX 8.0\ugto2d\ugto2d.def"

nXTo2dCreator1.FacetBodies = True

nXTo2dCreator1.AutoCADRevision = NXTo2dCreator.AutoCADRevisionOption.R14

nXTo2dCreator1.DxfSettingsFile = "C:\Program Files\Siemens\NX 8.0\dxfdwg\dxfdwg.def"

nXTo2dCreator1.InputFile = "\\Bus-local-srv08\Desktop\paulhorton\Desktop\TEST-DUMMY\CHCD-BK20_dwg.prt"

nXTo2dCreator1.OutputFile = "C:\TEMP\CHCD-BK20_dwg_2d.dwg"

nXTo2dCreator1.ExportData = NXTo2dCreator.ExportDataOption.Drawing

theSession.SetUndoMarkName(markId1, "2D Exchange Options Dialog")

nXTo2dCreator1.OutputFileType = NXTo2dCreator.OutputAsOption.DXFFile

nXTo2dCreator1.OutputFile = "C:\TEMP\CHCD-BK20_dwg_2d.dxf"

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "2D Exchange Options")

nXTo2dCreator1.DrawingName = "SH1"

nXTo2dCreator1.ViewName = "TOP"

Dim nXObject1 As NXObject
nXObject1 = nXTo2dCreator1.Commit()

theSession.DeleteUndoMark(markId2, Nothing)

theSession.SetUndoMarkName(markId1, "2D Exchange Options")

nXTo2dCreator1.Destroy()

(fingers crossed.....)
 
think i forgot to stop that one.... here's another

' NX 8.0.3.4
' Journal created by paulhorton on Tue Nov 11 15:05:08 2014 E. Australia Standard Time
'
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main

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

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: File->Export->2D Exchange...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim nXTo2dCreator1 As NXTo2dCreator
nXTo2dCreator1 = theSession.DexManager.CreateNxto2dCreator()

nXTo2dCreator1.AutoCADRevision = NXTo2dCreator.AutoCADRevisionOption.R2007

nXTo2dCreator1.MaxSystem3DModelSpace = True

nXTo2dCreator1.MaxSystemPointRes = True

nXTo2dCreator1.SpCurveTolerance = 0.0508

nXTo2dCreator1.MaxUser3DModelSpace = 10000.0

nXTo2dCreator1.MaxUserPointRes = 0.001

nXTo2dCreator1.OutputFileType = NXTo2dCreator.OutputAsOption.DXFFile

nXTo2dCreator1.OutputFile = "C:\TEMP\CHCD-BK20_dwg_2d.dxf"

nXTo2dCreator1.Nxto2dSettingsFile = "C:\Program Files\Siemens\NX 8.0\ugto2d\ugto2d.def"

nXTo2dCreator1.DxfSettingsFile = "C:\Program Files\Siemens\NX 8.0\dxfdwg\dxfdwg.def"

nXTo2dCreator1.ExportData = NXTo2dCreator.ExportDataOption.Drawing

nXTo2dCreator1.FacetBodies = True

nXTo2dCreator1.AutoCADRevision = NXTo2dCreator.AutoCADRevisionOption.R14

nXTo2dCreator1.InputFile = "\\Bus-local-srv08\Desktop\paulhorton\Desktop\TEST-DUMMY\CHCD-BK20_dwg.prt"

theSession.SetUndoMarkName(markId1, "2D Exchange Options Dialog")

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "2D Exchange Options")

nXTo2dCreator1.DrawingName = "SH1"

nXTo2dCreator1.ViewName = "TOP"

Dim nXObject1 As NXObject
nXObject1 = nXTo2dCreator1.Commit()

theSession.DeleteUndoMark(markId2, Nothing)

theSession.SetUndoMarkName(markId1, "2D Exchange Options")

nXTo2dCreator1.Destroy()

Dim scaleAboutPoint1 As Point3d = New Point3d(157.320967741935, -16.9620967741936, 0.0)
Dim viewCenter1 As Point3d = New Point3d(-157.320967741935, 16.9620967741936, 0.0)
workPart.Views.WorkView.ZoomAboutPoint(1.25, scaleAboutPoint1, viewCenter1)

Dim scaleAboutPoint2 As Point3d = New Point3d(125.856774193548, -13.5696774193548, 0.0)
Dim viewCenter2 As Point3d = New Point3d(-125.856774193548, 13.5696774193548, 0.0)
workPart.Views.WorkView.ZoomAboutPoint(1.5625, scaleAboutPoint2, viewCenter2)

Dim scaleAboutPoint3 As Point3d = New Point3d(80.5483354838709, -8.68459354838711, 0.0)
Dim viewCenter3 As Point3d = New Point3d(-80.5483354838709, 8.68459354838708, 0.0)
workPart.Views.WorkView.ZoomAboutPoint(0.8, scaleAboutPoint3, viewCenter3)

Dim scaleAboutPoint4 As Point3d = New Point3d(100.685419354839, -10.8557419354839, 0.0)
Dim viewCenter4 As Point3d = New Point3d(-100.685419354839, 10.8557419354839, 0.0)
workPart.Views.WorkView.ZoomAboutPoint(0.8, scaleAboutPoint4, viewCenter4)

Dim scaleAboutPoint5 As Point3d = New Point3d(125.856774193548, -13.5696774193548, 0.0)
Dim viewCenter5 As Point3d = New Point3d(-125.856774193548, 13.5696774193548, 0.0)
workPart.Views.WorkView.ZoomAboutPoint(0.8, scaleAboutPoint5, viewCenter5)

Dim scaleAboutPoint6 As Point3d = New Point3d(157.320967741935, -16.9620967741936, 0.0)
Dim viewCenter6 As Point3d = New Point3d(-157.320967741935, 16.9620967741935, 0.0)
workPart.Views.WorkView.ZoomAboutPoint(0.8, scaleAboutPoint6, viewCenter6)

Dim scaleAboutPoint7 As Point3d = New Point3d(196.651209677419, -21.202620967742, 0.0)
Dim viewCenter7 As Point3d = New Point3d(-196.651209677419, 21.2026209677419, 0.0)
workPart.Views.WorkView.ZoomAboutPoint(0.8, scaleAboutPoint7, viewCenter7)

Dim scaleAboutPoint8 As Point3d = New Point3d(245.814012096774, -26.5032762096774, 0.0)
Dim viewCenter8 As Point3d = New Point3d(-245.814012096774, 26.5032762096774, 0.0)
workPart.Views.WorkView.ZoomAboutPoint(0.8, scaleAboutPoint8, viewCenter8)

Dim scaleAboutPoint9 As Point3d = New Point3d(307.267515120967, -33.1290952620968, 0.0)
Dim viewCenter9 As Point3d = New Point3d(-307.267515120967, 33.1290952620967, 0.0)
workPart.Views.WorkView.ZoomAboutPoint(1.25, scaleAboutPoint9, viewCenter9)

Dim scaleAboutPoint10 As Point3d = New Point3d(245.814012096774, -26.5032762096775, 0.0)
Dim viewCenter10 As Point3d = New Point3d(-245.814012096774, 26.5032762096774, 0.0)
workPart.Views.WorkView.ZoomAboutPoint(1.25, scaleAboutPoint10, viewCenter10)

Dim scaleAboutPoint11 As Point3d = New Point3d(196.651209677419, -21.202620967742, 0.0)
Dim viewCenter11 As Point3d = New Point3d(-196.651209677419, 21.2026209677419, 0.0)
workPart.Views.WorkView.ZoomAboutPoint(1.25, scaleAboutPoint11, viewCenter11)

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module
 
The following is a bare-bones journal that will export a dxf file for each drawing sheet in the work part. The dxf files will be output to the same folder as the work part. The code will NOT work in NX 8.5 or higher; it was tested in NX 8 and may work with versions back to NX 6 (though NX 8 was the only version tested).

Code:
Option Strict Off
Imports System
Imports NXOpen

Module Module1

    Dim theSession As Session = Session.GetSession()

    Sub Main()

        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Const undoMarkName As String = "NXJ journal"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Dim exportFolder As String = IO.Directory.GetParent(workPart.FullPath).FullName
        If String.IsNullOrEmpty(exportFolder) Then
            MsgBox("Export folder, " & exportFolder & ", not found; journal exiting.", MsgBoxStyle.Critical, "Export folder error")
            Return
        End If

        For Each tempSheet As Drawings.DrawingSheet In workPart.DrawingSheets
            ExportDxf2DExchange(workPart, tempSheet, exportFolder)
        Next

        lw.Close()

    End Sub

    Sub ExportDxf2DExchange(ByVal inputPart As Part, ByVal inputSheet As Drawings.DrawingSheet, ByVal outputFolder As String)

        If Not IO.Directory.Exists(outputFolder) Then
            MsgBox("Output folder, " & outputFolder & ", not found; journal exiting.", MsgBoxStyle.Critical, "Output folder error")
            Return
        End If

        Dim dxfSettingsDir As String = theSession.GetEnvironmentVariableValue("DXFDWG_DIR")
        Dim ugTo2dDir As String = theSession.GetEnvironmentVariableValue("UGTO2D_DIR")

        If String.IsNullOrEmpty(dxfSettingsDir) Then
            MsgBox("DXF settings directory not found; journal exiting.", MsgBoxStyle.Critical, "DXF settings error")
            Return
        End If

        If String.IsNullOrEmpty(ugTo2dDir) Then
            MsgBox("UGto2D settings directory not found; journal exiting.", MsgBoxStyle.Critical, "UGto2D settings error")
            Return
        End If

        Dim nXTo2dCreator1 As NXTo2dCreator
        nXTo2dCreator1 = theSession.DexManager.CreateNxto2dCreator()

        Dim outputFileName As String = IO.Path.Combine(outputFolder, inputPart.Leaf & "_" & inputSheet.Name & ".dxf")

        With nXTo2dCreator1
            .Nxto2dSettingsFile = IO.Path.Combine(ugTo2dDir, "ugto2d.def")
            .DxfSettingsFile = IO.Path.Combine(dxfSettingsDir, "dxfdwg.def")
            .InputFile = inputPart.FullPath
            .OutputFile = outputFileName
            .DrawingName = inputSheet.Name

            .MaxSystem3DModelSpace = True
            .MaxSystemPointRes = True
            '.SpCurveTolerance = 0.0508
            '.MaxUser3DModelSpace = 10000.0
            '.MaxUserPointRes = 0.001
            .FacetBodies = True
            .AutoCADRevision = NXTo2dCreator.AutoCADRevisionOption.R14
            .ExportData = NXTo2dCreator.ExportDataOption.Drawing
            .OutputFileType = NXTo2dCreator.OutputAsOption.DXFFile

        End With

        Dim nXObject1 As NXObject
        nXObject1 = nXTo2dCreator1.Commit()

        nXTo2dCreator1.Destroy()

    End Sub

End Module

www.nxjournaling.com
 
[smile]Cowski,
Thanks for your help, it works fine, would you be so kind as to add in a browse to the export folder location, and overwrite if it already exists.
One other feature would also be very useful.... in the drawing file there's an attribute "REV" could the journal read this and add it into the dxf file name, just before the sheet name.
This would be very useful, but if its too hard, i'd appreciate if you could just add the browse to..
Thanks..
 
I'll probably have some time later this week to add those features in. I'm curious though, how does the output of this journal differ from the one you already have? Both output 2D DXF files; is there any significant difference?

www.nxjournaling.com
 
That'd be great thanks....some suppliers complain that with the other files (when they open in AutoBad) have data in the model space not just drwg space. My answer is "just switch to drwg space then!" , for some reason, its all just too hard..[ponder]
 
i have E-drawings (free from Solidworks)and with the 2D exchange method, you only see the one enviroment, but the other way you see "model" and "drawing"
 
then i tried to run the journal with NX9, but it gave this error....
So i recorded a 2D dxf export like you asked before, just in case it can be made to work with both.....

' NX 9.0.2.5
' Journal created by paulhorton on Fri Nov 14 09:22:18 2014 E. Australia Standard Time
'
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

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

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: File->Export->AutoCAD DXF/DWG...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim dxfdwgCreator1 As DxfdwgCreator
dxfdwgCreator1 = theSession.DexManager.CreateDxfdwgCreator()

dxfdwgCreator1.ExportData = DxfdwgCreator.ExportDataOption.Drawing

dxfdwgCreator1.AutoCADRevision = DxfdwgCreator.AutoCADRevisionOptions.R2004

dxfdwgCreator1.ViewEditMode = True

dxfdwgCreator1.FlattenAssembly = True

dxfdwgCreator1.SettingsFile = "C:\Program Files\Siemens\NX 9.0\dxfdwg\dxfdwg.def"

dxfdwgCreator1.OutputFile = "C:\TEMP\CHCD-BK20_dwg.dxf"

dxfdwgCreator1.ObjectTypes.Curves = True

dxfdwgCreator1.ObjectTypes.Annotations = True

dxfdwgCreator1.ObjectTypes.Structures = True

dxfdwgCreator1.InputFile = "\\Bus-local-srv08\Desktop\paulhorton\Desktop\TEST-DUMMY\New foldernx9\CHCD-BK20_dwg.prt"

theSession.SetUndoMarkName(markId1, "AutoCAD DXF/DWG Export Wizard Dialog")

' ----------------------------------------------
' Dialog Begin AutoCAD DXF/DWG Export Wizard
' ----------------------------------------------
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "AutoCAD DXF/DWG Export Wizard ")

theSession.DeleteUndoMark(markId2, Nothing)

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "AutoCAD DXF/DWG Export Wizard ")

dxfdwgCreator1.WidthFactorMode = DxfdwgCreator.WidthfactorMethodOptions.AutomaticCalculation

dxfdwgCreator1.LayerMask = "1-256"

dxfdwgCreator1.DrawingList = "SH1"

Dim nXObject1 As NXObject
nXObject1 = dxfdwgCreator1.Commit()

theSession.DeleteUndoMark(markId3, Nothing)

theSession.SetUndoMarkName(markId1, "AutoCAD DXF/DWG Export Wizard ")

dxfdwgCreator1.Destroy()

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module
 
 http://files.engineering.com/getfile.aspx?folder=1e9b8b19-6212-43e8-ba27-da28b93cc726&file=2d-dxf-nx9.JPG
Thanks very much, it works fine, the slow first go is not a problem.
I wonder... how hard would it be to get working on NX9?
Would you be able to add the REVISION part of the code into this pdf creator, i tried myself but couldn't get it to work.



'Programmed on 02-05-2010 by Jeff Gesiakowski
'This journal was created to automate exporting drawings to .pdf format

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
Dim theUfSession As UFSession = UFSession.GetUFSession

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

Sub Main

Dim dwgs As Drawings.DrawingSheetCollection
dwgs = workPart.DrawingSheets
Dim sheet As Drawings.DrawingSheet
Dim j 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


Dim n As Integer = 0
Dim myPlists() As Tag

theUfSession.Plist.AskTags(myPlists, n)
For i As Integer = 0 To n - 1
theUfSession.Plist.Update(myPlists(i))
Next





'currentFile = GetFilePath() & GetFileName() & ".prt"
currentPath = GetFilePath()
currentFile = GetFileName()
if LCase(Right(currentFile, 4)) = "_dwg" then
exportFile = Left(currentFile, Len(currentFile) - 4)

else
exportFile = currentFile
end if
'msgbox("Export file: " & exportFile)
'msgbox("current file: " & currentFile)

partUnits = displayPart.PartUnits
'0 = inch
'1 = metric



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)
rspAdvancePrint = vbNo

Dim shts As New ArrayList()
For Each sheet in dwgs
shts.Add(sheet.Name)
Next
shts.Sort()

j = 0
Dim sht As String
For Each sht in shts

For Each sheet in dwgs
'msgbox("sht: " & sht & vbcrlf & "sheet.name: " & sheet.name)
If sheet.name = sht Then
'msgbox("Names match! Now processing...")
'msgbox (sheet.name)
j = j + 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 j = 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 j = 0 Then
MessageBox.Show("This part has no drawing sheets to export", "PDF export failure", MessageBoxButtons.ok, MessageBoxIcon.Warning)
Else
MessageBox.Show("Exported: " & j & " 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 ="T:\3D (Master)\Drawings\PDF"
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.AsDisplayed
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.Text
printPDFBuilder1.RasterImages = True
printPDFBuilder1.ImageResolution = PrintPDFBuilder.ImageResolutionOption.Draft
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
 
Cowski,
They work brilliantly, thank you sooo much for your help. You're THE MAN..[thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor