"NXOpen.NXException.Invalid file name" error message
"NXOpen.NXException.Invalid file name" error message
(OP)
Hello,
I've completed VB code that properly creates html files from drawing sheets, in which it throws out an error message after creating the files and states the following:
"NXOpen.NXException.Invalid file name
at NXOpen.Builder.Commit()
at NXJournal.Main() in T:\Temp\NXJournals912\journal.vb:line193"
Lines 192 and 193 are as follows:
Is there any way to identify the "NXJournals912" error message?
Since the output is exactly what I desire with no errors, is there a method to bypass this error message and continue with the .NET code? ...possibly having the program hit the OK button to the error message without user input.
Thank you ahead of time for your help.
Regards,
NX Prof
I've completed VB code that properly creates html files from drawing sheets, in which it throws out an error message after creating the files and states the following:
"NXOpen.NXException.Invalid file name
at NXOpen.Builder.Commit()
at NXJournal.Main() in T:\Temp\NXJournals912\journal.vb:line193"
Lines 192 and 193 are as follows:
CODE --> .NET
Dim nXObject1 As NXObject
nXObject1 = plotBuilder1.Commit() Is there any way to identify the "NXJournals912" error message?
Since the output is exactly what I desire with no errors, is there a method to bypass this error message and continue with the .NET code? ...possibly having the program hit the OK button to the error message without user input.
Thank you ahead of time for your help.
Regards,
NX Prof





RE: "NXOpen.NXException.Invalid file name" error message
All Builder objects have a .Validate method that will return either True or False and indicates if the builder has enough information to successfully complete. As a test, I'd try calling this method and logging the response before calling the .Commit method.
To help catch, analyze, and potentially bypass errors; you can use the Try Catch block. It is similar to an If Else construct, only it works with errors. It would look something like this:
CODE
'plot builder code Try plotBuilder1.Commit Catch ex as NXException 'add code to inspect and handle error 'we'll just show a message box msgbox(ex.errorcode & ": " & ex.message) Finally 'any cleanup code you need to run whether there is an error or not plotBuilder1.Destroy End TryFor more info on Try Catch:
http://msdn.microsoft.com/en-us/library/fk6t46tz.a...
http://www.dotnetperls.com/exception-vbnet
http://www.homeandlearn.co.uk/NET/nets5p4.html
www.nxjournaling.com
RE: "NXOpen.NXException.Invalid file name" error message
I merged your code, which provided me with a journal message "1020005: Invalid file name".
The code (stripped down) I am currently using is as follows:
CODE --> .NET
' NX 7.5.5.4 ' 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 Imports System.Diagnostics Imports NXOpenUI Module NXJournal Sub Main Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Dim displayPart As Part = theSession.Parts.Display Dim dwgs As Drawings.DrawingSheetCollection dwgs = workPart.DrawingSheets Dim sheet As Drawings.DrawingSheet Dim currentFile As String Dim fileAndRev As String Dim strRevision As String currentFile = workPart.GetStringAttribute("PARTNUMBER") strRevision = workPart.GetStringAttribute("DB_PART_REV") fileAndRev = currentFile & "/" & strRevision '____________________________________________________________________________________ Dim theUISession As UI = UI.GetUI Dim sheetName As String Dim sheetNameString As String Dim sheetNameInteger As Integer Dim sheetNameIntegerMinusOne As Integer Dim totalNumberOfSheets As Integer = 0 Dim lengthOfSheetName As Integer ' ---------------------------------------------- ' Menu: File->Plot... ' ---------------------------------------------- Dim plotBuilder1 As PlotBuilder plotBuilder1 = workPart.PlotManager.CreatePlotBuilder() plotBuilder1.Copies = 1 plotBuilder1.Tolerance = 0.001 plotBuilder1.RasterImages = True plotBuilder1.XDisplay = PlotBuilder.XdisplayOption.Right plotBuilder1.XOffset = 0.15 plotBuilder1.CharacterSize = 0.06 plotBuilder1.Rotation = PlotBuilder.RotationOption.Degree90 plotBuilder1.JobName = fileAndRev '______________________________________________ For Each sheet In workPart.DrawingSheets totalNumberOfSheets += 1 'the final totalNumberOfSheets count = the total number of sheets (including the INFO sheet) Next totalNumberOfSheets = totalNumberOfSheets - 1 'the final totalNumberOfSheets count = the total number of sheets (NOT including the INFO sheet) Dim sheets1() As NXObject Dim filenames1() As String For Each sheet In workPart.DrawingSheets sheetName = sheet.Name lengthOfSheetName = sheetName.Length If sheetName <> "INFO" Then If sheetName.Substring(0, 2) = "SH" Then 'test to see if 1st 2 characters = "SH" & bypass "INFO" sheet If lengthOfSheetName = 3 Then sheetNameString = sheetName.Substring(2, 1) End If If lengthOfSheetName = 4 Then sheetNameString = sheetName.Substring(2, 2) End If If lengthOfSheetName > 3 Then If sheetName.Substring(3, 1) = "_" Then sheetNameString = sheetName.Substring(2, 1) End If End If If lengthOfSheetName > 4 Then If sheetName.Substring(4, 1) = "_" Then sheetNameString = sheetName.Substring(2, 2) End If End If End If sheetNameInteger = CInt(sheetNameString) sheetNameIntegerMinusOne = sheetNameInteger - 1 Dim drawingSheet1 As Drawings.DrawingSheet = CType(workPart.DrawingSheets.FindObject(sheetName), Drawings.DrawingSheet) ReDim Preserve sheets1(totalNumberOfSheets) sheets1(sheetNameIntegerMinusOne) = drawingSheet1 ReDim Preserve filenames1(totalNumberOfSheets) filenames1(sheetNameIntegerMinusOne) = "T:\TEMP\DWG_" & currentFile & strRevision & sheetNameString & ".cgm" End If Next '______________________________________________ plotBuilder1.SourceBuilder.SetSheets(sheets1) plotBuilder1.PlotterText = "HPGL2_TO_DISK" plotBuilder1.ProfileText = "compare_tiff_E-J_size" plotBuilder1.ColorsWidthsBuilder.Colors = PlotColorsWidthsBuilder.Color.BlackOnWhite plotBuilder1.ColorsWidthsBuilder.Widths = PlotColorsWidthsBuilder.Width.StandardWidths plotBuilder1.PrinterGroupText = "Plot_Files" plotBuilder1.SetFilenames(filenames1) '_________________________________________________________________________ 'plot builder code Try plotBuilder1.Commit() Catch ex As NXException 'add code to inspect and handle error 'we'll just show a message box msgbox(ex.errorcode & ": " & ex.message) Finally 'any cleanup code you need to run whether there is an error or not plotBuilder1.Destroy() End Try '_________________________________________________________________________ Dim nXObject1 As NXObject nXObject1 = plotBuilder1.Commit() ' ---------------------------------------------- ' Menu: Tools->Journal->Stop Recording ' ---------------------------------------------- End Sub End ModuleThank you again for your help.
Regards,
NX Prof
RE: "NXOpen.NXException.Invalid file name" error message
www.nxjournaling.com
RE: "NXOpen.NXException.Invalid file name" error message
But what I am considering is that there will always exist one more sheet in each file. Please see the example below, where the actual number of sheets = 5 and the first sheet “INFO” is to be ignored for the final output:
totalNumberOfSheets = 4
The sheet names are: “INFO” (to be overlooked), “SH1_B”, “SH2_A”, “SH3”, and “SH4_B”
- sheets1(0) = 1
- sheets1(1) = 2
- sheets1(2) = 3
- sheets1(3) = 4
And when the currentFile = “0123456” and strRevision = “B”,- filenames1(0) = "T:\TEMP\DWG_0123456BSH1_B.cgm"
- filenames1(1) = "T:\TEMP\DWG_0123456BSH2_B.cgm"
- filenames1(2) = "T:\TEMP\DWG_0123456BSH3_B.cgm"
- filenames1(3) = "T:\TEMP\DWG_0123456BSH4_B.cgm"
Later, I will add code that uses a batch routine to merge all of the files, while converting them to a single Multi_page.tif file where the final name would be 0123456_B.tif from the above example. So the name is not terribly important. But wouldn’t the sheets1 and filenames1 have an "off by one" condition to take care of the “INFO” sheet that is to be disregarded?Thank you greatly for your help.
Regards,
NX Prof
RE: "NXOpen.NXException.Invalid file name" error message
totalNumberOfSheets = 4
Later, you redim your array (which doesn't need to be in the loop , btw):
ReDim Preserve filenames1(totalNumberOfSheets {value = 4})
This gives you
filenames1(0)
filenames1(1)
filenames1(2)
filenames1(3)
filenames1(4)
Your array can now hold 5 sheet objects, but you are only interested in 4. When counting the sheets, you start with one (as normal humans do), but the Computer Science types like to start counting with zero (arrays are zero based); therefore you end up with one more element in your array than you need. The journal then tries to use one of the filenames twice, which leads to the "invalid file name" error.
(emphasis mine)
http://msdn.microsoft.com/en-us/library/w8k3cys2.a...
www.nxjournaling.com
RE: "NXOpen.NXException.Invalid file name" error message
I'll try to post an example tomorrow, time permitting.
www.nxjournaling.com
RE: "NXOpen.NXException.Invalid file name" error message
CODE
' NX 7.5.5.4 ' Option Strict Off Imports System Imports System.IO Imports System.Collections.Generic Imports System.Windows.Forms Imports System.Windows.Forms.MessageBox Imports NXOpen Imports NXOpen.UF Imports System.Diagnostics Imports NXOpenUI Module plot_drawings Sub Main() Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Dim displayPart As Part = theSession.Parts.Display 'Dim dwgs As Drawings.DrawingSheetCollection 'dwgs = workPart.DrawingSheets 'Dim sheet As Drawings.DrawingSheet Dim currentFile As String Dim fileAndRev As String Dim strRevision As String currentFile = workPart.GetStringAttribute("PARTNUMBER") strRevision = workPart.GetStringAttribute("DB_PART_REV") fileAndRev = currentFile & "/" & strRevision '____________________________________________________________________________________ Dim theUISession As UI = UI.GetUI Dim sheetName As String Dim sheetNameString As String Dim sheetNameInteger As Integer Dim sheetNameIntegerMinusOne As Integer Dim totalNumberOfSheets As Integer = 0 Dim lengthOfSheetName As Integer ' ---------------------------------------------- ' Menu: File->Plot... ' ---------------------------------------------- Dim plotBuilder1 As PlotBuilder plotBuilder1 = workPart.PlotManager.CreatePlotBuilder() plotBuilder1.Copies = 1 plotBuilder1.Tolerance = 0.001 plotBuilder1.RasterImages = True plotBuilder1.XDisplay = PlotBuilder.XdisplayOption.Right plotBuilder1.XOffset = 0.15 plotBuilder1.CharacterSize = 0.06 plotBuilder1.Rotation = PlotBuilder.RotationOption.Degree90 plotBuilder1.JobName = fileAndRev '______________________________________________ 'For Each sheet In workPart.DrawingSheets ' totalNumberOfSheets += 1 'the final totalNumberOfSheets count = the total number of sheets (including the INFO sheet) 'Next 'totalNumberOfSheets = totalNumberOfSheets - 1 'the final totalNumberOfSheets count = the total number of sheets (NOT including the INFO sheet) ''msgbox("total number of sheets: " & totalNumberOfSheets) 'Dim sheets1() As NXObject 'Dim filenames1() As String Dim mySheets As New List(Of NXObject) Dim fileNames As New List(Of String) For Each sheet As Drawings.DrawingSheet In workPart.DrawingSheets sheetName = sheet.Name lengthOfSheetName = sheetName.Length If sheetName.ToLower = "info" Then 'skip to next sheet Continue For End If If sheetName.Substring(0, 2) = "SH" Then 'test to see if 1st 2 characters = "SH" & bypass "INFO" sheet If lengthOfSheetName = 3 Then sheetNameString = sheetName.Substring(2, 1) End If If lengthOfSheetName = 4 Then sheetNameString = sheetName.Substring(2, 2) End If If lengthOfSheetName > 3 Then If sheetName.Substring(3, 1) = "_" Then sheetNameString = sheetName.Substring(2, 1) End If End If If lengthOfSheetName > 4 Then If sheetName.Substring(4, 1) = "_" Then sheetNameString = sheetName.Substring(2, 2) End If End If End If sheetNameInteger = CInt(sheetNameString) sheetNameIntegerMinusOne = sheetNameInteger - 1 'Dim drawingSheet1 As Drawings.DrawingSheet = CType(workPart.DrawingSheets.FindObject(sheetName), Drawings.DrawingSheet) 'ReDim Preserve sheets1(totalNumberOfSheets) 'sheets1(sheetNameIntegerMinusOne) = drawingSheet1 'ReDim Preserve filenames1(totalNumberOfSheets) 'filenames1(sheetNameIntegerMinusOne) = "T:\TEMP\DWG_" & currentFile & strRevision & sheetNameString & ".cgm" mySheets.Add(sheet) fileNames.Add("T:\TEMP\DWG_" & currentFile & strRevision & sheetNameString & ".cgm") Next '______________________________________________ plotBuilder1.SourceBuilder.SetSheets(mySheets.ToArray) plotBuilder1.PlotterText = "HPGL2_TO_DISK" plotBuilder1.ProfileText = "compare_tiff_E-J_size" plotBuilder1.ColorsWidthsBuilder.Colors = PlotColorsWidthsBuilder.Color.BlackOnWhite plotBuilder1.ColorsWidthsBuilder.Widths = PlotColorsWidthsBuilder.Width.StandardWidths plotBuilder1.PrinterGroupText = "Plot_Files" plotBuilder1.SetFilenames(fileNames.ToArray) '_________________________________________________________________________ 'plot builder code Try plotBuilder1.Commit() Catch ex As NXException 'add code to inspect and handle error 'we'll just show a message box msgbox(ex.errorcode & ": " & ex.message) Finally 'any cleanup code you need to run whether there is an error or not plotBuilder1.Destroy() End Try '_________________________________________________________________________ End Sub End Modulewww.nxjournaling.com
RE: "NXOpen.NXException.Invalid file name" error message
Tomorrow, I'll let you know how it works out.
Thank you again!
Regards,
NX Prof
RE: "NXOpen.NXException.Invalid file name" error message
Thank you very much for your incredible guidance, code, and suggestions which I cannot thank you enough! I'll definitely have to purchase another .NET book since the one I have (even though it is good) lacks many of the moderate to advance techniques of VB coding.
Best regards,
NX Prof
RE: "NXOpen.NXException.Invalid file name" error message
I have a few book recommendations here; but the page is a few years old so the books reference VB 2010. Perhaps the authors have put out new versions...
If you find a book that is helpful, please let me know and I will add it to the recommendation list.
www.nxjournaling.com