How do i avoid the document not found error box

How do i avoid the document not found error box

davidt162003
Advocate Advocate
352 Views
3 Replies
Message 1 of 4

How do i avoid the document not found error box

davidt162003
Advocate
Advocate

For a program im writing I want to check if a document exists or not then return the document object 

which im doing with the following code 

Friend Function SaveCopyOpen(Doc As Document, FileRoot As String, FileName As String,
                            _App As Inventor.Application, ByRef Exists As Boolean) As PartDocument
    Dim NewDoc As PartDocument
    With Doc
        .DisplayName = FileName
        Dim FullString = FileRoot & FileName & ".ipt"
        Dim ExistinDoc As Document
        Try
            'Exists = System.IO.File.Exists(FileRoot) ' gonna try and see if this version works better and dosent throw a error message 
            'If Exists Then
            '    ExistinDoc = _App.Documents.Open(FileName)
            '    Return ExistinDoc
            'End If
            ExistinDoc = _App.Documents.Open(FileRoot) 'will throw a error here if part is already open
            If ExistinDoc IsNot Nothing Then
                Exists = True
                Return ExistinDoc
            End If
        Catch ex As Exception

        End Try

        .SaveAs(FullString, True)
        Exists = False
        NewDoc = _App.Documents.Open(FullString)
    End With
    Return NewDoc
End Function
''' <summary>

It works however cause this window to pop up 

is their any way around this 

davidt162003_0-1704806063256.png

 

HII
0 Likes
Accepted solutions (1)
353 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @davidt162003.  That line of code you say is causing the error, is using 'FileRoot' variable as the String for the file to open.  That looks to me like only the folder path for where the file should be, but does not include the file name (which would be in the 'FileName' variable).  It seems to me like you would need to use the 'FullString' variable there, because that includes the 'FileRoot' variable's value, plus the 'FileName' variable's value, plus the file extension.  When opening a document, you need to specify the 'FullDocumentName' (path + file name + extension + iPart/iAssembly/ModelState member name), or at least the 'FullFileName' (path + file name + extension) of the file to open.

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=Documents_Open 

That error is likely coming from Line 14 in the code posted above, but the reason it seems to still be working, is that down at Line 25 of the code above, you are using the Documents.Open method again, but you are using the correct variable there, so it is opening the file, like it is supposed to do.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

davidt162003
Advocate
Advocate
Ah thank you part of me feels like their might have been a reason i had it set up that way but for the life of me i cant remember. But ive switched it back to full string now and it seem to work
HII
0 Likes
Message 4 of 4

davidt162003
Advocate
Advocate

I think Ive remembered why i had it like before. I belive it was because when the Document i was trying to copy is already open it throws a error. 

HII
0 Likes