Page 1 of 1

Load DWG Image and Save To WMF File

Posted: 16 Jul 2013, 19:39
by cedric
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

Re: Load DWG Image and Save To WMF File

Posted: 17 Jul 2013, 12:06
by support
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.

Re: Load DWG Image and Save To WMF File

Posted: 17 Jul 2013, 15:37
by cedric
Thanks for your help. Works better now.