Journal Export DXF and PDF
Journal Export DXF and PDF
(OP)
Hi All,
I've been looking into programming a journal to export a dxf and a pdf from a drawing.
I'm using the stand alone draft method (draft and model are one file)
The program code attached is ok regarding the pdf export part. De dxf export part is not ok. The dxf export is the export of the flat pattern in the model. When no flat pattern (sheet metal) is available only a warning should be given that no dxf is exported.
Since i'm no programming expert (far from) i'm looking for someone the pick out the bugs from my program.
Kind regards,
Lars
I've been looking into programming a journal to export a dxf and a pdf from a drawing.
I'm using the stand alone draft method (draft and model are one file)
The program code attached is ok regarding the pdf export part. De dxf export part is not ok. The dxf export is the export of the flat pattern in the model. When no flat pattern (sheet metal) is available only a warning should be given that no dxf is exported.
Since i'm no programming expert (far from) i'm looking for someone the pick out the bugs from my program.
Kind regards,
Lars
Lars
Solid Edge
Inventor
NX10.0.3.5 native





RE: Journal Export DXF and PDF
You don't describe you actual problem in enough detail to advise on what may be the problem.
I have no experience with the exportFlatPatternBuilder1 but you can also get a dxf by exporting the drawing sheet. The following is some working C# code that does that using the NXOpen DxfdwgCreator class.
Paul
CODE --> C#
// Export Specified Drawing Sheet to ACAD/DWG Format private static int ExportDrawingSheetToDxf(DrawingSheet aSheet, string aOutputFileName, Part aInputPart) { if (!ProjectSystemIO.CheckWritableFile(aOutputFileName)) return 1; string dxfSettingsDir = NXProgramClass.Session.GetEnvironmentVariableValue("DXFDWG_DIR"); string DxfdwgDir = NXProgramClass.Session.GetEnvironmentVariableValue("DXFDWG_DIR"); if(String.IsNullOrEmpty(dxfSettingsDir)) { MessageBox.Show("DXF settings directory not found; journal exiting.", "DXF settings error", MessageBoxButtons.OK, MessageBoxIcon.Error); return 1; } if(String.IsNullOrEmpty(DxfdwgDir)) { MessageBox.Show("Dxfdwg settings directory not found; journal exiting.", "Dxfdwg settings error", MessageBoxButtons.OK, MessageBoxIcon.Error); return 1; } DxfdwgCreator dxfdwgCreator1; dxfdwgCreator1 = NXProgramClass.Session.DexManager.CreateDxfdwgCreator(); dxfdwgCreator1.SettingsFile = ProjectSystemIO.PathCombine(dxfSettingsDir, "dxfdwg.def"); dxfdwgCreator1.InputFile = aInputPart.FullPath; dxfdwgCreator1.OutputFile = aOutputFileName; dxfdwgCreator1.DrawingList = aSheet.Name; // dxfdwgCreator1.AutoCADRevision = DxfdwgCreator.AutoCADRevisionOptions.R2000; dxfdwgCreator1.ExportData = DxfdwgCreator.ExportDataOption.Drawing; dxfdwgCreator1.OutputFileType = DxfdwgCreator.OutputFileTypeOption.Dxf; dxfdwgCreator1.ObjectTypes.Curves = true; dxfdwgCreator1.ObjectTypes.Annotations = true; dxfdwgCreator1.ObjectTypes.Structures = true; dxfdwgCreator1.FlattenAssembly = false; dxfdwgCreator1.ViewEditMode = false; dxfdwgCreator1.FileSaveFlag = false; dxfdwgCreator1.LayerMask = "1-256"; dxfdwgCreator1.DrawingList = ""; dxfdwgCreator1.ViewList = "TOP,FRONT,RIGHT,BACK,BOTTOM,LEFT,TFR-ISO,TFR-TRI"; NXObject nXObject1; nXObject1 = dxfdwgCreator1.Commit(); dxfdwgCreator1.Destroy(); // presume no other errors return 0; }Paul Turner
CAD & Process Engineer
Mastip Technology
RE: Journal Export DXF and PDF
Thanx for the response. The thing is that i'd really like to use the flat pattern export out of the model environment.
This because of the layer settings etc.
The shop i work for outsources al it's sheet metal production. They must have a dxf for laser cutting and bending and also a PDF to make sure no faults are made converting the dxf.
I've found two program's i think i can combine into one program.
Ik want to start this program out of the drafting environment and first make the pdf. Then the program has to switch into de sheet metal environment and export the flat pattern.
The location of the output files will have to be the same as the location of the prt file.
Thats all i want to do. Problem is that de PDF works ok. And the flat pattern also works (with a set flat pattern name).
When i try to inbed a piece of program which finds the flat pattern I get faults.
Kind Regards,
lars
Lars
Solid Edge
Inventor
NX10.0.3.5 native
RE: Journal Export DXF and PDF
CODE
Option Strict Off Imports System Imports System.Collections.Generic Imports NXOpen Imports NXOpen.UF Module Module1 Dim theSession As Session = Session.GetSession() Dim theUfSession As UFSession = UFSession.GetUFSession() Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow Sub Main() Dim currentPath As String = GetFilePath() Dim currentFile As String = GetFileName() Dim pdfFile As String = GetFilePath() & GetFileName() & ".pdf" Dim dxfFile As String = GetFilePath() & GetFileName() & ".dxf" Dim partUnits As Integer = theSession.Parts.Display.PartUnits '0 = inch '1 = metric Dim i As Integer = 0 For Each sheet As Drawings.DrawingSheet In theSession.Parts.Display.DrawingSheets 'msgbox (sheet.name) i = i + 1 Try ExportPDF(sheet, pdfFile, partUnits) Catch ex As Exception MsgBox("Error occurred in PDF export" & vbCrLf & ex.Message & vbCrLf & "journal exiting", vbCritical + vbOKOnly) Exit Sub End Try Next If i = 0 Then msgbox("This part has no drawing sheets to export") Else msgbox("Exported: " & i & " sheet(s) to pdf file" & vbcrlf & pdfFile, vbokonly + vbinformation) End If Dim myFlatPattern As Features.FlatPattern = GetFlatPattern() If IsNothing(myFlatPattern) Then 'skip it 'warn user? Else 'export flat pattern to dxf lw.WriteLine("exporting dxf to: " & dxfFile) ExportFlatPattern(myFlatPattern, dxfFile) End If End Sub Function GetFlatPattern() As Features.FlatPattern If IsNothing(theSession.Parts.Work) Then 'active part required Return Nothing End If For Each myFeature As Features.Feature In workPart.Features If TypeOf (myFeature) Is Features.FlatPattern Then Return myFeature End If Next 'if we make it here, no flat pattern was found Return Nothing End Function Sub ExportFlatPattern(ByVal theFlatPattern As Features.FlatPattern, ByVal outputFile As String) Dim exportFlatPatternBuilder1 As NXOpen.Features.SheetMetal.ExportFlatPatternBuilder exportFlatPatternBuilder1 = workPart.Features.SheetmetalManager.CreateExportFlatPatternBuilder() exportFlatPatternBuilder1.AddedTop = True exportFlatPatternBuilder1.AddedBottom = True exportFlatPatternBuilder1.DxfRevision = NXOpen.Features.SheetMetal.ExportFlatPatternBuilder.DxfRevisionType.R14 exportFlatPatternBuilder1.OutputFile = outputFile exportFlatPatternBuilder1.FlatPattern.Value = theFlatPattern Dim nXObject1 As NXOpen.NXObject nXObject1 = exportFlatPatternBuilder1.Commit() exportFlatPatternBuilder1.Destroy() End Sub Function GetFileName() Dim strPath As String Dim strPart As String Dim pos As Integer 'get the full file path strPath = theSession.Parts.Display.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 = theSession.Parts.Display.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) Dim printPDFBuilder1 As PrintPDFBuilder printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder() printPDFBuilder1.Scale = 1.0 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.High printPDFBuilder1.Append = False printPDFBuilder1.Watermark = "" 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 Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End Modulewww.nxjournaling.com
RE: Journal Export DXF and PDF
It works like a charm. Thanx a lot
Kind regards,
Lars
Lars
Solid Edge
Inventor
NX10.0.3.5 native
RE: Journal Export DXF and PDF
Thanks for sharing.
I tried to use above code from cwoski in NX6, with errors attached to the post
I was trying to export dxf from a sheetmetal part in NX using the above journal, Need help to use the progm.
Regards,
Subhash
Regards / Freundliche Grn¯e / Cordialement,
Subhash Madkatte
SIEMENS | I BT LV GC | R & D | Mumbai | India.
E-mail:subhash.madkatte@siemens.com; madkatte@gmail.com
RE: Journal Export DXF and PDF
The journal was written for NX 9/10; it makes use of at least one function that is not available in NX 6. It will probably work in NX 8, but will not work in any version before 8.
www.nxjournaling.com
RE: Journal Export DXF and PDF
Thanks for the info.
Hope to get NX9 soon :) & use this journal.
Regards / Freundliche Grn¯e / Cordialement,
Subhash Madkatte
RE: Journal Export DXF and PDF
The journal mentioned above works like a charm as I said.
The only thing that the journal is not doing, is exporting all the draft sheets.
The journal now only makes a PDF of the last sheet.
I've tweaked the journal a bit with the msgbox filling but don't see why that should affect the export of the draft to PDF.
The idea is that the exported PDF is one file containing als sheets.
Can this be done ?
Lars
Lars
Solid Edge
Inventor
NX10.0.3.5 native
RE: Journal Export DXF and PDF
CODE
www.nxjournaling.com
RE: Journal Export DXF and PDF
it works. Thnx a lot.
Lars
Lars
Solid Edge
Inventor
NX10.0.3.5 native
RE: Journal Export DXF and PDF
I said it was alright but the following happens now.
When I save the pdf and anPDF from this file is already exists, the sheets are added to this PDF. This causing errors and mistakes.
A simple question from windows to overwrite the existing (PDF) file or not should be sufficient to make sure no double data is made.
Can this be added to the current code ?
Kind regards,
Lars
Lars
Solid Edge
Inventor
NX10.0.3.5 native
RE: Journal Export DXF and PDF
CODE
Sub Main() Dim currentPath As String = GetFilePath() Dim currentFile As String = GetFileName() Dim pdfFile As String = GetFilePath() & GetFileName() & ".pdf" Dim dxfFile As String = GetFilePath() & GetFileName() & ".dxf" Dim partUnits As Integer = theSession.Parts.Display.PartUnits '0 = inch '1 = metric Dim i As Integer = 0 For Each sheet As Drawings.DrawingSheet In theSession.Parts.Display.DrawingSheets 'msgbox (sheet.name) i = i + 1 '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 IO.File.Exists(pdfFile) Then Dim rspFileExists As Windows.Forms.DialogResult rspFileExists = Windows.Forms.MessageBox.Show("The file: '" & pdfFile & "' already exists; overwrite?", "Overwrite file?", Windows.Forms.MessageBoxButtons.YesNo, Windows.Forms.MessageBoxIcon.Question) If rspFileExists = Windows.Forms.DialogResult.Yes Then Try IO.File.Delete(pdfFile) Catch ex As Exception Windows.Forms.MessageBox.Show(ex.Message & vbCrLf & "Journal exiting", "Error", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Error) Exit Sub End Try Else 'user chose not to overwrite file 'msgbox("journal exiting", vbokonly) Exit Sub End If End If End If Try ExportPDF(sheet, pdfFile, partUnits) Catch ex As Exception MsgBox("Error occurred in PDF export" & vbCrLf & ex.Message & vbCrLf & "journal exiting", vbCritical + vbOKOnly) Exit Sub End Try Next If i = 0 Then msgbox("This part has no drawing sheets to export") Else msgbox("Exported: " & i & " sheet(s) to pdf file" & vbcrlf & pdfFile, vbokonly + vbinformation) End If Dim myFlatPattern As Features.FlatPattern = GetFlatPattern() If IsNothing(myFlatPattern) Then 'skip it 'warn user? lw.WriteLine("flat pattern is nothing") Else 'export flat pattern to dxf lw.WriteLine("exporting dxf to: " & dxfFile) ExportFlatPattern(myFlatPattern, dxfFile) End If End Subwww.nxjournaling.com
RE: Journal Export DXF and PDF
Thnx fot this.
I get the following msg, (please see attachment)
Lars
Lars
Solid Edge
Inventor
NX10.0.3.5 native
RE: Journal Export DXF and PDF
i.e. change all the lines like
CODE
to:
CODE
www.nxjournaling.com
RE: Journal Export DXF and PDF
Works :)
Lars
Lars
Solid Edge
Inventor
NX10.0.3.5 native
RE: Journal Export DXF and PDF
The journal jou made works great thnx a lot for this help.
As you probably guessed ....I have a question
The automatic export of PDF and Flat pattern works great when using stand alone parts. But when I have a master model setup only the PDF is made. The flat pattern isn't exported?
I'de like to add a few lines of code which get the flat pattern out of the component linked to the draft.
Kind Regards,
Lars
Lars
NX10.0.3.5 native
Solid Edge
Inventor
RE: Journal Export DXF and PDF
Lars
NX10.0.3.5 native
Solid Edge
Inventor
RE: Journal Export DXF and PDF
CODE
Option Strict Off Imports System Imports System.Collections.Generic Imports NXOpen Imports NXOpen.UF Module Module3 Dim theSession As Session = Session.GetSession() Dim theUfSession As UFSession = UFSession.GetUFSession() Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow Sub Main() lw.Open() Dim currentPath As String = GetFilePath() Dim currentFile As String = GetFileName() Dim pdfFile As String = GetFilePath() & GetFileName() & ".pdf" Dim dxfFile As String = GetFilePath() & GetFileName() & ".dxf" Dim partUnits As Integer = theSession.Parts.Display.PartUnits '0 = inch '1 = metric Dim i As Integer = 0 For Each sheet As Drawings.DrawingSheet In theSession.Parts.Display.DrawingSheets 'msgbox (sheet.name) i = i + 1 '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 IO.File.Exists(pdfFile) Then Dim rspFileExists As System.Windows.Forms.DialogResult rspFileExists = System.Windows.Forms.MessageBox.Show("The file: '" & pdfFile & "' already exists; overwrite?", "Overwrite file?", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) If rspFileExists = System.Windows.Forms.DialogResult.Yes Then Try IO.File.Delete(pdfFile) Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.Message & vbCrLf & "Journal exiting", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error) Exit Sub End Try Else 'user chose not to overwrite file 'msgbox("journal exiting", vbokonly) Exit Sub End If End If End If Try ExportPDF(sheet, pdfFile, partUnits) Catch ex As Exception MsgBox("Error occurred in PDF export" & vbCrLf & ex.Message & vbCrLf & "journal exiting", vbCritical + vbOKOnly) Exit Sub End Try Next If i = 0 Then MsgBox("This part has no drawing sheets to export") Else MsgBox("Exported: " & i & " sheet(s) to pdf file" & vbCrLf & pdfFile, vbOKOnly + vbInformation) End If Dim myFlatPattern As Features.FlatPattern = Nothing Dim c As Assemblies.ComponentAssembly = theSession.Parts.Display.ComponentAssembly If IsNothing(c.RootComponent) Then 'Part has no components, look for flat pattern in this part lw.WriteLine("part has no components, looking for flat pattern in this file") myFlatPattern = GetFlatPattern(theSession.Parts.Display) End If If c.RootComponent.GetChildren.Length > 1 Then 'this is an assembly, not a drawing file lw.WriteLine("part is not a drawing (it has more than one component), exiting") Exit Sub End If 'lw.WriteLine("display part has one component") 'lw.WriteLine("display part has " & c.RootComponent.GetChildren(0).GetChildren.Length.ToString & " grandchildren") If c.RootComponent.GetChildren(0).GetChildren.Length <> 0 Then 'child component is a subassembly Exit Sub End If If Not LoadComponent(c.RootComponent.GetChildren(0)) Then 'component not fully loaded, will not be able to access flat pattern feature info Exit Sub End If myFlatPattern = GetFlatPattern(c.RootComponent.GetChildren(0).Prototype.OwningPart) If IsNothing(myFlatPattern) Then 'skip it 'warn user? lw.WriteLine("flat pattern is nothing") Else 'export flat pattern to dxf lw.WriteLine("exporting dxf to: " & dxfFile) ExportFlatPattern(myFlatPattern, dxfFile) End If lw.Close() End Sub Function GetFlatPattern(ByVal thePart As Part) As Features.FlatPattern If IsNothing(thePart) Then 'part required Return Nothing End If For Each myFeature As Features.Feature In thePart.Features If TypeOf (myFeature) Is Features.FlatPattern Then Return myFeature End If Next 'if we make it here, no flat pattern was found Return Nothing End Function Sub ExportFlatPattern(ByVal theFlatPattern As Features.FlatPattern, ByVal outputFile As String) Dim exportFlatPatternBuilder1 As NXOpen.Features.SheetMetal.ExportFlatPatternBuilder exportFlatPatternBuilder1 = workPart.Features.SheetmetalManager.CreateExportFlatPatternBuilder() exportFlatPatternBuilder1.AddedTop = True exportFlatPatternBuilder1.AddedBottom = True exportFlatPatternBuilder1.Type = Features.SheetMetal.ExportFlatPatternBuilder.FileType.Dxf exportFlatPatternBuilder1.DxfRevision = NXOpen.Features.SheetMetal.ExportFlatPatternBuilder.DxfRevisionType.R14 exportFlatPatternBuilder1.OutputFile = outputFile exportFlatPatternBuilder1.FlatPattern.Value = theFlatPattern Dim nXObject1 As NXOpen.NXObject nXObject1 = exportFlatPatternBuilder1.Commit() exportFlatPatternBuilder1.Destroy() End Sub Function GetFileName() Dim strPath As String Dim strPart As String Dim pos As Integer 'get the full file path strPath = theSession.Parts.Display.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 = theSession.Parts.Display.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) Dim printPDFBuilder1 As PrintPDFBuilder printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder() printPDFBuilder1.Scale = 1.0 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.High printPDFBuilder1.Append = True printPDFBuilder1.Watermark = "" 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 Private Function LoadComponent(ByVal theComponent As Assemblies.Component) As Boolean Dim thePart As Part = theComponent.Prototype.OwningPart Dim partName As String = "" Dim refsetName As String = "" Dim instanceName As String = "" Dim origin(2) As Double Dim csysMatrix(8) As Double Dim transform(3, 3) As Double Try If thePart.IsFullyLoaded Then 'component is fully loaded Else 'component is partially loaded End If Return True Catch ex As NullReferenceException 'component is not loaded Try theUfSession.Assem.AskComponentData(theComponent.Tag, partName, refsetName, instanceName, origin, csysMatrix, transform) Dim theLoadStatus As PartLoadStatus theSession.Parts.Open(partName, theLoadStatus) '_theUfSession.Assem.SetAssemOptions(curLoadOptions) If theLoadStatus.NumberUnloadedParts > 0 Then Dim allReadOnly As Boolean = True For i As Integer = 0 To theLoadStatus.NumberUnloadedParts - 1 If theLoadStatus.GetStatus(i) = 641058 Then 'read-only warning, file loaded ok Else '641044: file not found allReadOnly = False End If Next If allReadOnly Then Return True Else 'warnings other than read-only... Return False End If Else Return True End If Catch ex2 As NXException Return False End Try Catch ex As NXException 'unexpected error Return False Finally End Try End Function Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End Modulewww.nxjournaling.com