DWG to SVG: Extra lines appearing in picture

I’m use our component Aspose.Cad(Net) for read .dwg file.
At some time i ran into the problem. I see extra lines in BlockEntities
(Aspose.CAD.FileFormats.Cad.CadConsts.CadEntityTypeName.POLYLINE).
I don’t see them in AutoCad, in Ares Comander also. But I see them in your Aspos Cad Viewer.
I do not find a creterion by which Ican divide the lines that I see in Autocad or some do not see. I suppose these are construction lines when drawing blocks. Please help me.
Thank to advance.

@IrinaAvrutin

In order to investigate the issue further on my end, I request you to please provide the working sample code, source file and generated output along with comparison output with us.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspose;
using ConsoleAppTest.Models;
using System.Collections;
using System.IO;

namespace ConsoleAppTest
{
public class AsposeParse
{

    private static string filepath = @"C:\Temp\DWG\AnitaForAspose.dwg";

    static void Main()
    {
        Run();

        Console.Read();
    }


    public static void Run()
    {
        using (FileStream filedwg = File.OpenRead(filepath))
        {
            // Load an existing DWG file and convert it into CadImage 
            using (Aspose.CAD.FileFormats.Cad.CadImage image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.FileFormats.Cad.CadImage.Load(filedwg))
            {
                List<string> svgList = new List<string>();
                List<Block> Blocks = new List<Block>();

                Block blo;
                Aspose.CAD.FileFormats.Cad.CadBlockDictionary cadBloks = image.BlockEntities;
                foreach (System.Collections.DictionaryEntry bl in cadBloks)
                {
                    try
                    {
                        blo = new Block()
                        {
                            Name = bl.Key.ToString(),
                            Type = 0,
                            SubType = 0,
                            svgFileName = bl.Key.ToString().Replace('*', '-') + ".svg",
                            svg = ParseBlockImageToSvg((Aspose.CAD.FileFormats.Cad.CadObjects.CadBaseEntity[])((Aspose.CAD.FileFormats.Cad.CadObjects.CadBlockEntity)bl.Value).Entities)

                        };

                        if (blo.svg.Length > 10)
                            CreateFileSvg(blo.svgFileName, blo.svg);

                        Blocks.Add(blo);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Block" + bl.Key.ToString() + " -- " + ex.Message);
                    }

                }

                string end = "success";
            }
        }
    }


    private static string ParseBlockImageToSvg(Aspose.CAD.FileFormats.Cad.CadObjects.CadBaseEntity[] Blocks)
    {
        if (Blocks.Count() == 0) return "";

        double minX = 0;
        double minY = 0;
        double maxX = 0;
        double maxY = 0;
        double deltaX = 0.25;
        double deltaY = 0.25;
        double deltaW = 0.25;
        double deltaH = 0.25;
        string svg = "";

        //TEXT
        var labels = from b in Blocks
                     where b.TypeName.Equals(Aspose.CAD.FileFormats.Cad.CadConsts.CadEntityTypeName.TEXT)
                     select b;//Texts;
        if (labels.Count() > 0)

            foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadText lb in labels)
            {

                svg = svg + "<text ";

                svg = svg + " x='" + Math.Round(lb.FirstAlignment.X, 2).ToString() + "' y='"
                                    + "-" + Math.Round(lb.FirstAlignment.Y, 2).ToString() + "' style='"
                                    + "font:" + lb.TextHeight.ToString() + "px ariel; fill:black;"
                                    + "'>" + lb.DefaultValue + "</text>";
            }


        //SOLID
        var solids = from b in Blocks
                     where b.TypeName.Equals(Aspose.CAD.FileFormats.Cad.CadConsts.CadEntityTypeName.SOLID)
                     select b;//Solids;


        foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadSolid sl in solids)
        {
            svg = svg + "<polygon points = '";

            svg = svg + sl.FirstCorner.X.ToString() + " " + ((-1) * sl.FirstCorner.Y).ToString() + " "
                + sl.SecondCorner.X.ToString() + " " + ((-1) * sl.SecondCorner.Y).ToString() + " "
                + sl.FourthCorner.X.ToString() + " " + ((-1) * sl.FourthCorner.Y).ToString() + " "
                + sl.ThirdCorner.X.ToString() + " " + ((-1) * sl.ThirdCorner.Y).ToString() + "'";

            if (minX > sl.FirstCorner.X) { minX = sl.FirstCorner.X; deltaX = sl.LineWeight; }
            if (minY > sl.FirstCorner.Y) { minY = sl.FirstCorner.Y; deltaH = sl.LineWeight; }
            if (maxX < sl.FirstCorner.X) { maxX = sl.FirstCorner.X; deltaW = sl.LineWeight; }
            if (maxY < sl.FirstCorner.Y) { maxY = sl.FirstCorner.Y; deltaY = sl.LineWeight; }

            if (minX > sl.SecondCorner.X) { minX = sl.SecondCorner.X; deltaX = sl.LineWeight; }
            if (minY > sl.SecondCorner.Y) { minY = sl.SecondCorner.Y; deltaH = sl.LineWeight; }
            if (maxX < sl.SecondCorner.X) { maxX = sl.SecondCorner.X; deltaW = sl.LineWeight; }
            if (maxY < sl.SecondCorner.Y) { maxY = sl.SecondCorner.Y; deltaY = sl.LineWeight; }

            if (minX > sl.ThirdCorner.X) { minX = sl.ThirdCorner.X; deltaX = sl.LineWeight; }
            if (minY > sl.ThirdCorner.Y) { minY = sl.ThirdCorner.Y; deltaH = sl.LineWeight; }
            if (maxX < sl.ThirdCorner.X) { maxX = sl.ThirdCorner.X; deltaW = sl.LineWeight; }
            if (maxY < sl.ThirdCorner.Y) { maxY = sl.ThirdCorner.Y; deltaY = sl.LineWeight; }

            if (minX > sl.FourthCorner.X) { minX = sl.FourthCorner.X; deltaX = sl.LineWeight; }
            if (minY > sl.FourthCorner.Y) { minY = sl.FourthCorner.Y; deltaH = sl.LineWeight; }
            if (maxX < sl.FourthCorner.X) { maxX = sl.FourthCorner.X; deltaW = sl.LineWeight; }
            if (maxY < sl.FourthCorner.Y) { maxY = sl.FourthCorner.Y; deltaY = sl.LineWeight; }
            svg = svg + " stroke = 'black' fill = 'black' stroke-width ='" + sl.LineWeight.ToString() + "'/>";
        }

        //POLYLINES
        var polyLines = from b in Blocks
                        where b.TypeName.Equals(Aspose.CAD.FileFormats.Cad.CadConsts.CadEntityTypeName.POLYLINE)
                        select b;

        foreach (Aspose.CAD.FileFormats.Cad.CadObjects.Polylines.CadPolyline pl in polyLines)
        {
            var vr = from v in pl.ChildObjects
                     where v.TypeName.Equals(Aspose.CAD.FileFormats.Cad.CadConsts.CadEntityTypeName.VERTEX)
                     select v;

            svg = svg + "<polyline points = '";

            foreach (Aspose.CAD.FileFormats.Cad.CadObjects.Vertices.Cad2DVertex v in vr)
            {
                svg = svg + v.LocationPoint.X.ToString() + " " + ((-1) * v.LocationPoint.Y).ToString() + " ";

                if (minX > v.LocationPoint.X) { minX = v.LocationPoint.X; deltaX = pl.StartWidth; }
                if (minY > v.LocationPoint.Y) { minY = v.LocationPoint.Y; deltaH = pl.StartWidth; }
                if (maxX < v.LocationPoint.X) { maxX = v.LocationPoint.X; deltaW = pl.StartWidth; }
                if (maxY < v.LocationPoint.Y) { maxY = v.LocationPoint.Y; deltaY = pl.StartWidth; }
            }
            svg = svg + "' stroke = 'black' fill = 'none' stroke-width ='" + pl.StartWidth + "' />";

        }

        double w = maxX - minX + deltaX / 2 + deltaH / 2;
        double h = maxY - minY + deltaY / 2 + deltaW / 2;

        minX = minX - deltaX / 2;
        maxY = maxY + deltaY / 2;

        svg = "<?xml version='1.0' standalone='no'?><svg width = '" + w + "' height = '" + h +
            "' viewBox='" + minX + " " + ((-1) * (maxY)).ToString() + " " + w + " " + h + "' version = '1.1' xmlns = 'http://www.w3.org/2000/svg'>" + svg + "</svg>";

        return svg;
    }


    private static void CreateFileSvg(string fileName, string svgString)
    {

        string folderName = @"C:\Temp\SVG\";

        try
        {
            // Check if file already exists. If yes, delete it.     
            if (File.Exists(folderName + fileName))
            {
                File.Delete(folderName + fileName);
            }

            // Create a new file     
            using (FileStream fs = File.Create(folderName + fileName))
            {
                // Add some text to file    
                Byte[] title = new UTF8Encoding(true).GetBytes(svgString);
                fs.Write(title, 0, title.Length);

            }


        }
        catch (Exception Ex)
        {
            Console.WriteLine(Ex.ToString());
        }
    }


   
}



public class Line
{

    public Point FirstPoint { get; set; }
    public Point SecondPoint { get; set; }
    public string LayerName { get; set; }

    public Double Length;
    public Line()
    {
        FirstPoint = new Point();
        SecondPoint = new Point();
    }

}

public class PolyLine
{
    public List<Point> Points { get; set; }
    public string LayerName { get; set; }

    public Double Length;
    public PolyLine()
    {
        Points = new List<Point>();
    }

}


public class CadSpline
{
    public List<Point> Points { get; set; }
    public string LayerName { get; set; }

    public Double Length;
    //ublic double Rotation { get; set; }
    public CadSpline()
    {
        Points = new List<Point>();
    }


}


public class CadElement
{

    public string Name { get; set; }

    public string ObjectHandle { get; set; }

    public double Rotation { get; set; }


    public Point InsertionPoint;

    public Scale Scale { get; set; }

    public List<BlockAttributes> Attributes;

    public string LayerName { get; set; }

    public CadElement()
    {
        Attributes = new List<BlockAttributes>();
        InsertionPoint = new Point();
    }

}
public class Point
{
    public double X { get; set; }
    public double Y { get; set; }
    public double Z { get; set; }
}

public class Scale
{
    public double X { get; set; }
    public double Y { get; set; }
    public double Z { get; set; }

}

public class BlockAttributes
{
    public string DefinitionTagString { get; set; }
    public string DefaultText { get; set; }
    public string TypeName { get; set; }

}

public class Block
{

    public int Id { get; set; }

    public string Name { get; set; }

    public string Width { get; set; }

    public double Height { get; set; }

    public Point InsertionPoint;

    public int Type { get; set; }

    public int SubType { get; set; }

    public List<BlockAttributes> Attributes;

    public string LayerName { get; set; }

    public string svg { get; set; }

    public string svgFileName { get; set; }

    public Block()
    {
        Attributes = new List<BlockAttributes>();
        InsertionPoint = new Point();
    }


}

}

view Block.PNG (23.4 KB)

My program parse @“C:\Temp\DWG\AnitaForAspose.dwg” file with yAnitaForAspose.zip (146.7 KB)
our component Aspose Cad.
And Create .svg files from all blocks into Folder “C://Temp/SVG”
All blocks ok, only PCS66-0_STATE2.svg have extra lines.
I don’t see this extra lines in Autocad and in AresCommander , But I see them in Aspose Online Viewer.

@IrinaAvrutin

Can you please share the generated SVG with us. Please also share that which API version you have used on your end. If you have used any older version then please try using latest version of API on your end as well.

ezyzip.zip (29.0 KB)

@IrinaAvrutin

I have observed the issue and have created an issue with ID CADNET-8211 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Thanks in advance!

where I can see this issues list with ID CADNET-8211?
Send me link please

@IrinaAvrutin

At present the issue is still unresolved. We request for your patience and will share good news with you as soon as the issue will be fixed.