AnsweredAssumed Answered

The object invoked has disconnected from its clients

Question asked by Arne Morten Fredriksen on Sep 24, 2014
Latest reply on Oct 15, 2015 by Nicolas Ziegler

Hi,

 

I'm trying to create an ePDM addin that handles rebuilding, and reopening of a drawing inside SolidWorks.

The code is executed at the EdmCmd_PostState event in ePDM. After the code has executed the drawing has change state, it has been rebuilded and everything looks alright. But, an error message is thrown every time and the ePDM task pane inside SolidWorks is not updated.

 

The error message says:

Could not Change the State of the file.

Error=0x80010108

Description='The object invoked has disconnected from its clients.'

 

I have commented the part of the code who is responsible for the error to appear.

Here is the stripped down code:

 

Case EdmCmdType.EdmCmd_PostState

     'Get file and folder object.

     Dim oFile As EdmLib.IEdmFile7 = oVault.GetObject(EdmLib.EdmObjectType.EdmObject_File, ppoData(nIndex).mlObjectID1)

     Dim oFolder As EdmLib.IEdmFolder6 = oVault.GetObject(EdmLib.EdmObjectType.EdmObject_Folder, ppoData(nIndex).mlObjectID2)

 

     'Full file path.

     Dim sFullFilePath As String = "C:\TestVault\CAD\Part1.slddrw"

 

     'Get latest version of the file.

     oFile.GetFileCopy(0, 0)

 

     'Check the file out.

     oFile.LockFile(oFolder.ID, 0)

 

     'Connect to SolidWorks.

     Dim oSolidWorksApplication As Object = Nothing

     oSolidWorksApplication = GetObject(, "SldWorks.Application")

 

     'Activate the drawing document in SolidWorks.

     Dim nError As Integer

     Dim oDocument As SldWorks.ModelDoc2

     oDocument = oSolidWorksApplication.ActivateDoc2(sFullFilePath, True, nError)

 

     'Rebuild drawing.

     oDocument.Rebuild(SwConst.swRebuildOptions_e.swForceRebuildAll)

 

     'Save the rebuilded drawing.

     oDocument.Save2(True)

 

     'Reopen the document in SolidWorks.

     Dim nOption As System.Int32 = 0

     Dim nValue As System.Int32

     Dim oNewDoc As SldWorks.ModelDoc2 = Nothing

 

     '----THIS IS THE LINE OF CODE WHO TRIGGERS THE ERROR MESSAGE----

     nValue = DirectCast(oSolidWorksApplication, SldWorks.SldWorks).CloseAndReopen(oDocument, nOption, oNewDoc) 'The return value nValue is 0 meaning nothing went wrong.

     '---------------------------------------------------------------

 

     oDocument = Nothing

     oNewDoc = Nothing

 

     'Check in the document.

     oFile.UnlockFile(0, "Saved Rebuilded drawing")

 

     System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oSolidWorksApplication)

     oSolidWorksApplication = Nothing

     GC.Collect()

     GC.WaitForPendingFinalizers()

     GC.Collect()

     GC.WaitForPendingFinalizers()

'--------------------------------------------------------------------------------------------------------------------------------------------

 

Does anyone have a clue of what is happening here???

I have debugged this for 2 days now without any result.

Any help will be appreciated.

 

Thanks in advance.

Outcomes