Procedure for exporting DWG to Stream
Moderators: SDS, support, admin
Procedure for exporting DWG to Stream
I am using CADImport .NET professional and I'm having problems exporting a CADImport.DWGImage to a Stream in bitmap format. The code I use is roughly:
where __loaded is a DWGImage and __imageStream is a MemoryStream. My problem is for some files I get a invalid parameters exception, for others the file renders but not completely (some blocks are left out). I've tried various ways of constructing the DRect which I need to feed to the SaveToStream procedure (including the Extents property of the image), but results are inconsistent, and the documentation for this feature is vague at best.
Your CAD Viewer component seems to be able to load the files correctly. Could you kindly point me to some documentation, code example, or explain how I can export CAD Images completely and correctly to a raster stream?
Thank You
Code: Select all
CADImport.DRect ext = new CADImport.DRect(
0, 0, 0,
__loaded.AbsWidth, __loaded.AbsHeight, 0);
__loaded.SaveToStream(__imageStream, System.Drawing.Imaging.ImageFormat.Bmp,
ext);
Your CAD Viewer component seems to be able to load the files correctly. Could you kindly point me to some documentation, code example, or explain how I can export CAD Images completely and correctly to a raster stream?
Thank You
Re: Procedure for exporting DWG to Stream
Hello!
Can you please send us to support@cadsofttools.com some of your files which SaveToStream fails to export correctly?
Sergey.
Can you please send us to support@cadsofttools.com some of your files which SaveToStream fails to export correctly?
Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
Re: Procedure for exporting DWG to Stream
Unfortunately, I cannot upload the files because they belong to a client and contain sensitive information.
I can tell you though that the files load correctly into your examples, so your component does its job: this is just a documentation failure or something I'm doing wrong on my side. So if you can send me some docs or a description of what your component does to load and display the files correctly (transforms on the files, etc), that would be great.
Thank you very much.
I can tell you though that the files load correctly into your examples, so your component does its job: this is just a documentation failure or something I'm doing wrong on my side. So if you can send me some docs or a description of what your component does to load and display the files correctly (transforms on the files, etc), that would be great.
Thank you very much.
Re: Procedure for exporting DWG to Stream
Hello Vlad,
Would you please try the following code (it is based on Viewer demo):
Sergey.
Would you please try the following code (it is based on Viewer demo):
Code: Select all
private void btnReadToStream_SaveToJPG_Click(object sender, System.EventArgs e)
{
Stream str = File.OpenRead(@"c:\YourFile.dwg");
this.cadImage = new CADImport.DWG.DWGImage();
this.cadImage.LoadFromStream(str);
str.Close();
DRect tmpRect = new DRect(0, 0, 1, 1);
this.cadImage.SetNewMMToPixel(this.cadPictBox.CreateGraphics());
double realScaleDouble = this.cadImage.AbsWidth / this.cadImage.MMToPixelX;
tmpRect.Width = tmpRect.Width * realScaleDouble;
tmpRect.Height = tmpRect.Height * realScaleDouble;
this.cadImage.SaveToFile(@"c:\YourFile.bmp", ImageFormat.Bmp, tmpRect);
}
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
Re: Procedure for exporting DWG to Stream
Thank you for the example; I have tracked one of the problems (image not showing completely) to image loading the wrong layout by default (your editors would probably set CurrentLayoutIndex to 1 somewhere). The other problem is due to the enormous size of the image passed sometimes, which causes GDI+ to crash - resloved by clipping the image.
My other question is, can the CAD Import .NET library write a DWG file in any way?
My other question is, can the CAD Import .NET library write a DWG file in any way?
Re: Procedure for exporting DWG to Stream
Hello!
We recommend to control tmpRect size. Ratser images are very exacting to system resources. That is why if they create large raster file it may cause system crush.
Sergey.
We recommend to control tmpRect size. Ratser images are very exacting to system resources. That is why if they create large raster file it may cause system crush.
Do you mean saving to DWG file format?My other question is, can the CAD Import .NET library write a DWG file in any way?
Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
Re: Procedure for exporting DWG to Stream
Why yes, any way of saving DWG? And, if not, any plans for that in the near future?
Re: Procedure for exporting DWG to Stream
Converting to DWG file format is on our list of things to investigate. We plan to start working on it in the future. Not nearest future.
Sergey.
Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support