Merge two dxf into one

Dec 21, 2012 at 12:24 PM


I would like to insert a block that is stored in a dxf into an other dxf.

So I would like to merge those two dxf files. Is this possible with this C-libary?



Dec 21, 2012 at 6:14 PM
Edited Dec 21, 2012 at 6:16 PM

Yes, it is possible and also easy to do. Here you have an example code on how to do it.

        private static void BlockAdd()
            DxfDocument firstDxf = new DxfDocument();
            firstDxf.Load("original drawing.dxf");
            string blockName = "MyBlockName";
            Block myBlock = null;

            // We need to find the block definition we want given a name.
            // This method is a bit cumbersome, next time I will allow better access to the block dictionary
            // to be able to get a block definition only with myBlock = firstDxf.Blocks[blockName];
// or something like myBlock = firstDxf.GetBlock(blockName);

 // and also to add directly table objects to the document. for (int indexBlock = 0; indexBlock < firstDxf.Blocks.Count; indexBlock++) { if (firstDxf.Blocks[indexBlock].Name == blockName) { myBlock = firstDxf.Blocks[indexBlock]; break; } } DxfDocument secondDxf = new DxfDocument(); if (myBlock != null) { Insert insertBlock = new Insert(myBlock); secondDxf.AddEntity(insertBlock); } secondDxf.Save("new drawing.dxf", DxfVersion.AutoCad2000); }

You should be able to do this with any kind of entity.


Dec 21, 2012 at 7:36 PM

Thanks for your quick reply.

I will try it this week.

Also thanks for the code, it will be very help full.