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 :: gridview edit update delete in asp.net textbox size 
Csharp :: Wait some seconds without blocking UI execution 
Csharp :: split a datatable based on number of rows 
Csharp :: c# write to registry hkey_current_user 
Csharp :: gridview column cell alignment form c# 
Csharp :: mouse position to canvas transform 
Csharp :: convert web app to linux 
Csharp :: keep sprites at fixed transform according to screen resolution unity 
Csharp :: dotnet core vue in subdirectory 
Csharp :: how to read reportview query string asp.net c# 
Csharp :: wpf c# add style to object 
Csharp :: character stay in ground unity 3d 
Csharp :: start wpf application when windows start 
Csharp :: c# linq foreach example 
Csharp :: datagridview show noti each row column 
Csharp :: c# class responsible for creating instances 
Csharp :: LAST ELEMT OF ARRAY 
Csharp :: how to oppen a site using c# 
Csharp :: .net SaveChanges vs update difference 
Csharp :: Cursor Invisibility 
Csharp :: Runtime.getRuntime().addShutdownHook(printingHook); c# 
Csharp :: c# is not 
Csharp :: report background worker 
Csharp :: c# validate username and password 
Csharp :: c# lernen kostenlos 
Csharp :: translate nicely between two vector3 
Csharp :: c# enum to string 
Csharp :: c# loop back 
Csharp :: c# if int is even 
Csharp :: get selected rows gridcontrol devexpress 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =