Products

Closing Documents

By jnewell

Prior to Solid Edge ST8 being released, one of the developers emailed me to give me a heads up on a new API to handle closing documents. The problem has always been that in order to close a document, you had to call the Close() method of that object. The problem was that Solid Edge couldn’t fully close the document because we were still holding a reference to it. In ST8, we have a new option available.

If you download the lastest Samples for Solid Edge on GitHub, you’ll notice a new OpenClose project. I wrote this project to demonstrate our options for closing documents. Rather than copypasting the entire code in this post, I’ll highlight the important part. The code below is C# but the VB version is available on GitHub.

The main point to notice is that starting with ST8, the Documents collection has a new CloseDocument() method. This method allows you to fully release your reference to the document prior to closing it. Something we have not had the ability to do prior to ST8.

// Prior to ST8, we needed a reference to a document to close it.
// That meant that SE can’t fully close the document because we’re holding a reference.
if (solidEdgeVesion.Major < 108)
{
// Close the document.
document.Close();

// Release our reference to the document.
Marshal.FinalReleaseComObject(document);
document = null;

// Give SE a chance to do post processing (finish closing the document).
application.DoIdle();
}
else
{
// Release our reference to the document.
Marshal.FinalReleaseComObject(document);
document = null;

// Starting with ST8, the Documents collection has a CloseDocument() method.
documents.CloseDocument(file.FullName, false, Missing.Value, Missing.Value, true);
}

The definition of the Documents.CloseDocument() method look like:

void CloseDocument(String Filename, [Object SaveChanges], [Object SaveAsFileName], [Object RouteWorkbook], [Object DoIdle])
Member of SolidEdgeFramework.Documents

You will want to pass true to the DoIdle argument. That will prevent you from having to call application.DoIdle() manually.

Be sure and check out the Solid Edge ST8 – What’s New SDK topic. I always enjoy browsing the What’s New pages for each version to see what goodies the development team gave us.

Jason Newell

Jason is a Solutions Architect for Charles Machine Works in Perry, Oklahoma. As a 21 year IT veteran, Jason is well versed in a broad range of software technologies and programming languages. In 2005, Jason started JasonNewell.NET, a website dedicated to expanding the Solid Edge developer community and offering consulting services. Through his website, he was able to acquire Siemens PLM Solution Partner status and soon began consulting for Siemens PLM directly. Through his consulting efforts with Siemens PLM, Jason takes a leading role in expanding the developer community by contributing to the Solid Edge SDK, authoring open source projects and speaking at conferences.

More from this author

Leave a Reply

This article first appeared on the Siemens Digital Industries Software blog at https://blogs.sw.siemens.com/solidedge/closing-documents/