Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

journal execute error 1

Status
Not open for further replies.

loworange88

Mechanical
Joined
Apr 30, 2009
Messages
40
Location
US
Hey everyone. UGNX 1953, I recently have had an issue with a journal file, that exports a BOM Partslist to a TXT file. We then import that TXT file into Excel for your procurement folks. Weve been running this for about 5 years and all of the sudden I am getting errors on executing this journal. Other users with the same file (on their respective machines) are having no issue.

journal_error_kb4rtk.png


Here is the journal file:

Option Strict Off

Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities


Module output_parts_list_to_text_file

Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = s.ListingWindow


Sub Main()


'Display the listing window
'lw.open
'lw.WriteLine("UserName: " & Environment.UserName)
Dim User_Name as String = Environment.UserName
'Temporarily allow multiple PLists on the sheet
ufs.UF.SetVariable("UGII_UPDATE_ALL_ID_SYMBOLS_WITH_PLIST", 0)

'''CreatePartsList

Dim my_plist_tag As NXOpen.Tag = NXOpen.Tag.Null
Dim dispPart As NXOpen.Tag = s.Parts.Display.Tag

'Find the name of what we are working on
Dim workPart As Part = s.Parts.Work
'lw.WriteLine("PartName: " & workpart.Name)
Dim Part_Num as String = workpart.Name

Const attributeName As String = "BENENNUNG"
Dim attributeInfo As NXObject.AttributeInformation
Dim Part_Name as String
If workPart.HasUserAttribute(attributeName, NXObject.AttributeType.String, -1) Then
attributeInfo = workPart.GetUserAttribute(attributeName, NXObject.AttributeType.String, -1)
'lw.WriteLine("attribute value: " & attributeInfo.StringValue)
Part_Name = attributeInfo.StringValue
Else
'lw.WriteLine("the work part does not have an attribute named: " & attributeName)
Part_Name = ""
End If

Dim fileNameNoExt As String = IO.Path.GetFileNameWithoutExtension(workPart.FullPath)
Dim filename As String = "C:\MSI_NX_Custom\stuckliste_data\" & fileNameNoExt & "_full.txt"

'my_plist_tag = GetPlistTag(dispPart)

'Create the full Plist
Dim my_new_plist_tag As NXOpen.Tag = NXOpen.Tag.Null
Dim tab_name As String = "C:\MSI_NX_Custom\table_files\MSI_STUCKLISTE_metric.prt"
Dim origin As Double() = New Double(2) {0.0, 0.0, 0.0}
ufs.Plist.CreateFromTemplate(tab_name,origin, my_new_plist_tag)

Export_Parts_List(my_new_plist_tag, filename, User_Name, Part_Name, Part_Num)
Delete_Tables(my_new_plist_tag)

filename = "C:\MSI_NX_Custom\stuckliste_data\" & fileNameNoExt & "_top_level.txt"

Dim my_new_plist_tag2 As NXOpen.Tag = NXOpen.Tag.Null
Dim tab_name2 As String = "C:\MSI_NX_Custom\table_files\MSI_STUCKLISTE_TOP_LEVEL_metric.prt"
Dim origin2 As Double() = New Double(2) {0.0, 0.5, 0.0}
ufs.Plist.CreateFromTemplate(tab_name2,origin2, my_new_plist_tag2)

Export_Parts_List(my_new_plist_tag2, filename, User_Name, Part_Name, Part_Num)
Delete_Tables(my_new_plist_tag2)


'Set it back
ufs.UF.SetVariable("UGII_UPDATE_ALL_ID_SYMBOLS_WITH_PLIST", 1)



End Sub

Public Function Delete_Tables(tab_tag)

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

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Delete")

Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete

theSession.UpdateManager.ClearErrorList()
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")

Dim obj as Object
obj=NXOpen.Utilities.NXObjectManager.Get(tab_tag)
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(obj)

Dim notifyOnDelete2 As Boolean
notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete

Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId2)

theSession.DeleteUndoMark(markId1, Nothing)

End Function

Public Function GetPlistTag(ByRef partTag As NXOpen.Tag) As NXOpen.Tag

Dim tempTag As NXOpen.Tag = NXOpen.Tag.Null
Dim type As Integer
Dim subtype As Integer

Do
ufs.Obj.CycleObjsInPart(partTag, _
UFConstants.UF_tabular_note_type, tempTag)

ufs.Obj.AskTypeAndSubtype(tempTag, type, subtype)

If subtype = UFConstants.UF_parts_list_subtype Then
'Guide.InfoWriteLine("The tempTag = " & tempTag)
'Guide.InfoWriteLine("The subtype = " & subtype)
'Guide.InfoWriteLine("The type = " & type)
'Guide.InfoWriteLine("The name = " & ufs.Obj.Name)
Return tempTag
End If

Loop Until tempTag = NXOpen.Tag.Null

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

Return Session.LibraryUnloadOption.Immediately

End Function



Public Function Export_Parts_List(tag_name As NXOpen.Tag, fil_name as String, UName as String, PName as String, PNum as String)


Dim my_plist As New List(Of Tag)
my_plist.Add(tag_name)

Dim numSections As Integer = 0
ufs.Tabnot.AskNmSections(tag_name, numSections)
'Guide.InfoWriteLine("The numSections = " & numSections)

Dim numRows As Integer = 0
ufs.Tabnot.AskNmRows(tag_name, numRows)
'Guide.InfoWriteLine("The numRows = " & numRows)

Dim numCols As Integer = 0
ufs.Tabnot.AskNmColumns(tag_name, numCols)
'Guide.InfoWriteLine("The numCols = " & numCols)

Dim rowTag As Tag = Nothing
Dim colTag As Tag = Nothing
Dim cellTag As Tag = Nothing

Dim Stream As new System.IO.StreamWriter(fil_name)
'Stream.WriteLine("============================================================")
'Stream.WriteLine("@Part list level:")
Stream.writeline(PNum & Chr(9) & PName & Chr(9) & UName)
For j As Integer = 0 To numRows - 1

ufs.Tabnot.AskNthRow(tag_name, j, rowTag)

For k As Integer = 0 To numCols - 1

ufs.Tabnot.AskNthColumn(tag_name, k, colTag)
ufs.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
Dim cellText As String = ""
Dim evalCellText As String = ""
ufs.Tabnot.AskCellText(cellTag, cellText)
ufs.Tabnot.AskEvaluatedCellText(cellTag, evalCellText)

Stream.Write(evalCellText)

If k < (numCols - 1) Then
Stream.Write(vbtab)
end If

Next

Stream.Write(vbNewLine)
Next

Stream.Close

End Function





End Module
 
That line of code is trying to access your template file. Make sure the file: "C:\MSI_NX_Custom\table_files\MSI_STUCKLISTE_metric.prt" exists.

You might get more info on the error by checking the NX log file after the error occurs. Also, you could use a Try block to get more info on the error.

Replace
Code:
ufs.Plist.CreateFromTemplate(tab_name,origin, my_new_plist_tag)

with the following:
Code:
Try
  ufs.Plist.CreateFromTemplate(tab_name,origin, my_new_plist_tag)
Catch ex as Exception
  lw.writeline(ex.message)
End Try


www.nxjournaling.com
 
Cowski, Thank you! That worked. I did rename that file, and now its pointing to where it needs to go. The export is working again. Have a great day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top