Solid Edge Framework Type Library > Application Object : DoIdle Method |
Visual Basic |
---|
Public Sub DoIdle() |
In automation situations where a client is keeping Solid Edge extremely busy, Solid Edge will not have an opportunity to perform background tasks. Depending on the automation scenario, this could mean that certain objects may not be in an expected state.
One of the most important tasks that DoIdle() performs is to ensure that a SolidEdgeDocument gets fully released after SolidEdgeDocument.Close is called. This is significant because even though SolidEdgeDocument.Close is called, the calling client is still holding a reference to the COM object via IUnknown.AddRef(). It is recommended that DoIdle() be called after any document is closed if the client that closed the document is going to do more processing before returning control to Solid Edge.
The following list are examples of background tasks that Solid Edge may perform during DoIdle() processing.
Imports System.IO Imports System.Runtime.InteropServices Module Example <STAThread()> _ Sub Main() Dim objApplication As SolidEdgeFramework.Application = Nothing Dim objFolder As DirectoryInfo = Nothing Dim objFiles() As FileInfo = Nothing Dim objFile As FileInfo = Nothing Try OleMessageFilter.Register() ' Attach to Solid Edge objApplication = Activator.CreateInstance(Type.GetTypeFromProgID("SolidEdge.Application")) objApplication.Visible = True objApplication.DisplayAlerts = False objFolder = New DirectoryInfo("C:\My Drafts") objFiles = objFolder.GetFiles("*.dft") For Each objFile In objFiles ConvertDraftToDxf(objFile, objApplication) Next Catch ex As Exception Console.WriteLine(ex.Message) Finally OleMessageFilter.Revoke() End Try End Sub Sub ConvertDraftToDxf(ByVal objFile As FileInfo, ByVal objApplication As SolidEdgeFramework.Application) Dim objDraftDocument As SolidEdgeDraft.DraftDocument = Nothing Dim objDocuments As SolidEdgeFramework.Documents = Nothing Dim objSections As SolidEdgeDraft.Sections = Nothing Dim objSection As SolidEdgeDraft.Section = Nothing Dim objSectionSheets As SolidEdgeDraft.SectionSheets = Nothing Dim objSheet As SolidEdgeDraft.Sheet = Nothing Dim strDxfPath As String Try objDocuments = objApplication.Documents objDraftDocument = objDocuments.Open(objFile.FullName) objSections = objDraftDocument.Sections ' Get the "Working" section. objSection = objSections.WorkingSection objSectionSheets = objSection.Sheets ' Save each working section sheet as dxf. For Each objSheet In objSectionSheets ' Build path of dxf to be created. strDxfPath = String.Format( _ "{0} ({1}).dxf", _ Path.Combine(objFile.Directory.FullName, _ Path.GetFileNameWithoutExtension(objFile.Name)), _ objSheet.Name) ' Activate the current sheet. objSheet.Activate() ' Save the dxf. objDraftDocument.SaveAs(strDxfPath) Marshal.ReleaseComObject(objSheet) objSheet = Nothing Next Catch ex As Exception Console.WriteLine(ex.Message) Finally If Not objSheet Is Nothing Then Marshal.ReleaseComObject(objSheet) End If If Not objSectionSheets Is Nothing Then Marshal.ReleaseComObject(objSectionSheets) End If If Not objSection Is Nothing Then Marshal.ReleaseComObject(objSection) End If If Not objSections Is Nothing Then Marshal.ReleaseComObject(objSections) End If If Not objDocuments Is Nothing Then Marshal.ReleaseComObject(objDocuments) End If If Not objDraftDocument Is Nothing Then ' Close draft file without saving any changes. objDraftDocument.Close(False) Marshal.ReleaseComObject(objDraftDocument) ' Give Solid Edge time to fully close the document. objApplication.DoIdle() End If End Try End Sub End Module