Page 1 of 1

Load data from DWG file or stream into block

Posted: 12 Jul 2018, 11:10
by StefanChrist
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!

Re: Load data from DWG file or stream into block

Posted: 12 Jul 2018, 22:18
by support
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

Re: Load data from DWG file or stream into block

Posted: 13 Jul 2018, 09:21
by StefanChrist
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

Re: Load data from DWG file or stream into block

Posted: 13 Jul 2018, 22:30
by support
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