Dear Aspose Support,
I’m trying to create a DWG file from scratch using DwgImage
in C# (.NET), and I would like to add layers and assign entities to specific layers. Unfortunately, this doesn’t seem to work as expected.
Below is a simplified example of what I’m doing:
DwgImage dwgImage = new DwgImage();
var linesLayer = new CadLayerTable { Name = "LinesLayer" };
dwgImage.Layers.Add(linesLayer);
var pointsLayer = new CadLayerTable { Name = "PointsLayer" };
dwgImage.Layers.Add(pointsLayer);
//add line
CadLine line = new CadLine(new Cad3DPoint(0, 0, 0), new Cad3DPoint(100, 100, 100));
line.LayerName = "LinesLayer";
dwgImage.AddEntity(line);
CadPoint point = new CadPoint();
point.CenterPoint = new Cad3DPoint(-10, -10, -10);
point.LayerName = "PointsLayer";
dwgImage.AddEntity(point);
var cadPoints = new List<Cad2DPoint>();
var point1 = new Cad2DPoint(-5, -5);
var point2 = new Cad2DPoint(-5, 10);
var point3 = new Cad2DPoint(20, 10);
var point4 = new Cad2DPoint(20, -5);
cadPoints.Add(point1);
cadPoints.Add(point2);
cadPoints.Add(point3);
cadPoints.Add(point4);
var cadPolyline = new CadLwPolyline
{
Coordinates = cadPoints,
Flag = CadLwPolylineFlag.Closed,
ConstantWidth = 0.1,
PointCount = cadPoints.Count,
LayerName = "LinesLayer"
};
dwgImage.AddEntity(cadPolyline);
CadLine lineColor = new CadLine(new Cad3DPoint(0, 0, 0), new Cad3DPoint(-100, 100, 0));
lineColor.LayerName = "LinesLayer";
dwgImage.AddEntity(lineColor);
lineColor.ColorId = 15; //ACI color id
dwgImage.Save("fileResult.dwg");
Problem:
- The file is saved, but the added layers are not visible in AutoCAD or other DWG viewers.
- When I set
LayerName = "..."
, the entities do not appear and no custom layers show up. - If I remove
LayerName
, the entities are displayed, but always on the default"0"
layer.
Context:
- I’m using the latest version of Aspose.CAD via NuGet.
- My free trial license has expired – could that affect visibility of layers or entities?
- I couldn’t find clear documentation or working examples on how to properly add layers to a new
DwgImage
.
My questions:
- Is it officially supported to add new layers to a
DwgImage
? - Do you have a simple working example of:
- a DWG file with one custom layer (e.g.,
"MyLayer"
) - one entity (e.g., a line) assigned to that layer
- Where can I find up-to-date documentation for working with
CadLayer
andDwgImage
? - Does an expired evaluation license hide or suppress custom layers/entities in any way?
Thank you in advance for your time and support — I’m working on a project to generate DWG files from XML and would like to use Aspose.CAD for this.
Best regards,
Abne