Load DWG Image and Save To WMF File
Moderators: SDS, support, admin
Load DWG Image and Save To WMF File
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 :
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
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
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
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.
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
Chat support on Skype: cadsofttools.support
Re: Load DWG Image and Save To WMF File
Thanks for your help. Works better now.