This project has moved. For the latest updates, please go here.

DXF Files

Feb 19, 2015 at 12:30 PM
Hi All,

I want to take a single DXF file and pull out the images into separate DXF files.
I have already created a method that will add an image to a blank DXF file.
The problem is I can't get the images from the original file.
Coordinator
Feb 20, 2015 at 12:10 AM
If all you want to do is to create different dxf files with every individual image entity contained in another dxf, this is all you have to do:
// the original file that contains all your images
DxfDocument allImages = DxfDocument.Load("AllImages.dxf");
int counter = 1;
foreach (Image image in allImages.Images)
{
    // create the dxf that will hold every individual image
    DxfDocument doc = new DxfDocument();
    // it is VERY IMPORTANT to make copies of any entity or table object that you want to move between documents,
    // object handles and owner references cannot be shared between dxfs.
    Image copy = (Image) image.Clone();
    // add the copy to the new dxf, the AddEntity method will take care of everything else, its image definition, its layer, linetype, application registries,...
    doc.AddEntity(copy);
    // give a name to the new dxf
    string fileName = string.Format("Image{0}.dxf", counter++);
    // save the file
    doc.Save(fileName);
}
The Images property of a DxfDocument will return a ReadOnlyCollection<Image> object that contains the complete list of Image entities contained in a dxf across all layouts. The bitmap file details (file name, size, and resolution) are stored in the Definition property (an ImageDef object) of the Image entity. You can access the complete list of image definitions through the ImageDefinitions property of a DxfDocument. Also remember that multiple images can share the same definition.

Daniel