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

How to insert a block from another drawing (Might be in dxf format)

Oct 14, 2014 at 4:32 AM
Dear Mr.Daniyal,

How can we insert a block from external drawing.

Regards,
Muthu
Oct 14, 2014 at 7:06 AM
Yes. I found. It is working fine. now...
 Dim block As Block = Block.Load("D:\rmk\blocks.dxf")
    Dim insert As New Insert(Block, New Vector2(10, 10))
        insert.Layer = dxf.Layers("Primary")
        dxf.Blocks.Add(block)
        dxf.AddEntity(insert)
Thanks...
Coordinator
Oct 14, 2014 at 6:28 PM
I guess you already answered your own question.

Through the Block.Load method you will create a new block with the contents of the specified dxf, keep in mind that only entities defined in ModelSpace will be used. If what you need is to load a specific block of a dxf, you need to load the whole document first with DxfDocument.Load, get the requiered one from the blocks list, and use it to create the insert entity.

There is no need to add the block to document prior to adding the Insert entity to the document, The DxfDocument.AddEntity will do it for you in the same way as layers, styles, linetypes,... but there is no harm on doing it. Add the block to the blocks list only if you need this block definition to appear in the drawing without any actual references.

Daniel
Oct 15, 2014 at 12:18 PM
Thank you so much Mr.Daniel.

Keep it up your great work.

Do you work with Realdwg ?

Regards,
Muthu
Coordinator
Oct 16, 2014 at 4:19 PM
No, I have never worked with RealDWG, that is a way overpriced piece of software, something that Autodesk should have released for free in the first place.

Daniel
Dec 13, 2014 at 1:29 AM
I planed to make many blocks in a dxf file just like a database until I this topic .
but I have not do well with dynamic block .

from this topic , you give me a other implement.
Block also have load() , not just DxfDocument.

I will also to learn the dynamic block .


Thank you for mkumar123 ,Thank you for Daniel .
Dec 14, 2014 at 12:03 PM
Edited Dec 14, 2014 at 12:03 PM
the orinal dynamic block name that you defined is under the tag "AcDbDynamicBlockTrueName2" .
        public static Block GetDynamicBlockByTrueName(this DxfDocument dxf, string blockName)
        {
            Block rsBlock = null;
            foreach (Block block in dxf.Blocks)
            {
                if (!block.Record.XData.ContainsAppId("AcDbDynamicBlockTrueName2"))
                    continue;
                XData xdata = block.Record.XData["AcDbDynamicBlockTrueName2"];
                foreach (XDataRecord data in xdata.XDataRecord)
                {
                    if (blockName.Equals((string)data.Value))
                        rsBlock = block;
                }
            }       
            return rsBlock;
        }
Coordinator
Dec 15, 2014 at 2:58 PM
Edited Dec 15, 2014 at 2:58 PM
All this stuff about dynamic blocks is undocumented, and what I found looking at dxfs with dynamic blocks is that the AppId "AcDbDynamicBlockTrueName" only appears in the extended data of the original, unmodified, BLOCK_RECORD. The rest of blocks, that were generated based on that one, do not contains that AppId, but the "AcDbBlockRepBTag" with a code 1005 that contains the handle to the original, unmodified block.

Daniel
Dec 16, 2014 at 8:26 AM
Edited Dec 16, 2014 at 8:27 AM
dear Daniel

I can't find "AcDbBlockRepBTag" in dxf files with 2000、2004、 2007、2010. In the TestDxfDocument , I can't find the file "DynamicBlock.dxf" of the DynamicBlocks function. I don't know how "AcDbBlockRepBTag" be created.
public static void DynamicBlocks()
{
    DxfDocument drawing;
    drawing = DxfDocument.Load("..//samples//DynamicBlock.dxf");  
}
Coordinator
Dec 16, 2014 at 5:50 PM
The file "DynamicBlock.dxf" is any file that you can create that contains dynamic blocks. That is a file that I used to test it, but any other should work.

"AcDbBlockRepBTag" is the application registry name that AutoCad uses to register extended data associated with those BLOCK_RECORDs that are the result of modifying dynamic blocks. netDxf do not support dynamic blocks therefore it does not create them.

Remember, when in AutoCad, you modify one of those dynamic parameters of an INSERT entity that references a dynamic block; it, internally, creates another block with those *U# names, so when saving the drawing is necessary a way to know the original block, and this information is stored in extended data.

Daniel