Unable to add variables to datacard and checkin - VB.NET,

Hello there!

Thi part of my program is not working. dwgFile is showing a value but I get the error that says “File could not be found”. I am trying to update mandatory data card variables of a draftsight file and check it in to the vault.

If File.Exists(dwgFilePath) Then
    Try
        dwgFile = vault.GetFileFromPath(dwgFilePath)
        If Not dwgFile Is Nothing Then
            vars = dwgFile.GetEnumeratorVariable()
            obj = FileName
            vars.SetVar("DrawingNo", "", obj)
            'vars.SetVar("DrawingNo", "Model", obj)
            obj = "Nameplate"
            vars.SetVar("DrgDescription", "", obj)
            vars.CloseFile(True)
            dwgFile.UnlockFile(0, "Nameplate DWG")           
                    End If
    Catch ex As Exception
        MsgBox("DWG checkin failed, please checkin manually!" & ex.ToString)
    End Try
End If

This is the exception: system.runtime.interopservices.comexception (0x80040213): the file could not be found, at epdm.interop.epdm.iedmfile5.unlockfile(int32 iparentwnd, string bscomment, int32 iedmunlockflags, object poedmrefcallback)

I am using 2023 SP5.0 PDM, MS VS 2022, Draftsight 2020. Any suggestions would be very helpful.

Thank you,
Hima.

Since its only a part of your code its tricky, but ill take a guess here.

First whenever you add variables add vars.Flush() to update the card properly

I would comment out vars.Closefile(true) this might the problem…

Also its not ideal to use dwgFile.UnlockFile(0, “Nameplate DWG”) using 0 here is not recommended, either use the Parent folder as a reference or try first with Me.Handle.ToInt32()) instead of 0

1 Like

There are several things wrong with this code.

  1. Use IEdmEnumeratorVariable5::Flush. Although CloseFile should be okay.
  2. UnlockFile needs the parent window handle. That’s probably why you are getting exception. I would also call IEdmFile:Refresh before checking the file back into the vault.