{"id":5610,"date":"2015-02-09T03:08:02","date_gmt":"2015-02-09T11:08:02","guid":{"rendered":"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/How-to-export-draft-images\/ba-p\/290473"},"modified":"2026-03-26T07:16:11","modified_gmt":"2026-03-26T11:16:11","slug":"how-to-export-draft-images","status":"publish","type":"post","link":"https:\/\/blogs.sw.siemens.com\/solidedge\/how-to-export-draft-images\/","title":{"rendered":"How to export draft images"},"content":{"rendered":"<p><P>Have you ever had a need to export <a href=\"http:\/\/en.wikipedia.org\/wiki\/Vector_graphics\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">vector graphics<\/A>&nbsp;or&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Raster_graphics\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">raster graphics<\/A>&nbsp;from a draft file? Over my 15 years of working with Solid Edge, I have found myself in that position many, many times. In this post, I&#8217;ll cover two possible approaches to accomplishing&nbsp;this task.<\/P><P><STRONG>Background<\/STRONG><\/P><P>When a Solid Edge draft file is saved, an <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/dd162600.aspx\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Enhanced Metafile (EMF)<\/A>&nbsp;is embedded into the file for each working sheet. The reason Solid Edge does this is so that their lightweight viewer can easily and quickly render a graphical view of the draft. The EMF format is ideal in this scenario as it is lightweight, vector based and scales perfectly when resized rather than distorting like a raster image would.<\/P><P><IMG alt=\"revision-manager.png\" border=\"0\" title=\"revision-manager.png\" src=\"https:\/\/siemensplm.i.lithium.com\/t5\/image\/serverpage\/image-id\/11533i9275DE6AE08D0953\/image-size\/original?v=mpbl-1&amp;px=-1\" \/><\/P><P>If we can aquire these vector images ourselves, a lot of doors open to what we can accomplish.&nbsp;The question is, how do we access these embedded EMF images for our own purposes.<\/P><P><EM>For technical details about the EMF format, see the <a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/cc230514.aspx\" rel=\"nofollow noopener noreferrer\">Enhanced Metafile Format Specification<\/A>.<\/EM><\/P><P><STRONG>Option 1 &#8211; Solid Edge API + a touch of open source<\/STRONG><\/P><P>If we examine the Solid Edge API, in this case draft.tlb, we will find a&nbsp;CopyEMFToClipboard() method available for a Sheet object.<\/P><PRE>\/\/ Generated .IDL file (by the OLE\/COM Object Viewer)<br \/>\n\/\/<br \/>\n\/\/ typelib filename: draft.tlb<br \/>\n[<br \/>\n  uuid(3E2B3BDC-F0B9-11D1-BDFD-080036B4D502),<br \/>\n  version(1.0),<br \/>\n  helpstring(&#8220;Solid Edge Draft Type Library&#8221;),<br \/>\n]<br \/>\nlibrary SolidEdgeDraft<br \/>\n{<br \/>\n\t[<br \/>\n\t  uuid(FFB20FA0-339B-11CE-956A-08003601DFE5),<br \/>\n\t  helpstring(&#8220;Represents a sheet in a document.&#8221;),<br \/>\n\t  helpcontext(0x00007537)<br \/>\n\t]<br \/>\n\tdispinterface Sheet {<br \/>\n\t\tproperties:<br \/>\n\t\tmethods:<br \/>\n\t\t\t[id(0x000000de), helpstring(&#8220;Copies an enhanced metafile to the operating system clipboard.&#8221;), helpcontext(0x0000756c)]<br \/>\n\t\t\tvoid CopyEMFToClipboard();<br \/>\n\t};<br \/>\n};<\/PRE><P>The&nbsp;CopyEMFToClipboard() method&nbsp;creates an in-memory EMF and places it on the clipboard in <a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ff729168.aspx\" rel=\"nofollow noopener noreferrer\">CF_ENHMETAFILE<\/A>&nbsp;format. In order to access the EMF data, we use the&nbsp;<a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms649039.aspx\" rel=\"nofollow noopener noreferrer\">GetClipboardData()<\/A>&nbsp;function which returns a pointer to a HMETAFILE. For most (non C++) programmers, everything comes to a screeching halt right there. Unless you have ever dabbled with C++, you likely have no idea how to proceed.<\/P><P>Fortunately, it&#8217;s 2015 and people actually share code. If you don&#8217;t want to dig into the gory details of how to access the EMF on the clipboard, you can easily install the <a target=\"_blank\" href=\"https:\/\/www.nuget.org\/packages\/SolidEdge.Community\/\" rel=\"nofollow noopener noreferrer\">SolidEdge.Community NuGet package<\/A>&nbsp;and leverage pre-built extension methods to gain access to the actual EMF. If you&#8217;re not familiar with NuGet, no worries, I&#8217;ve got you covered in my&nbsp;<a target=\"_blank\" href=\"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Developer-Blog\/How-to-use-NuGet-for-Solid-Edge-custom-development\/ba-p\/288791\" rel=\"noopener noreferrer\">How to use NuGet for Solid Edge custom development<\/A>&nbsp;post. If you&#8217;re not comfortable using an open source library, no problem! You can view the full source code for&nbsp;<a target=\"_blank\" href=\"https:\/\/github.com\/SolidEdgeCommunity\/SolidEdge.Community\" rel=\"nofollow noopener noreferrer\">SolidEdge.Community on GitHub<\/A>. Specifically for this article, you&#8217;ll want to reference&nbsp;<a target=\"_blank\" href=\"https:\/\/github.com\/SolidEdgeCommunity\/SolidEdge.Community\/blob\/master\/src\/SolidEdge.Community\/Extensions\/SheetExtensions.cs\" rel=\"nofollow noopener noreferrer\">SheetExtensions.cs<\/A>&nbsp;and look for the&nbsp;SaveAsEnhancedMetafile() extension method. Extension methods like this enhance the base Solid Edge API by overlaying additional methods to classes like SolidEdgeDraft.Sheet.<\/P><P>For an example of how to use the&nbsp;<SPAN>SaveAsEnhancedMetafile() extension method, head over to the <a target=\"_blank\" href=\"https:\/\/github.com\/SolidEdgeCommunity\" rel=\"nofollow noopener noreferrer\">Solid Edge Community on GitHub<\/A>. There is a <a target=\"_blank\" href=\"https:\/\/github.com\/SolidEdgeCommunity\/Samples-CS\/blob\/master\/Applications\/ExportSheets\/ExportSheets\/Program.cs\" rel=\"nofollow noopener noreferrer\">C# sample<\/A>&nbsp;and <a target=\"_blank\" href=\"https:\/\/github.com\/SolidEdgeCommunity\/Samples-VB\/blob\/master\/Applications\/ExportSheets\/ExportSheets\/Program.vb\" rel=\"nofollow noopener noreferrer\">Visual Basic sample<\/A>&nbsp;available. The following is a short snippet demonstrating the usage.<\/SPAN><\/P><PRE>foreach (SolidEdgeDraft.Sheet sheet in workingSection.Sheets)<br \/>\n{<br \/>\n    \/\/ Note: SaveAsEnhancedMetafile() is an extension method from SolidEdge.Community.dll.<br \/>\n    sheet.SaveAsEnhancedMetafile(emfFileName);<br \/>\n}<\/PRE><P>I should also&nbsp;mention that the&nbsp;GetEnhancedMetafile() extension method is also available. This will return a .NET friendly&nbsp;<a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.drawing.imaging.metafile.aspx\" rel=\"nofollow noopener noreferrer\">System.Drawing.Imaging.Metafile<\/A>.<\/P><P>Note that in order to enabled these extension methods, you must use the C# using keyword or the Visual Basic Imports keyword.<\/P><PRE>using SolidEdgeCommunity.Extensions;<\/PRE><P>&nbsp;or<\/P><PRE>Imports SolidEdgeCommunity.Extensions<\/PRE><P><STRONG>Option 2 &#8211; Open source only<\/STRONG><\/P><P>As an Applications Architect, I often find myself with project requirements that don&#8217;t always agree with existing software APIs. For example, I&#8217;ve needed&nbsp;to process and export 11,000+ draft files as fast as possible. I&#8217;ve also needed to perform this export process in an automated server environment. Automating Solid Edge as shown in Option 1 was not really a (good) option as Solid Edge is a UI application.<\/P><P>Considering these requirements, the <a target=\"_blank\" href=\"https:\/\/www.nuget.org\/packages\/SolidEdge.Community.Reader\" rel=\"nofollow noopener noreferrer\">SolidEdge.Community.Reader NuGet package<\/A>&nbsp;was born. Full source code can be found on the <a target=\"_blank\" href=\"https:\/\/github.com\/SolidEdgeCommunity\/SolidEdge.Community.Reader\" rel=\"nofollow noopener noreferrer\">SolidEdge.Community.Reader GitHub page<\/A>. Installing this NuGet package into your project adds a reference to the SolidEdge.Community.Reader.dll assembly. The assembly has the ability to read Solid Edge files natively and perform the same export operation without the need to have Solid Edge running.<\/P><P>For an example of how to use the&nbsp;<a target=\"_blank\" href=\"https:\/\/www.nuget.org\/packages\/SolidEdge.Community.Reader\" rel=\"nofollow noopener noreferrer\">SolidEdge.Community.Reader NuGet package<\/A><SPAN>, head over to the <a target=\"_blank\" href=\"https:\/\/github.com\/SolidEdgeCommunity\" rel=\"nofollow noopener noreferrer\">Solid Edge Community on GitHub<\/A>. There is a <a target=\"_blank\" href=\"https:\/\/github.com\/SolidEdgeCommunity\/Samples-CS\/blob\/master\/Applications\/ExportSheets\/ExportSheets\/Program.cs\" rel=\"nofollow noopener noreferrer\">C# sample<\/A>&nbsp;and <a target=\"_blank\" href=\"https:\/\/github.com\/SolidEdgeCommunity\/Samples-VB\/blob\/master\/Applications\/ExportSheets\/ExportSheets\/Program.vb\" rel=\"nofollow noopener noreferrer\">Visual Basic sample<\/A>&nbsp;available. The following is a short snippet demonstrating the usage.<\/SPAN><\/P><PRE>\/\/ Open the file.<br \/>\nusing (var draftDocument = DraftDocument.Open(options.FileName))<br \/>\n{<br \/>\n    \/\/ Process each sheet.<br \/>\n    foreach (var sheet in draftDocument.Sheets)<br \/>\n    {<br \/>\n        \/\/ Save EMF.<br \/>\n        sheet.SaveAsEmf(emfFileName);<br \/>\n    }<br \/>\n}<\/PRE><P>In my particular project, using the&nbsp;<a target=\"_blank\" href=\"https:\/\/www.nuget.org\/packages\/SolidEdge.Community.Reader\" rel=\"nofollow noopener noreferrer\">SolidEdge.Community.Reader NuGet package<\/A>&nbsp;yielded the following results.<\/P><UL><LI><SPAN style=\"line-height: 18px;\"><STRONG>DFT count<\/STRONG>: 11,450 (65 files processed  sec)<\/li>\n<p><LI><STRONG>EMF count<\/STRONG>: 24,202 (137 files exported  sec)<\/LI><LI><STRONG>Duration<\/STRONG>: 2 minutes 57 seconds<\/LI><\/UL><P>65 DFT files per second! 137 EMF files per second! Now that&#8217;s what I&#8217;m talking about. Honestly, I was a bit mind blown when I saw the results. It goes without saying that a lot of hard work has gone into the&nbsp;<a target=\"_blank\" href=\"https:\/\/www.nuget.org\/packages\/SolidEdge.Community.Reader\" rel=\"nofollow noopener noreferrer\">SolidEdge.Community.Reader NuGet package<\/A>. It is an extremely efficient and fast bit of code.&nbsp;<\/P><P><STRONG>Conclusion<\/STRONG><\/P><P>In this post, I demonstrated 2 methods of how to access and export an EMF for each working sheet in a draft. I focused on the EMF format but&nbsp;the<SPAN>&nbsp;<\/SPAN><a target=\"_blank\" href=\"https:\/\/github.com\/SolidEdgeCommunity\/Samples-CS\/blob\/master\/Applications\/ExportSheets\/ExportSheets\/Program.cs\" rel=\"nofollow noopener noreferrer\">C# sample<\/A><SPAN>&nbsp;and <\/SPAN><a target=\"_blank\" href=\"https:\/\/github.com\/SolidEdgeCommunity\/Samples-VB\/blob\/master\/Applications\/ExportSheets\/ExportSheets\/Program.vb\" rel=\"nofollow noopener noreferrer\">Visual Basic sample<\/A><SPAN>&nbsp;also show you how to convert the EMF to other image types.<\/SPAN><\/P><P>Reasons for the ability to do this include but not limited to:<\/P><UL><LI>Displaying draft files outside of Solid Edge<\/LI><LI>Converting&nbsp;EMFs to other formats for other purposes.<\/LI><LI>Batch printing. *You can render EMFs directly to printers \ud83d\ude09<\/LI><\/UL><P><STRONG>More than anything, I want you all to be aware of the usefullness and power of open source. In my opinion, if you&#8217;re not leveraging andor contributing to what open source has to offer, you&#8217;re doing it wrong.<\/STRONG><\/P><P><IMG alt=\"valve_house.jpg\" border=\"0\" title=\"valve_house.jpg\" src=\"https:\/\/siemensplm.i.lithium.com\/t5\/image\/serverpage\/image-id\/11531i22A70572BBA0A2B6\/image-size\/original?v=mpbl-1&amp;px=-1\" \/><\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever had a need to export vector graphics&nbsp;or&nbsp;raster graphics&nbsp;from a draft file? Over my 15 years of working with Solid Edge, I have found myself in that position many, many ti&#8230;<\/p>\n","protected":false},"author":61367,"featured_media":5611,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spanish_translation":"","french_translation":"","german_translation":"","italian_translation":"","polish_translation":"","japanese_translation":"","chinese_translation":"","footnotes":""},"categories":[1],"tags":[],"industry":[],"product":[],"coauthors":[],"class_list":["post-5610","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news"],"featured_image_url":"https:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/revision-manager.png","_links":{"self":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/5610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/users\/61367"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/comments?post=5610"}],"version-history":[{"count":3,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/5610\/revisions"}],"predecessor-version":[{"id":5615,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/5610\/revisions\/5615"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/media\/5611"}],"wp:attachment":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/media?parent=5610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/categories?post=5610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/tags?post=5610"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/industry?post=5610"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/product?post=5610"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/coauthors?post=5610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}