0

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.

RBuntu
  • 907
  • 10
  • 22
  • 1
    No, that _invApp interface is not associated with the process you started. When you created the object, you already got the process running. Have a look-see with Task Manager. You just have to tell it to load the document. – Hans Passant Aug 03 '15 at 13:58

1 Answers1

1

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.

Heinzi
  • 167,459
  • 57
  • 363
  • 519
  • Ah thanks. I used the process.start because I thought there was no way to add a document from a file name in the program, but I just found it. – RBuntu Aug 03 '15 at 15:26