Procedure for exporting DWG to Stream

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
VladC
Posts: 4
Joined: 18 Sep 2008, 16:14

Procedure for exporting DWG to Stream

Post by VladC » 18 Sep 2008, 16:27

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:

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);
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

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

Re: Procedure for exporting DWG to Stream

Post by support » 18 Sep 2008, 17:13

Hello!

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

VladC
Posts: 4
Joined: 18 Sep 2008, 16:14

Re: Procedure for exporting DWG to Stream

Post by VladC » 18 Sep 2008, 17:56

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.

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

Re: Procedure for exporting DWG to Stream

Post by support » 19 Sep 2008, 15:49

Hello Vlad,

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);			
}
Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

VladC
Posts: 4
Joined: 18 Sep 2008, 16:14

Re: Procedure for exporting DWG to Stream

Post by VladC » 20 Sep 2008, 15:49

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?

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

Re: Procedure for exporting DWG to Stream

Post by support » 22 Sep 2008, 09:44

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.
My other question is, can the CAD Import .NET library write a DWG file in any way?
Do you mean saving to DWG file format?

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

VladC
Posts: 4
Joined: 18 Sep 2008, 16:14

Re: Procedure for exporting DWG to Stream

Post by VladC » 22 Sep 2008, 14:29

Why yes, any way of saving DWG? And, if not, any plans for that in the near future?

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

Re: Procedure for exporting DWG to Stream

Post by support » 22 Sep 2008, 14:47

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.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply