Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

dxf read c#

    private void ReadDxfFile (string DxfFile)
{
    string Layer = "";

    string[] D = DxfFile.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

    int iEntities = 0; for(int i = 0; i < D.Length; i++) { if (D[i] == "ENTITIES") {iEntities = i; break; } }
    for (int i = iEntities; i < D.Length; i++)
    {
        if (D[i] == "POINT" || D[i] == "AcDbPoint")
        {
            int iEntity = i; if (D[i].StartsWith("AcDb")) { for (iEntity = i; D[iEntity] != "AcDbEntity"; iEntity--) ; }
            Layer = ""; for (int iLayer = iEntity; iLayer < i + 10 && Layer == ""; iLayer++) { if (D[iLayer] == "  8") { Layer = D[iLayer + 1]; }; }
            for (int iWaarden = i; iWaarden < i + 8; iWaarden++)
            {
                if (D[iWaarden] == " 10" && D[iWaarden + 2] == " 20")
                {
                    //Here you can store the following data in a list for later use
                    //LayerName = Layer
                    //X = D[iWaarden + 1]
                    //Y = D[iWaarden + 3]
                    //Z = D[iWaarden + 5]
                }
            }
        }

        if (D[i] == "LINE" || D[i] == "AcDbLine")
        {
            int iEntity = i; if (D[i].StartsWith("AcDb")) { for (iEntity = i; D[iEntity] != "AcDbEntity"; iEntity--) ; }
            Layer = ""; for (int iLayer = iEntity; iLayer < i + 10 && Layer == ""; iLayer++) { if (D[iLayer] == "  8") { Layer = D[iLayer + 1]; }; }
            for (int iWaarden = i; iWaarden < i + 10; iWaarden++)
            {
                if (D[iWaarden] == " 10" && D[iWaarden + 2] == " 20")
                {
                    //Here you can store the following data in a list for later use
                    //LayerName = Layer
                    //Xbegin = D[iWaarden + 1]
                    //Ybegin = D[iWaarden + 3]
                    //Zbegin = D[iWaarden + 5]
                    //Xend = D[iWaarden + 7]
                    //Yend = D[iWaarden + 9]
                    //Zend = D[iWaarden + 11]
                }
            }
        }

        if (D[i] == "ARC" || D[i] == "AcDbArc" || D[i] == "AcDbCircle")
        {
            int iEntity = i; if (D[i].StartsWith("AcDb")) { for (iEntity = i; D[iEntity] != "AcDbEntity"; iEntity--) ; }
            Layer = ""; for (int iLayer = iEntity; iLayer < i + 10 && Layer == ""; iLayer++) { if (D[iLayer] == "  8") { Layer = D[iLayer + 1]; }; }
            for (int iWaarden = i; iWaarden < i + 10; iWaarden++)
            {
                if (D[iWaarden] == " 10" && D[iWaarden + 2] == " 20" && D[iWaarden + 10] == " 51")
                {
                    //Here you can store the following data in a list for later use
                    //LayerName = Layer
                    //Xmid = D[iWaarden + 1]
                    //Ymid = D[iWaarden + 3]
                    //Zmid = D[iWaarden + 5]
                    //Radius = D[iWaarden + 7]
                    //StartAngle = D[iWaarden + 9]
                    //StartAngle = D[iWaarden + 11]
                }
                if (D[iWaarden] == " 10" && D[iWaarden + 2] == " 20" && D[iWaarden + 12] == " 51")
                {
                    //Here you can store the following data in a list for later use
                    //LayerName = Layer
                    //Xmid = D[iWaarden + 1]
                    //Ymid = D[iWaarden + 3]
                    //Zmid = D[iWaarden + 5]
                    //Radius = D[iWaarden + 7]
                    //StartAngle = D[iWaarden + 11]
                    //StartAngle = D[iWaarden + 13]
                }
            }
        }

    }
}
Comment

read dxf file c#

//format autocad 2018
private void ReadDxfFile(string DxfFile)
        {
            DxfFile = System.IO.File.ReadAllText(DxfFile);
            string Layer = "";
            //because I'm italian
            DxfFile = DxfFile.Replace(".", ",");

            string[] D = DxfFile.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            int iEntities = 0;// for (int i = 0; i < D.Length; i++) { if (D[i] == "ENTITIES") { iEntities = i; break; } }
            for (int i = iEntities; i < D.Length; i++)
            {
                if (D[i] == "POINT" || D[i] == "AcDbPoint")
                {
                    int iEntity = i; if (D[i].StartsWith("AcDb")) { for (iEntity = i; D[iEntity] != "AcDbEntity"; iEntity--) ; }
                    Layer = ""; for (int iLayer = iEntity; iLayer < i + 10 && Layer == ""; iLayer++) { if (D[iLayer] == "  8") { Layer = D[iLayer + 1]; }; }
                    for (int iWaarden = i; iWaarden < i + 8; iWaarden++)
                    {
                        if (D[iWaarden] == " 10" && D[iWaarden + 2] == " 20")
                        {
                            //Here you can store the following data in a list for later use
                            //LayerName = Layer
                            string X = D[iWaarden + 1];
                            string Y = D[iWaarden + 3];
                            string Z = D[iWaarden + 5];
                        }
                    }
                }

                if (D[i] == "LINE" || D[i] == "AcDbLine")
                {
                    int iEntity = i; if (D[i].StartsWith("AcDb")) { for (iEntity = i; D[iEntity] != "AcDbEntity"; iEntity--) ; }
                    Layer = ""; for (int iLayer = iEntity; iLayer < i + 10 && Layer == ""; iLayer++) { if (D[iLayer] == "  8") { Layer = D[iLayer + 1]; }; }
                    for (int iWaarden = i; iWaarden < i + 10; iWaarden++)
                    {
                        if (D[iWaarden] == " 10" && D[iWaarden + 2] == " 20")
                        {
                            //Here you can store the following data in a list for later use
                            //LayerName = Layer
                            lines.Add(new List<double>());


                            lines[lines.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 1])); //Xbegin
                            lines[lines.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 3])); //Ybegin
                            lines[lines.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 5])); //Zbegin

                            lines[lines.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 7])); //Xend
                            lines[lines.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 9])); //Yend
                            lines[lines.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 11])); //Zend
                        }
                    }
                }

                if (D[i] == "CIRCLE" || D[i] == "AcDbCircle")
                {
                    int iEntity = i; if (D[i].StartsWith("AcDb")) { for (iEntity = i; D[iEntity] != "AcDbEntity"; iEntity--) ; }
                    Layer = ""; for (int iLayer = iEntity; iLayer < i + 10 && Layer == ""; iLayer++) { if (D[iLayer] == "  8") { Layer = D[iLayer + 1]; }; }
                    for (int iWaarden = i; iWaarden < i + 10; iWaarden++)
                    {
                        if (D[iWaarden] == " 10" && D[iWaarden + 2] == " 20")
                        {

                            //Here you can store the following data in a list for later use
                            //LayerName = Layer
                            arcs.Add(new List<double>());
                            arcs[arcs.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 1])); //Xmid
                            arcs[arcs.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 3])); //Ymid
                            arcs[arcs.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 5])); //Zmid

                            arcs[arcs.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 7])); //Radious
                            //Check if this is an arc
                            if (D[iWaarden + 8] == "100")
                            {
                                arcs[arcs.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 11])); //StartAngle
                                arcs[arcs.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 13])); //EndAngle
                            }
                            else
                            {
                                arcs[arcs.Count() - 1].Add(0); //StartAngle
                                arcs[arcs.Count() - 1].Add(360); //EndAngle
                            }
                        }
                    }
                }
            }

        }
Comment

PREVIOUS NEXT
Code Example
Csharp :: join dictionaries keys c# 
Csharp :: how to use buildcontext in initstate flutter 
Csharp :: onmousedown not working unity 
Csharp :: vb.net datagridview set row index 
Csharp :: edit list element linq c# 
Csharp :: c# ? 
Csharp :: string interpolation in c# 
Csharp :: how to sign in with your unity id in unity hub 
Csharp :: c# xmldocument from file 
Csharp :: c# to pascal case 
Csharp :: Remove access to admin from deleting the file in C# 
Csharp :: unity scene switch 
Csharp :: asp.net get most recent file in directory 
Csharp :: unique field in class model .net core 
Csharp :: asp c# page scroll position change after postback 
Csharp :: unity draw waypoints path 
Csharp :: convert getdate to ist c# 
Csharp :: unity basic public options 
Csharp :: c# selenium xunit testing 
Csharp :: How to jump in Unity using physics 3D 
Csharp :: c# .net core entity framework one to many 
Csharp :: unity array c# 
Csharp :: unity sprite disappears when using transform.lookat 
Csharp :: unity vector3 initialization 
Csharp :: How to create a new object instance from a Type 
Csharp :: c# list contains null 
Csharp :: run in wpf 
Csharp :: summernote dropdown plugin 
Csharp :: c# new object 
Csharp :: c# console.writeline 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =