Error after compiling

I am getting an error while running a script after it has been compiled. Not every drawing triggers the error though. The script changes plotted line weights, adds notes, plots, and then resets plotted line weights.

The error is:
Error in external library. See system log for details.
File name: c:\NX_Tools\202.dll
Function name: ufusr

This is from the log:
NXOpen.NXException: There is no displayed part or the displayed part is invalid for this operation.
at NXOpen.UF.UFPlot.AskDefaultJobName(Tag drawing_sheet, String& job_name)
at Checkplot.UFPlotSheet(DrawingSheet dwgSheet)
at Checkplot.Main()

Any thoughts?

Do you have a valid display part when you run the code. And does this valid display part contain at least 1 drawing sheet?

NXOpen.UF.UFPlot.AskDefaultJobName(Tag drawing_sheet, String& job_name)
Are you actually passing in the value: String& job_name?
The "&" character is used as the string concatenation operator (and it is also legal as a type declaration when declaring a variable, though you probably won't see it used much that way any more), it is not legal to use it in a variable name. If that is literally what you are passing in to the function, it may be causing problems.

I am viewing the sheet when the code is ran so hopefully it is valid. I can run the uncompiled VB on the same drawing with no errors and a successful plot. I can also use the compiled program on other drawings successfully.It is only one part in ten that seems to cause a crash of the compiled version. All of our parts are named as 8 digit numbers ending with a dash DWG(ie, 00000000-DWG). All of our drawing sheets are SH1, etc. No funky characters or formatting.

tl;dr. .VB plot works 100%. Compiled DLL works 90% on same parts. Compiled runs much faster when it works, so it is still my desired goal.

Also, I reopened the one of the drawings this morning and the compiled plot script worked flawlessly.

Wrap the problem statement in a Try block. If/when an error occurs, you can look at the exception object to get more information as to what happened.


Dim jobName As String
Try
theUfSession.Plot.AskDefaultJobName(dwgSheet.Tag, jobName)
Catch ex As NXException
MsgBox(ex.ErrorCode & ": " & ex.Message, vbExclamation + vbOKOnly, "NX Exception")
jobName = Now.Ticks.ToString
Catch ex As Exception
MsgBox(ex.GetType.ToString & ": " & ex.Message, vbExclamation + vbOKOnly, "Error")
jobName = Now.Ticks.ToString
End Try