Search code examples
vb.netautodesk

How do I tell a VB.NET app to wait until the document is loaded?


I am curious how I can tell my application to wait until my document is loaded. Currently, I have a code that is activated on a button.click event. A section of the code is:

System.Diagnostics.Process.Start(oInitialPath & ".idw")
oDrawingDoc = _invApp.Documents.ItemByName(oInitialPath & ".idw")
oDrawingDoc.SaveAs(StripFilename(MyFile) & oNewName & ".idw", False)

I'm not sure if .process.start is the best way to open an Autodesk Inventor document, but regardless it works. The issue is that the next line, where I assign the document to the variable, is called before the document can open. So I get an exception error because the document doesnt exist yet. What can I put in that will make the application wait until the document is fully open before assigning it to a variable? Without using a messagebox or threading.sleep.


Solution

  • You have already identified the cause of your problem: You use two different ways to communicate with your third-party application:

    1. Process.Start to open a file and
    2. the application's COM automation interface to manipulate and save the file.

    The solution is simple: Use the application's COM automation interface (_invApp) also for opening the file. How to do that can be found in the documentation of your third-party application.