I wrote code to export a PDF file from an NX file. When I run it for a single file everything is Ok.
Then I try to use this code through a bunch of files (over a for loop), Everything is fine. But sometimes when I try to change the target files, it throws an exception on the BasePart:
basePart1 = theSession.Parts.OpenActiveDisplay(SourceFilePath, DisplayPartOption.AllowAditional, out _);
After that error, I have to reopen the project and run it from scratch, always the problem doesn't show again. But when I try to open another bunch of files, usually the problem shown again. How can I handle it?
It seems like the fact that you're doing multi-threading is the problem, because, from NX, error code 3795014 is
Function may only be called from the main thread
.See the Siemens docs on multi-threading with NX Open.
For the most part, you cannot use multi-threading with NX Open API calls, regardless of languages. Even if the language allows it, for example Java which does, internally, NX locks each call so that no NX Open function calls actually get executed in parallel.