EMF problem with 6.3.2942.31648

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
Robert Simpson
Posts: 12
Joined: 11 Dec 2007, 21:38
Location: USA

EMF problem with 6.3.2942.31648

Post by Robert Simpson » 31 Jan 2008, 20:16

Given the following snippet of code, which generates several variations of EMF's from a DWG:

Code: Select all

      CADImport.CADImage img = new CADImport.DWG.DWGImage();
      img.LoadFromFile(@"e:\Sample Matter\DWG\456253.DWG");
      img.SetCurrentLayout(img.DefaultLayoutIndex);
      using (System.Windows.Forms.Form f = new System.Windows.Forms.Form())
      using (System.Drawing.Graphics g = f.CreateGraphics())
      using (System.Drawing.Imaging.Metafile mfo = new Metafile("c:\\out.emf", g.GetHdc(), EmfType.EmfOnly))
      using (Graphics go = Graphics.FromImage(mfo))
      {
        <font color="green">//img.Draw(go, new RectangleF(0, 0, (float)(img.AbsWidth * 1000), (float)(img.AbsHeight * 1000)));</font id="green">

        g.ReleaseHdc();
        img.ExportToMetafile("c:\\out1.emf", new CADImport.DRect(0, 0, img.AbsWidth * 1000.0, img.AbsHeight * 1000.0));
        System.Drawing.Imaging.Metafile mf = new System.Drawing.Imaging.Metafile("c:\\out1.emf");

        using (System.Drawing.Imaging.Metafile mfnew = new System.Drawing.Imaging.Metafile("c:\\out2.emf", g.GetHdc(), System.Drawing.Imaging.EmfType.EmfOnly))
        using (Graphics gnew = Graphics.FromImage(mfnew))
        {
          metafile1 = mf;
          gnew.EnumerateMetafile(mf, new Point(0, 0), new Graphics.EnumerateMetafileProc(MetafileCallback));
        }
      }
When I run this, all the EMF files are empty. If I uncomment the above commented line which first renders the image to an EMF surface using Draw(), then all the subsequent EMF's are rendered correctly to their respective locations.

Robert Simpson
Posts: 12
Joined: 11 Dec 2007, 21:38
Location: USA

Post by Robert Simpson » 31 Jan 2008, 22:19

On a similar note ... I use this code to feed to another module so I can create a fixed document format file.

On the older version of CADImport I was using (6.0.2645.16081) generated an EMF with text drawing instructions -- such that my final output document had selectable text.

The latest version, with no other code changes, doesn't generate an EMF that I can get selectable text from.

Robert Simpson
Posts: 12
Joined: 11 Dec 2007, 21:38
Location: USA

Post by Robert Simpson » 01 Feb 2008, 01:27

Alright I've figured out why the generated EMF files no longer have text in them ...

You've set the SmoothingMode on the Graphics object to Antialias when you render the EMF file. Can you guys either turn that off or make it user-selectable in CADConst?

Robert

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 01 Feb 2008, 17:32

Hello!

Could you please explain the main goal of your metafile import-export actions?

Sergey.

Please post questions to the forum or write to support@cadsofttools.com

Robert Simpson
Posts: 12
Joined: 11 Dec 2007, 21:38
Location: USA

Post by Robert Simpson » 01 Feb 2008, 18:18

Sure ... here's what I need to do with a DWG:

My end goal is to convert a DWG to PDF with selectable text. This is a small piece of a much larger program to convert many file types to PDF.

The older version of CADImport produced an EMF which I was able to rewrite to PDF. Debugging the metafile playback, I was able to see the various EMF Text drawing functions being played back.

The newer version however, when playing back the EMF records, there are no text drawing functions. Further debugging shows that CADImport sets the Antialias setting to ON, which triggers a different rendering method for drawing text to the metafile -- resulting in no actual text drawing functions being called. The characters are actually drawn with lines from GDI+.

That's the more critical of my needs. Ideally I'd like to be able to call LoadFromFile() to load the DWG, and ExportToMetafile() to export to EMF. The old version allowed me to do that, but the new version requires that I first call Draw() to render the dwg to a hidden surface.

Some bells and whistles that'd be nice would be:
- The ability to set the font smoothing mode in CADConst
- The ability to specify the EMF type in CADConst (EmfOnly, EmfPlusDual, EmfPlus)

Thanks for your time

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 04 Feb 2008, 12:39

Hello Robert,

We suppose there is a little bit easier way for converting DWG file contents to anithing you need. CAD Import .NET gives access to all entities inside of DWG file including texts. The following code is based on <b>Viewer</b> demo:

Code: Select all

<font color="blue">for</font id="blue"> (<font color="blue">int</font id="blue"> i=0;i<<font color="blue">this</font id="blue">.cadImage.CurrentLayout.Converter.GetCounts(CADImport.FaceModule.ConvSection.Entities);i++)
{
	<font color="blue">if</font id="blue"> (<font color="blue">this</font id="blue">.cadImage.CurrentLayout.Converter.GetSection(CADImport.FaceModule.ConvSection.Entities).Entities[i] <font color="blue">is</font id="blue"> CADText)
	{
		CADText entText = (CADText)<font color="blue">this</font id="blue">.cadImage.CurrentLayout.Converter.GetSection(CADImport.FaceModule.ConvSection.Entities).Entities[i];
Is this way is acceptable for you?

Sergey.


Please post questions to the forum or write to support@cadsofttools.com

Robert Simpson
Posts: 12
Joined: 11 Dec 2007, 21:38
Location: USA

Post by Robert Simpson » 04 Feb 2008, 17:43

I'll look into it ... but currently I use EMF because its easy to play back to a printer device -- in this case the "Adobe PDF" or "Ghostscript" printer driver.

Robert

Robert Simpson
Posts: 12
Joined: 11 Dec 2007, 21:38
Location: USA

Post by Robert Simpson » 05 Feb 2008, 17:43

For now I've reverted to using an older version of the cadimport library, which is kindof unfortunate. There's no way for me to write a whole rendering and translation program to draw the CAD drawing to PDF without purchasing another PDF library separately.

Also -- I couldn't find any of the objects you referenced in the CADImport.DLL assembly. CurrentLayout, ConvSection, CADText, etc.

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 05 Feb 2008, 18:09

Hello!

<ol type="1"><li>There is an opportunity to prepare CADImport.DLL which will create EMF with readable texts. If you are interested, please contact us to support@vadsofttools.com with a reference to this topic in the e-mail.</li>
<li>We plan to add export to PDF file format soon.</li></ol id="1">
Sergey.

Please post questions to the forum or write to support@cadsofttools.com

Post Reply