Hi together!:)
I am trying to automate a NX update. Unfortunately,I encountered an error. My .fem file is linked to an idealized part. If I am changing the idealized part geometry, the .fem file shall adapt. If the idealized part is somehow unstable, the .fem is not updating properly.
If I am trying to update the .fem model to a idealized part, which is broken, it throws the error "error: tool body is completely outside target body" or something like that. Nevertheless, the .fem file keeps on updating and pretends that everything is fine. The mesh is different than expected, but the body is meshed.
How can I tell my NX journal, that it shall write out this "update error" into a txt file?
I already read myself into "Update.Errorlist" and SetDefaultUpdateFailureAction etc., but I was not able to find a working solution :(
I found something like this:
Dim myErrList As NXOpen.ErrorList
For i As Integer = 0 To myErrList.Length - 1
lw.WriteLine("Error number: " & i.ToString)
lw.WriteLine(" " & ErrList.GetErrorInfo(i).ErrorCode & ": " & myErrList.GetErrorInfo(i).Description)
lw.WriteLine("")
Next
But this is not working due to the error:"object reference not set to an instance of an object"
Thank you very much!
Regards
Benny
re: error list
You can set your "myErrList" variable to reference the current session error list:
dim myErrList as NXOpen.ErrorList
myErrList = theSession.UpdateManager.ErrorList
or you can just access the session error list directly.
It is a good idea to clear the error list before running your code to ensure that any errors in the list are from your code and not previous operations:
theSession.UpdateManager.ErrorList.Clear()
And finally, if your code is throwing exceptions (as opposed to update errors), put the potentially problematic code in a Try Catch block.
https://msdn.microsoft.com/en-us/library/fk6t46tz.aspx
Thank you very very much for
Thank you very very much for your answer! No error is popping up now and the information from the "Information window" is written to the lw.file
When I am loading the idealized partfile to the .fem file, the "INFORMATION" window appears with the following content:
============================================================
************************************************************
Update Warning and Failure Report
************************************************************
------------------------------------------------------------
Model_fem1_idealised
------------------------------------------------------------
Split Body(12) Error: Tool body completely outside target body.
============================================================
Information listing created by :
Date :
Current work part : ============================================================
CAE Polygon Body Update Log
===========================
Searching for modified polygon faces.
Unable to perform surgical update for the following reason:
A polygon face that is referenced by a Glue Coincident or Free Coincident
type of Mesh Mating condition will be modified by the update.
Beginning full update process.
All polygon bodies have been marked for update.
These would be deleted and recreated.
So it states the error and writes out the content.
The code for that is now :
Try
theSession.UpdateManager.ClearErrorList()
Catch
logFile.writeLine("Clearing failed")
logfile.Flush
End Try
Try
myErrList = theSession.UpdateManager.ErrorList
Catch
logFile.writeLine("Initialisation failed")
logfile.Flush
End Try
and later in the code:
For i As Integer = 0 To myErrList.Length - 1
logFile.WriteLine("Error number: " & i.ToString)
logFile.WriteLine(" " & myErrList.GetErrorInfo(i).ErrorCode & ": " & myErrList.GetErrorInfo(i).Description)
logFile.WriteLine("")
Next
For i As Integer = 0 To myErrList.Length - 1
lw.WriteLine("Error number: " & i.ToString)
lw.WriteLine(" " & myErrList.GetErrorInfo(i).ErrorCode & ": " & myErrList.GetErrorInfo(i).Description)
lw.WriteLine("")
Next
The output is only written to the lw and not to logfile, but that is not too bad.
Is there a possibility, to create something as follows:
If the word "error" is existing in lw, do something.
?
Thank you!:)
re: catching errors
Clearing the error list and accessing the error list will probably never throw an error, so enclosing these operations in a try block is unnecessary. What should be placed in the try block is the operation that you suspect is generating the error condition. For example, let's assume there is a subroutine called "UpdateMesh" that we suspect may error; we would enclose the call to "UpdateMesh" in a try block to help identify and potentially correct the error. It is better to catch the error when it happens rather than trying to parse the listing window information to see what happened.
theSession.UpdateManager.ErrorList.Clear()
dim myErrList as ErrorList
myErrList = theSession.UpdateManager.ErrorList
Try
UpdateMesh
Catch ex as NXException
'code to handle NX error
Catch ex as Exception
'code to handle other error
Finally
'optional block to hold any necessary clean up code
End Try
Thank you.
Thank you.
I already tried to identify the action that throws the error, but I didnt manage to catch the error somehow.
Actually, it is only the "load the idealized part" action that tries to load it and realizes that one feature is not working, but continues to load it and then somehow the saving fails. I will try your solution on monday !:)
Hi,
Hi,
I tried to embrace the whole "load idealized part" action with a try-catch statement now, but the error isn't caught either.
Try
Dim idealpart As Part
Dim idealpartLoadStatus As PartLoadStatus
idealpart = theSession.Parts.Open(PATHNAME & IDIALIZEDPARTFILENAME, idealpartLoadStatus)
idealpartLoadStatus.Dispose()
Catch ex as NXException
logFile.writeLine("Idealized Partfile loading failed!")
logFile.writeLine("Error Message:" & ex.Message)
logFile.Flush
ExitProcess(1&)
Catch ex as Exception
logFile.writeLine("Idealized Partfile loading failed!")
logFile.writeLine("Error Message:" & ex.Message)
logFile.Flush
ExitProcess(1&)
Finally
End Try
I think, that it isn't directly an error, because NX is able to mesh it and to load it, so the commands are executed properly. NX only realizes, that there's the feature "split body" in the idealized part, which can not be done but ignores it and continues the mesh update. It only states the error in the information window.
My aim would be to "exitprocess" if there's any inconsistency in the model. But I am still not sure how to do that. The dirtiest workaround would be, to create this lw file, where the information is written down, and to create a additional python script, which exits the process if the word "error" is found in the log.txt.
re: feature errors and warnings
The feature class has methods:
.GetFeatureErrorMessages
.GetFeatureWarningMessages
.GetFeatureInformationalMessages
After opening/updating the part, I'd suggest iterating through the features looking for any with error or warning messages.
If you would like to parse the listing window contents, the first part of the article below shows how to redirect the listing window to a file which you can then open and read. You will want to redirect the output before opening/updating the part.
http://nxjournaling.com/content/write-text-file
Thank you again for your
Thank you again for your effort!
I tried the following:
Dim idealpart As Part
Dim idealpartLoadStatus As PartLoadStatus
idealpart = theSession.Parts.Open(PATHNAME & IDIALIZEDPARTFILENAME, idealpartLoadStatus)
lw.WriteLine("*** All Features ***")
For Each myFeature As Feature In theSession.Parts.Work.Features
For k as Integer = 0 To myFeature.GetFeatureErrorMessages.Length - 1
lw.WriteLine(".GetFeatureError: " & myFeature.GetFeatureErrorMessages(k))
Next
Next
idealpartLoadStatus.Dispose()
But somehow, this doesn't work :( I'm really new to the whole journaling thing sorry :(
re: error messages
The .GetFeatureErrorMessages returns a string array.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ")
lw.Open()
For Each tempFeat As Features.Feature In theSession.Parts.Work.Features
Dim errMsgs() As String = tempFeat.GetFeatureErrorMessages
If errMsgs.Length > 0 Then
For Each errLine As String In errMsgs
lw.WriteLine(errLine)
Next
End If
Next
lw.Close()
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 Module