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

Block layer not set

Jul 29, 2016 at 12:56 PM
Edited Jul 29, 2016 at 12:59 PM
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");
doc.Blocks.Add(TestBlock);
netDxf.Vector2 GlobalPosition = new netDxf.Vector2(0, 0);
var InsertBlock = new netDxf.Entities.Insert(TestBlock, GlobalPosition);
InsertBlock.Rotation = 0;
doc.AddEntity(InsertBlock);
doc.Save("savefile.dxf");
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");
doc.Layers.Add(layer);
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?
Coordinator
Aug 9, 2016 at 10: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.

Daniel
Aug 22, 2016 at 2: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.

Tom
Coordinator
Aug 24, 2016 at 5: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.

Daniel