void DoOpenCloseInternal(string fileName) { //SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgeFramework.SolidEdgeDocument document = null; // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); try { // Get reference to application object. var application = this.Application; // Get reference to documents collection. documents = application.Documents; // Open the document. document = (SolidEdgeFramework.SolidEdgeDocument)documents.Open(fileName); // Not sure why but as of ST8, I had to add a Sleep() call to prevent crashing... System.Threading.Thread.Sleep(500); // Do idle processing. application.DoIdle(); // Close the document. document.Close(false); //System.Threading.Thread.Sleep(500); // Do idle processing. application.DoIdle(); documents.Close(); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
void DoOpenSaveInternal(string filePath, OpenSaveSettings openSaveSettings) { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); try { SolidEdgeFramework.Application application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true); SolidEdgeFramework.Documents documents = null; SolidEdgeFramework.SolidEdgeDocument document = null; application.DisplayAlerts = openSaveSettings.Application.DisplayAlerts; application.Visible = openSaveSettings.Application.Visible; if (openSaveSettings.Application.DisableAddins == true) { DisableAddins(application); } // Disable (most) prompts. application.DisplayAlerts = false; // Get a reference to the documents collection. documents = application.Documents; // Close any documents that may be left open for whatever reason. documents.Close(); // Open the file. document = documents.Open <SolidEdgeFramework.SolidEdgeDocument>(filePath); application.DoIdle(); if (document != null) { // Environment specific routines. if (document is SolidEdgeAssembly.AssemblyDocument) { DoOpenSave((SolidEdgeAssembly.AssemblyDocument)document, openSaveSettings.Assembly); } else if (document is SolidEdgeDraft.DraftDocument) { DoOpenSave((SolidEdgeDraft.DraftDocument)document, openSaveSettings.Draft); } else if (document is SolidEdgePart.PartDocument) { DoOpenSave((SolidEdgePart.PartDocument)document, openSaveSettings.Part); } else if (document is SolidEdgePart.SheetMetalDocument) { DoOpenSave((SolidEdgePart.SheetMetalDocument)document, openSaveSettings.SheetMetal); } else if (document is SolidEdgePart.WeldmentDocument) { DoOpenSave((SolidEdgePart.WeldmentDocument)document, openSaveSettings.Weldment); } // Save document. document.Save(); // Close document. document.Close(); application.DoIdle(); } } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }