Block layer not set

Jul 29, 2016 at 11:56 AM
Edited Jul 29, 2016 at 11:59 AM
Hi there,

I am trying to merge the content of multiple DXF files into one. I have managed to extract the data from the different DXF files and insert it in a new document using the following code:
DxfDocument doc = new DxfDocument();
netDxf.Blocks.Block TestBlock;
TestBlock = netDxf.Blocks.Block.Load("loadfile.dxf");
netDxf.Vector2 GlobalPosition = new netDxf.Vector2(0, 0);
var InsertBlock = new netDxf.Entities.Insert(TestBlock, GlobalPosition);
InsertBlock.Rotation = 0;
The problem I have is that the content in the new DXF is always created on layer 0 and hidden in all programs I try to open it with (CAD, Acrobat, Illustrator) unless I manually change the layer. I tried creating a new layer and setting the blocks and inserts to this layer but this has no effect:
var layer = new netDxf.Tables.Layer("1");
layer.IsVisible = true;
layer.IsFrozen = false;
layer.IsLocked = false;
var myColor = new netDxf.AciColor(0, 0, 0);
layer.Color = myColor;

TestBlock.Layer = layer;
InsertBlock.Layer = layer
Any suggestions on how to solve this issue?
Aug 9, 2016 at 9:45 AM
Under normal circumstances always leave the block and its entities in the default layer "0", and only change the Insert layer. So, it is normal that the entities in the file your are loading are at layer "0", what you should do is just create an Insert with that block and change the its layer to the one you like.

Another detail, about the layer color, just in case, your black rgb AciColor might not be visible if you have a dark background. Usually for white and black is better to use the AciColor index 7 (AciColor.Default), it will change accordingly depending on the background.

Aug 22, 2016 at 1:24 PM
Hi Daniel,

Thank you for your response. I tried only setting the Insert layer, however this is still resulting in the block being inserted at layer 0 (which equals hidden in my CAD program and Acrobat). Perhaps I need to set all entities to layer 1 when loading the external file as a block? Or should I do something with the Model/Paper Space layouts? If so, how do I manage to do this?

Thanks in advance.

Aug 24, 2016 at 4:03 PM
You can try to change the layer of the entities in the block and see what happens. Not all programs read the dxf files in the same way, some of them might not read all entities available or interpret the data in some weird way. What I can explain you is how AutoCad reads the dxf files.
About the Model/Paper Space, under normal circumstances you will work in Model Space and if you do not specifically change anything that is the default mode. The Paper Space is really to prepare the plans for printing.