*Model_Space as block

Mar 18, 2015 at 9:54 PM
Is there a way to manage the model space as a regular block ?

What I would expect is to have something like this

DxfDocument doc;
var m = doc.ModelSpace;

where m is netDxf.Blocks.Block

this should helpful for block based drawing functions where I could use .Entities.Add(x) as for any Block.
For example I can have a function to draw a table, but I would to use that to draw the table in a block, a nested block, or in the model space without have to differentiate at this level the two objects.

The only way I found to manage that is with a function like this:
public static class Toolkit
    {

        public static void AddEntity(DxfObject dxf_obj, EntityObject entity_obj)
        {
            if (dxf_obj is DxfDocument)
                (dxf_obj as DxfDocument).AddEntity(entity_obj);

            else if (dxf_obj is Block)
                (dxf_obj as Block).Entities.Add(entity_obj);

            else throw new ArgumentException("dxf_obj must DxfDocument or Block");
        }

    }
Coordinator
Mar 19, 2015 at 5:08 PM
No. Even if there is a relationship between a layout and its associated block, there is a big conceptual difference between adding an entity to a document and to a block. While entities added to the document have a graphical representation, blocks don't. Blocks requires an Insert entity to actually appear in the drawing. I am not going into details but those *Model_Space, *Paper_Space, *Paper_Space0,... are for internal use only they are not there to be edited directly, they are required for the internal implementation of the dxf format; who knows why, and personally I do not like it. Perhaps I should add limits on how you access them.

The normal workflow is to create the blocks first for any object that needs to be repeated throughout the drawing. Later those blocks are added to the document with an Insert, together with the rest of entities. It is also common to have a bunch of external files as dwgs or dxfs so you can easily share blocks between different drawings. There are two methods in the Block class called Load and Save for this kind of procedure. Those methods only read the entities that belong to the Model layout are used to create the block. I could add a method to create blocks directly from another DxfDocument, it would be exactly as the Load method but without having to load the file first, if that helps you.

Daniel