Opening drawing file invisible causes code to crash

Opening drawing file invisible causes code to crash

kmiller
Collaborator Collaborator
885 Views
2 Replies
Message 1 of 3

Opening drawing file invisible causes code to crash

kmiller
Collaborator
Collaborator

Hi there,

 

I am building a custom batch update for our drawings to take border definitions as well as custom iproperties from a current template and push them into a specified inventor dwg file.  I built a form for the users to select the template they want to import into a list of files they place in the form.  The program opens the template, get's all the information (iproperties, border defs, etc... using the active document to get the document) then iterates through the list of the users doing the following for each file (also getting the active document to get the items in each file):  open, replace border definition, insert any non-existent custom iproperties, save and close the file.  It works great when I keep the open visible set to true for the files.  When I switch the visible property to false for each one of the files I want to open I get an error similar to this:  Systems.InvalidCastException: Unable to cast object of type 'Inventor._DocumentClass' to type 'Inventor._DrawingDocument'. at  ---- then my button click event here. 

 

Does inventor technically not see a document as an active document if the file is not visible when opened?  I think that might be my problem.

 

Thanks in advance.

-------------------------------------------------------------------------------------------------

If this response answers your question please click "Accept as Solution".
0 Likes
Accepted solutions (1)
886 Views
2 Replies
Replies (2)
Message 2 of 3

philippe.leefsma
Alumni
Alumni
Accepted solution

The ActiveDocument is the document being currently active in the UI. If you open the documents in invisible mode this property is not valid. You should keep a reference to the documents you are going to invoke at the time you open them, a Document object is returned by the Open method. Or you can always access the list of loaded documents from Application.Documents.

 

I hope it helps.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 3

kmiller
Collaborator
Collaborator

Yes - Thank you, I was figuring it was something like that. 

 

-------------------------------------------------------------------------------------------------

If this response answers your question please click "Accept as Solution".
0 Likes