Load DWG Image and Save To WMF File

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
cedric
Posts: 2
Joined: 16 Jul 2013, 19:23

Load DWG Image and Save To WMF File

Post by cedric » 16 Jul 2013, 19:39

Hi Folks,

I'm trying to convert a DWG file to WMF file by following the great sample ViewerDemo code.
I have almost do the job but i have got an exception "Object reference not set to an instance of an object" on ExportToMetafile method.
I'm scratching my head on what i'm doing wrong but did find out so far.

Below my peace of code :

Code: Select all

	    
            string strFileName = string.Empty;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "dwg files (*.dwg)|*.dwg";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                strFileName = openFileDialog1.FileName;
            }

            if (strFileName.Equals(string.Empty))
                return;

            CADImage cadImage = null;
            if (cadImage == null)
            {
                cadImage = new CADImage();
                cadImage.InitialNewImage();
                cadImage.UseDoubleBuffering = false;
            }
           cadImage.LoadFromFile(strFileName);
	     DRect tmpRect = new DRect(0, 0, 1000, 1000);
            ImageFormat imgFrm = ImageFormat.Wmf;
            cadImage.DefaultColor = Color.Black;
            cadImage.DefaultColor = CADImport.CADConst.clNone;
            cadImage.ExportToMetafile(@"c:\Test.wmf", tmpRect); // => Get the message : "Object reference not set to an instance of an object"
           //cadImage.SaveToFile(@"c:\Test.wmf", ImageFormat.Wmf, tmpRect); => Works
I have also tried the SaveToFile method who works pretty well.
So wondering what is the difference between SaveToFile and ExportToMetafile cause both are able to generate WMF file ?
One last question. How get the current resolution of the DWG file. Actually, i would like to genreate WMF file with the same resolution of DWG file.

Thanks in advance for your help,

Best regards,

Cedric

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

Re: Load DWG Image and Save To WMF File

Post by support » 17 Jul 2013, 12:06

Hello.
Please complete visualization of imported drawing before exporting it with ExportToMetafile method. SaveToFile method creates a raster file. Even if you receive emf/wmf extension with SaveToFile, the file structure will be raster.

Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

cedric
Posts: 2
Joined: 16 Jul 2013, 19:23

Re: Load DWG Image and Save To WMF File

Post by cedric » 17 Jul 2013, 15:37

Thanks for your help. Works better now.

Post Reply