cart: empty [ Login ]

How to override the layer color

1 
Liubomyr Chahoub
3/9/2023 3:37 PM

I am trying to set the color of the entity (WW.Cad.Model.Entities.EntityColor DxfEntity.Color). But when I open the DXF file I see that the objects use the color of the layer (WW.Cad.Model.Color DxfLayer.Color) instead.

C# Code:
var layer = new DxfLayer(layerName) { Color = WW.Cad.Model.Colors.Green }; model.Layers.Add(layer); foreach (DxfEntity entity in entities) { entity.Layer = layer; entity.Color = EntityColors.Blue; model.Entities.Add(entity); }
The version of Cadlib: (6.0.6.0.0-rc26, multiplatform)

Wout
3/9/2023 9:18 PM

Can you post a complete program with input data if present? I can't do anything with this. - Wout

Liubomyr Chahoub
3/10/2023 4:19 PM

I've changed the code. The method Draw() produces a DXF file with a poly face mesh. The mesh object consists of a rectangle face and a triangle face. I open the file using the "DWG TrueView 2023" program. I need this poly face mesh to use the color that I am setting directly to the mesh object (red):

C# Code:
mesh.Color = EntityColors.Red;
. Also, I need that object to use that color in every view ("2D Wireframe", "Conceptual" etc.) I am using here the DxfBlock and DxfInsert because this way the mesh object at least uses the color of the layer (blue), if I do it without them (commented code) The mesh is just white. I need this because I want to have a number of different poly face meshes with different colors within 1 layer and I have some trouble doing it. They all use the color of the layer, no matter what color I am setting directly to the mesh objects.
C# Code:
public static void Draw() { DxfModel model = new DxfModel(); var layer = new DxfLayer("RectLayer") { Color = Colors.Blue }; model.Layers.Add(layer); var mesh = new DxfPolyfaceMesh(); var vertices = new List<DxfVertex3D>() { new DxfVertex3D(0, 0, 0), new DxfVertex3D(0, 1, 0), new DxfVertex3D(1, 1, 0), new DxfVertex3D(1, 0, 0), new DxfVertex3D(2, 0.5, 0), }; foreach (var vertex in vertices) { mesh.Vertices.Add(vertex); } var face1 = new DxfMeshFace(0, 1, 2, 3); var face2 = new DxfMeshFace(2, 3, 4); mesh.Faces.Add(face1); mesh.Faces.Add(face2); //mesh.Layer = layer; //model.Entities.Add(mesh); mesh.Color = EntityColors.Red; var block = new DxfBlock("RectBlock"); block.Entities.Add(mesh); model.Blocks.Add(block); var insert = new DxfInsert() { Layer = layer }; insert.Block = block; model.Entities.Add(insert); DxfWriter.Write("Drawing.dxf", model); }

Screenshot_182.png
Screenshot_183.png
Wout
3/10/2023 4:41 PM

Hi, This is how AutoDesk designed the polyface mesh entity. The polyface mesh has a Color property, but it doesn't seem to be used. This is because each mesh face is by itself an entity (it inherits from DxfEntity), with its own Color property, and this is the property that is used. This property has the bylayer color by default. So if you change each face color to red, it should work as you want it to. Edit 1: I may have spoken too soon, if I change the polyface mesh color in AutoCAD, it does change the whole mesh color, so maybe CadLib does something wrong with writing the face colors. Edit 2: Yes, it does seem my initial analysis is correct. When I change color of the mesh in AutoCAD, it will internally actually change the color of the mesh, and also of all its faces and all its vertices (each vertex is also an entity). - Wout

Liubomyr Chahoub
3/13/2023 10:41 AM

It helped! Thank you very much!

1