This project has moved and is read-only. For the latest updates, please go here.

Model View Only

Aug 8, 2014 at 11:57 AM

If I load my dxf file into a viewer like Teigha Viewer, I get a Model view and the layout view.

Is there a way I can get just the model data form the file and not the layout data?


Aug 8, 2014 at 7:03 PM
If what you need is the full list of entities in ModelSpace you can just use:
List<DxfObject> entities = dxfDocument.Layouts.GetReferences("Model");
The ModelSpace is a reserved layout that is always present in every drawing and it is always called "Model".
DxfDocument dxfLoad = DxfDocument.Load("PaperSpace.dxf");

// For every entity you can check its layout
// The entity Owner will return the block to which it belongs, it can be a *Model_Space, *Paper_Space, ... or a common block if the entity is part of its geometry.
// The block record stores information about the block and one of them is the layout, this mimics the way the dxf stores this information.
// Remember only the internal blocks *Model_Space, *Paper_Space, *Paper_Space0, *Paper_Space1, ... have an associated layout,
// all other blocks will return null is asked for block.Record.Layout
Layout associatedLayout = dxfLoad.Lines[0].Owner.Record.Layout;

// or you can get the complete list of entities of a layout
foreach (Layout layout in dxfLoad.Layouts)
     List<DxfObject> entities = dxfLoad.Layouts.GetReferences(layout.Name); 

// You can also remove any layout from the list, except the "Model".
// Remember all entities that has been added to this layout will also be removed.
// This mimics the behaviour in AutoCad, when a layout is deleted all entities in it will also be deleted.

dxf.Save("PaperSpace removed.dxf");