Load data from DWG file or stream into block

Discuss and ask questions about CAD .NET library.

Moderators: support, SDS, admin

Post Reply
StefanChrist
Posts: 22
Joined: 06 Jul 2018, 10:52

Load data from DWG file or stream into block

Post by StefanChrist » 12 Jul 2018, 11:10

Hello support,

we would like to store DWG data (small structures like circles, polylines..) in our database and restore them as blocks to add them to the exisiting drawing. Is there a way to realize that?

Thank you!

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

Re: Load data from DWG file or stream into block

Post by support » 12 Jul 2018, 22:18

Hello Stefan,

Could you please tell in what data format you would like to store DWG entity data and how you would like to read it?

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

StefanChrist
Posts: 22
Joined: 06 Jul 2018, 10:52

Re: Load data from DWG file or stream into block

Post by StefanChrist » 13 Jul 2018, 09:21

Hello Mikhail,

we would like to store DWG from "BricsCAD" in our dabase (as DWG) and restore it from there. We want to create drawings with "BricsCAD" and use those as blocks in new drawings within CAD .NET.

Thank you!

Stefan

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

Re: Load data from DWG file or stream into block

Post by support » 13 Jul 2018, 22:30

Hello Stefan,

CAD .NET API allows to insert external DWG drawings to a current drawing (CADImage). The inserted DWG drawing acts as an external reference (XREF) with respect to the current drawing, its contents are not written in the current drawing file that helps in keeping the file size of the current drawing small. However, the external reference data can be accessed from the current CADImage through a corresponding XREF block.

Let's assume that a BricsCAD DWG drawing is stored in a byte array (byte[]) and you want to insert it into a new drawing created from scratch in CAD .NET, at a given point, with certain scale and rotation angle. The code example below shows how to achieve that.

Code: Select all

using System.IO;
using CADImport;

	...

	CADImage cadImage;
	byte[] dwgFile;		// DWG from BricsCAD

	...

	private void AddExternalDWGFromByteArray(CADImage curDrawing, byte[] dwgBytes, string dwgFilePath, DPoint insPoint, DPoint scale, float rotAngle)
	{
	    // Write all the DWG bytes to a .dwg file on the disk
	    File.WriteAllBytes(dwgFilePath, dwgBytes);
	    // Create a CADImage object for the external .dwg file
	    CADImage xRefImage = CADImage.CreateImageByExtension(dwgFilePath);
	    // Load the external .dwg file to the CADImage object
	    xRefImage.LoadFromFile(dwgFilePath);
	    // Insert the external reference into the current drawing
	    curDrawing.AddScaledDXF(xRefImage, dwgFilePath, insPoint, scale, rotAngle);
	}

	...

	// Create a new drawing
	cadImage = new CADImage();
	cadImage.InitialNewImage();
	AddExternalDWGFromByteArray(cadImage, dwgFile, @"c:\xrefs\drawing1.dwg", new DPoint(100, 100, 0), new DPoint(1, 1, 1), 0);
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply