【问题标题】:How to extract all coordinates from a dxf file如何从dxf文件中提取所有坐标
【发布时间】:2020-11-26 20:16:39
【问题描述】:

我有一个 dxf 文件 https://filebin.net/7l8izrv2js7doicc/5holes-8x8.dxf?t=9ro7k928(下载和扩展名为 .dxf) 我能够解析它的线条和所有但我现在想提取所有坐标。 目的是,如果我获得所有坐标,则 Id 能够为所有这些坐标创建一个边界框。 由于绘图有曲线和线条,我不知道如何为曲线等做。

===我的部分代码来显示线条和拉出线条的起点和终点====

flist=open("test2.dxf")

#fil.readlines()
# entityflist = open("filename.txt").readlines()
lst=[]

parsing = False
for line in flist:
    #print ("==================")
    if line.startswith("ENDSEC"):
        parsing = False
    if parsing:
        #print (line)
        lst.append(line)
        #Do stuff with data 
    if line.startswith("LINE"):
        parsing = True
        #print ("LINE")

# lines coordinates list
ts=(''.join(lst).split('LINE'))

#print out all the point coordinates of lines start & end
# i.e. 2 coordinate pairs for each line
for i in ts:
    print ((i.split()[19],i.split()[21]))
    print ((i.split()[15],i.split()[17]))

【问题讨论】:

标签: python algorithm geometry autocad


【解决方案1】:

第二部分

        public class Table : Section
        {
            public List<VPort> vPorts;
            VPort currentVPort = null;
            GROUP_CODE currentGroupCode { get; set; }
            string vPortName { get; set; }
            READ_STATE readState = READ_STATE.GET_OBJECT_TYPE;

            public Result TableParse(string line)
            {

                Result result = new Result() { status = "OK" };
                switch (readState)
                {
                    case READ_STATE.GET_OBJECT_TYPE :
                        currentGroupCode = (GROUP_CODE)Enum.Parse(typeof(GROUP_CODE), line);
                        readState = READ_STATE.GET_OBJECT;
                        break;
                    case READ_STATE.GET_OBJECT :
                        readState = READ_STATE.GET_GROUP_CODE;
                        break;
                    case READ_STATE.GET_GROUP_CODE:
                        currentGroupCode = (GROUP_CODE)Enum.Parse(typeof(GROUP_CODE), line);
                        readState = READ_STATE.GET_VARIABLE_NAME;
                        break;
                    case READ_STATE.GET_VARIABLE_NAME:
                        if (line == "ENDSEC")
                        {
                            result.status = line;
                        }
                        else
                        {
                            if (currentVPort == null) currentVPort = new VPort();
                            currentVPort.tableName = line;
                            readState = READ_STATE.GET_VARIABLE_TYPE;
                        }
                        break;
                    case READ_STATE.GET_VARIABLE_TYPE:
                        currentGroupCode = (GROUP_CODE)Enum.Parse(typeof(GROUP_CODE), line);
                        switch (currentGroupCode)
                        {
                            case GROUP_CODE.ENTITY_TYPE:
                                readState = READ_STATE.GET_VARIABLE_NAME;
                                break;
                            default:
                                readState = READ_STATE.GET_VARIABLE_VALUES;
                                break;
                        }
                        break;
                    case READ_STATE.GET_VARIABLE_VALUES:
                        switch (currentGroupCode)
                        {
                            case GROUP_CODE.ANGLE:
                                currentVPort.angle = double.Parse(line);
                                break;
                            case GROUP_CODE.ANGLE_1:
                                currentVPort.angle1 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION:
                                currentVPort.doublePrecission = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_1:
                                currentVPort.doublePrecission1 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_2:
                                currentVPort.doublePrecission2 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_3:
                                currentVPort.doublePrecission3 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_4:
                                currentVPort.doublePrecission4 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_POINT:
                                currentVPort.doublePrecissionPoint = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_POINT_1:
                                currentVPort.doublePrecissionPoint1 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_POINT_2:
                                currentVPort.doublePrecissionPoint2 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_POINT_3:
                                currentVPort.doublePrecissionPoint3 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_POINT_4:
                                currentVPort.doublePrecissionPoint4 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_POINT_5:
                                currentVPort.doublePrecissionPoint5 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_POINT_6:
                                currentVPort.doublePrecissionPoint6 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_POINT_7:
                                currentVPort.doublePrecissionPoint7 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_POINT_8:
                                currentVPort.doublePrecissionPoint8 = double.Parse(line);
                                break;
                            case GROUP_CODE.DOUBLE_PRECISION_POINT_9:
                                currentVPort.doublePrecissionPoint9 = double.Parse(line);
                                break;
                            case GROUP_CODE.ENTITY_HANDLE:
                                currentVPort.handle = int.Parse(line);
                                break;
                            case GROUP_CODE.INT_VALUE:
                                currentVPort.maxEntries = int.Parse(line);
                                break;
                            case GROUP_CODE.INT_VALUE_1 :
                                currentVPort.integer_1 = int.Parse(line);
                                break;
                            case GROUP_CODE.INT_VALUE_2:
                                currentVPort.integer_2 = int.Parse(line);
                                break;
                            case GROUP_CODE.INT_VALUE_3:
                                currentVPort.integer_3 = int.Parse(line);
                                break;
                            case GROUP_CODE.INT_VALUE_4:
                                currentVPort.integer_4 = int.Parse(line);
                                break;
                            case GROUP_CODE.INT_VALUE_5:
                                currentVPort.integer_5 = int.Parse(line);
                                break;
                            case GROUP_CODE.INT_VALUE_6:
                                currentVPort.integer_6 = int.Parse(line);
                                break;
                            case GROUP_CODE.INT_VALUE_7:
                                currentVPort.integer_7 = int.Parse(line);
                                break;
                            case GROUP_CODE.INT_VALUE_8:
                                currentVPort.integer_8 = int.Parse(line);
                                break;
                            case GROUP_CODE.INT_VALUE_9:
                                currentVPort.integer_9 = int.Parse(line);
                                break;
                            case GROUP_CODE.INT_16_1:
                                currentVPort.int16_1= int.Parse(line);
                                break;

                            case GROUP_CODE.NAME:
                                currentVPort.tableName = line;
                                break;
                            case GROUP_CODE.SOFT_POINTER_HANDLE:
                                currentVPort.softPointerHandle = int.Parse(line);
                                break;
                            case GROUP_CODE.SUBCLASS_MARKER:
                                if (currentVPort.subclassMarkers == null) currentVPort.subclassMarkers = new List<string>();
                                currentVPort.subclassMarkers.Add(line);
                                break;
                            case GROUP_CODE.PRIMARY_POINT:
                                currentVPort.primaryPoint = double.Parse(line);
                                break;
                            case GROUP_CODE.PRIMARY_POINT_CORNER:
                                currentVPort.primaryPointCorner = double.Parse(line);
                                break;
                            case GROUP_CODE.PRIMARY_POINT_2:
                                currentVPort.primaryPoint2 = double.Parse(line);
                                break;
                            case GROUP_CODE.PRIMARY_POINT_3:
                                currentVPort.primaryPoint3 = double.Parse(line);
                                break;
                            case GROUP_CODE.PRIMARY_POINT_4:
                                currentVPort.primaryPoint4 = double.Parse(line);
                                break;
                            case GROUP_CODE.PRIMARY_POINT_5:
                                currentVPort.primaryPoint5 = double.Parse(line);
                                break;
                            case GROUP_CODE.PRIMARY_POINT_6:
                                currentVPort.primaryPoint6 = double.Parse(line);
                                break;
                            case GROUP_CODE.PRIMARY_POINT_7:
                                currentVPort.primaryPoint7 = double.Parse(line);
                                break;
                            case GROUP_CODE.PRIMARY_POINT_8:
                                currentVPort.primaryPoint8 = double.Parse(line);
                                break;
                            case GROUP_CODE.PRIMARY_POINT_9:
                                currentVPort.primaryPoint9 = double.Parse(line);
                                break;
                            case GROUP_CODE.UCF_X:
                                currentVPort.ucf_x = double.Parse(line);
                                break;
                            case GROUP_CODE.UCF_X1:
                                currentVPort.ucf_x1 = double.Parse(line);
                                break;
                            case GROUP_CODE.UCF_X2:
                                currentVPort.ucf_x2 = double.Parse(line);
                                break;
                            case GROUP_CODE.UCF_Y:
                                currentVPort.ucf_y = double.Parse(line);
                                break;
                            case GROUP_CODE.UCF_Y1:
                                currentVPort.ucf_y1 = double.Parse(line);
                                break;
                            case GROUP_CODE.UCF_Y2:
                                currentVPort.ucf_y2 = double.Parse(line);
                                break;
                            case GROUP_CODE.UCF_Z:
                                currentVPort.ucf_z = double.Parse(line);
                                break;
                            case GROUP_CODE.UCF_Z1:
                                currentVPort.ucf_z1 = double.Parse(line);
                                break;
                            case GROUP_CODE.UCF_Z2:
                                currentVPort.ucf_z2 = double.Parse(line);
                                break;
                            case GROUP_CODE.Y_VALUE:
                                currentVPort.y = double.Parse(line);
                                break;
                            case GROUP_CODE.Y_VALUE_CORNER:
                                currentVPort.yCorner = double.Parse(line);
                                break;
                            case GROUP_CODE.Y_VALUE_2:
                                currentVPort.y2 = double.Parse(line);
                                break;
                            case GROUP_CODE.Y_VALUE_3:
                                currentVPort.y3= double.Parse(line);
                                break;
                            case GROUP_CODE.Y_VALUE_4:
                                currentVPort.y4 = double.Parse(line);
                                break;
                            case GROUP_CODE.Y_VALUE_5:
                                currentVPort.y5 = double.Parse(line);
                                break;
                            case GROUP_CODE.Y_VALUE_6:
                                currentVPort.y6 = double.Parse(line);
                                break;
                            case GROUP_CODE.Y_VALUE_7:
                                currentVPort.y7 = double.Parse(line);
                                break;
                            case GROUP_CODE.Y_VALUE_8:
                                currentVPort.y8 = double.Parse(line);
                                break;
                            case GROUP_CODE.Y_VALUE_9:
                                currentVPort.y9 = double.Parse(line);
                                break;
                            case GROUP_CODE.Z_VALUE:
                                currentVPort.z = double.Parse(line);
                                break;
                            case GROUP_CODE.Z_VALUE_CORNER:
                                currentVPort.zCorner = double.Parse(line);
                                break;
                            case GROUP_CODE.Z_VALUE_2:
                                currentVPort.z2 = double.Parse(line);
                                break;
                            case GROUP_CODE.Z_VALUE_3:
                                currentVPort.z3 = double.Parse(line);
                                break;
                            case GROUP_CODE.Z_VALUE_4:
                                currentVPort.z4 = double.Parse(line);
                                break;
                            case GROUP_CODE.Z_VALUE_5:
                                currentVPort.z5 = double.Parse(line);
                                break;
                            case GROUP_CODE.Z_VALUE_6:
                                currentVPort.z6 = double.Parse(line);
                                break;
                            case GROUP_CODE.Z_VALUE_7:
                                currentVPort.z7 = double.Parse(line);
                                break;
                            case GROUP_CODE.Z_VALUE_8:
                                currentVPort.z8 = double.Parse(line);
                                break;
                            case GROUP_CODE.Z_VALUE_9:
                                currentVPort.z9 = double.Parse(line);
                                break;
                            default:
                                break;
                        }
                        readState = READ_STATE.GET_VARIABLE_TYPE;
                        break;

                }

                return result;
            }
        }
        public class VPort
        {
            public string dxfName { get; set; }
            public string tableName { get; set; }
            public int handle { get; set; }
            public int softPointerHandle { get; set; }
            public List<string>subclassMarkers { get; set; }
            public int maxEntries { get; set; }

            public double doublePrecission { get; set; }
            public double doublePrecission1 { get; set; }
            public double doublePrecission2 { get; set; }
            public double doublePrecission3 { get; set; }
            public double doublePrecission4 { get; set; }

            public double doublePrecissionPoint { get; set; }
            public double doublePrecissionPoint1 { get; set; }
            public double doublePrecissionPoint2 { get; set; }
            public double doublePrecissionPoint3 { get; set; }
            public double doublePrecissionPoint4 { get; set; }
            public double doublePrecissionPoint5 { get; set; }
            public double doublePrecissionPoint6 { get; set; }
            public double doublePrecissionPoint7 { get; set; }
            public double doublePrecissionPoint8 { get; set; }
            public double doublePrecissionPoint9 { get; set; }

            public int integer_1 { get; set; }
            public int integer_2 { get; set; }
            public int integer_3 { get; set; }
            public int integer_4 { get; set; }
            public int integer_5 { get; set; }
            public int integer_6 { get; set; }
            public int integer_7 { get; set; }
            public int integer_8 { get; set; }
            public int integer_9 { get; set; }

            public int int16_1 { get; set; }
     

            public double angle { get; set; }
            public double angle1 { get; set; }

            public double primaryPoint { get; set; }
            public double primaryPoint1 { get; set; }
            public double primaryPoint2 { get; set; }
            public double primaryPoint3 { get; set; }
            public double primaryPoint4 { get; set; }
            public double primaryPoint5 { get; set; }
            public double primaryPoint6 { get; set; }
            public double primaryPoint7 { get; set; }
            public double primaryPoint8 { get; set; }
            public double primaryPoint9 { get; set; }
            public double primaryPointCorner { get; set; }

            public double ucf_x { get; set; }
            public double ucf_x1 { get; set; }
            public double ucf_x2 { get; set; }
            public double ucf_y { get; set; }
            public double ucf_y1 { get; set; }
            public double ucf_y2 { get; set; }
            public double ucf_z { get; set; }
            public double ucf_z1 { get; set; }
            public double ucf_z2 { get; set; }


            public double y { get; set; }
            public double yCorner { get; set; }
            public double y2 { get; set; }
            public double y3 { get; set; }
            public double y4 { get; set; }
            public double y5 { get; set; }
            public double y6 { get; set; }
            public double y7 { get; set; }
            public double y8 { get; set; }
            public double y9 { get; set; }
            public double z { get; set; }
            public double zCorner { get; set; }
            public double z2 { get; set; }
            public double z3 { get; set; }
            public double z4 { get; set; }
            public double z5 { get; set; }
            public double z6 { get; set; }
            public double z7 { get; set; }
            public double z8 { get; set; }
            public double z9 { get; set; }

        }
    }

【讨论】:

    【解决方案2】:

    他是一个好的开始。我做了标题、类、实体和表(大部分代码)。

    第 1 部分

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    
    namespace DXF_Parser
    {
        class Program
        {
            enum State
            {
                SECTION_START,
                SECTION_CONTINUE,
                EOF,
                NONE
            }
            const string FILENAME = @"c:\temp\test1.txt";
            static void Main(string[] args)
            {
                StreamReader reader = new StreamReader(FILENAME);
                State state = State.SECTION_START;
                Section section = new Section(); 
                string line = "";
                Result result = null;
                int lineCount = 0;
                while ((state != State.EOF) && (line = reader.ReadLine()) != null)
                {
                    line = line.Trim();
                    lineCount++;
                    //if (line.Length > 0)
                    //{
                        switch (state)
                        {
                            case State.SECTION_START:
                                //section = new Section();
                                //section.AddSection();
                                result = section.Parse(line);
                                if (result.status != "OK") Error(lineCount, line, result);
                                state = State.SECTION_CONTINUE;
                                break;
    
                            case State.SECTION_CONTINUE:
                                if (line == "EOF")
                                {
                                    state = State.EOF;
                                }
                                else
                                {
                                    result = section.Parse(line);
                                    switch (result.status)
                                    {
                                        case "OK":
                                            break;
                                       case "ENDSEC":
                                            state = State.SECTION_START;
                                            section.row = 1;
                                            break;
                                        default:
                                            Error(lineCount, line, result);
                                            break;
                                    }
                                }
                                break;
                        }
                    //}
                }
                Console.Write("Press Return");
                Console.ReadLine();
            }
            static void Error(int lineCount, string line, Result error)
            {
                Console.WriteLine("Error : {0}, Line Number : {1}, Line : {2}", error.message, lineCount, line);
            }
    
        }
        public class Result
        {
            public string status { get; set; }
            public string message { get; set; }
        }
        public enum GROUP_CODE
        {
            ENTITY_TYPE = 0,
            PRIMARY_TEXT_VALUE = 1,
            NAME = 2,
            TEXT = 3,
            ENTITY_HANDLE = 5,
            LINE_TYPE = 6,
            TEXT_STYLE_NAME = 7,
            LAYER_NAME = 8,
            DXF = 9,
            PRIMARY_POINT = 10,
            PRIMARY_POINT_CORNER = 11,
            PRIMARY_POINT_2 = 12,
            PRIMARY_POINT_3 = 13,
            PRIMARY_POINT_4 = 14,
            PRIMARY_POINT_5 = 15,
            PRIMARY_POINT_6 = 16,
            PRIMARY_POINT_7 = 17,
            PRIMARY_POINT_8 = 18,
            PRIMARY_POINT_9 = 19,
            Y_VALUE = 20,
            Y_VALUE_CORNER = 21,
            Y_VALUE_2 = 22,
            Y_VALUE_3 = 23,
            Y_VALUE_4 = 24,
            Y_VALUE_5 = 25,
            Y_VALUE_6 = 26,
            Y_VALUE_7 = 27,
            Y_VALUE_8 = 28,
            Y_VALUE_9 = 29,
            Z_VALUE = 30,
            Z_VALUE_CORNER = 31,
            Z_VALUE_2 = 32,
            Z_VALUE_3 = 33,
            Z_VALUE_4 = 34,
            Z_VALUE_5 = 35,
            Z_VALUE_6 = 36,
            Z_VALUE_7 = 37,
            Z_VALUE_8 = 38,
            Z_VALUE_9 = 39,
            DOUBLE_PRECISION = 40,
            DOUBLE_PRECISION_1 = 41,
            DOUBLE_PRECISION_2 = 42,
            DOUBLE_PRECISION_3 = 43,
            DOUBLE_PRECISION_4 = 44,
            LINE_TYPE_SCALE = 48,
            ANGLE = 50,
            ANGLE_1 = 51,
            COLOR_NUMBER = 62,
            NOT_IN_SPECIFICATION = 65,
            INT_VALUE = 70,
            INT_VALUE_1 = 71,
            INT_VALUE_2 = 72,
            INT_VALUE_3 = 73,
            INT_VALUE_4 = 74,
            INT_VALUE_5 = 75,
            INT_VALUE_6 = 76,
            INT_VALUE_7 = 77,
            INT_VALUE_8 = 78,
            INT_VALUE_9 = 79,
            PROXY_CAPABILITY_FLAG = 90,
            SUBCLASS_MARKER = 100,
            UCF_X = 110,
            UCF_X1 = 111,
            UCF_X2 = 112,
            UCF_Y = 120,
            UCF_Y1 = 121,
            UCF_Y2 = 122,
            UCF_Z = 130,
            UCF_Z1 = 131,
            UCF_Z2 = 132,
    
            DOUBLE_PRECISION_POINT = 140,
            DOUBLE_PRECISION_POINT_1 = 141,
            DOUBLE_PRECISION_POINT_2 = 142,
            DOUBLE_PRECISION_POINT_3 = 143,
            DOUBLE_PRECISION_POINT_4 = 144,
            DOUBLE_PRECISION_POINT_5 = 145,
            DOUBLE_PRECISION_POINT_6 = 146,
            DOUBLE_PRECISION_POINT_7 = 147,
            DOUBLE_PRECISION_POINT_8 = 148,
            DOUBLE_PRECISION_POINT_9 = 149,
    
    
            INSTANCE_COUNT = 91,
            INT_16 = 280,
            INT_16_1 = 281,
            BOOLEAN = 290,
            SOFT_POINTER_HANDLE = 330,
            HARD_POINTER_HANDLE_7 = 347,
            LINE_WEIGHT = 370,
            PLOT_STYLE =380
        }
        public enum READ_STATE
        {
            GET_CREATE_SECTION,
            GET_OBJECT_TYPE,
            GET_OBJECT,
            GET_GROUP_CODE,
            GET_LAYER,
            GET_LAYER_NAME,
            GET_SECTION_DATA,
            GET_VARIABLE_NAME,
            GET_VARIABLE_TYPE,
            GET_VARIABLE_VALUES,
            NONE
        }
        public class Section
        {
            public static List<Section> sections = new List<Section>();
            GROUP_CODE currentGroupCode { get; set; }
            Section currentSection { get; set; }
            public int row = 1;
            string sectionName { get; set; }
            READ_STATE readState = READ_STATE.NONE;
    
            public int numberValues { get; set; }
            public int valueCounter = 0;
    
            public void AddSection()
            {
                 sections.Add(this);
            }
            public Result Parse(string line)
            {
                Result result = new Result() { status = "OK" };
                int number = 0;
    
                switch (row)
                {
                    case 1:
                        number = int.Parse(line);
                        if (number != (int)GROUP_CODE.ENTITY_TYPE)
                        {
                            result.status = "ERROR";
                            result.message = "Bad Section Code";
                        }
                        break;
                    case 2:
                        switch (line)
                        {
                            case "SECTION" :
                                break;
                            case "EOF" :
                                result.status = "EOF";
                                break;
                            default :
                                result.status = "ERROR";
                                result.message = "Expecting Section";
                                break;
                        }
                        break;
    
                    case 3:
                        number = int.Parse(line);
                        if (number != (int)GROUP_CODE.NAME)
                        {
                            result.status = "ERROR";
                            result.message = "Bad Group Code";
                        }
                        break;
                    case 4:
                        sectionName = line;
                        readState = READ_STATE.GET_CREATE_SECTION;
                        break;
    
                    default:
                        if (readState == READ_STATE.GET_CREATE_SECTION)
                        {
                            switch (sectionName)
                            {
                                case "HEADER":
                                    currentSection = new Header();
                                    break;
                                case "ENTITIES":
                                    currentSection = new Entities();
                                    break;
                                case "CLASSES":
                                    currentSection = new Class();
                                    break;
                                case "TABLES":
                                    currentSection = new Table();
                                    break;
                                default :
                                    break;
                            }
                            currentSection.sectionName = sectionName;
                            Section.sections.Add(currentSection);
                            readState = READ_STATE.GET_SECTION_DATA;
                        }
                        switch (sectionName)
                        {
                            case "HEADER":
                                result = ((Header)currentSection).HeaderParse(line);
                                break;
                            case "ENTITIES":
                                result = ((Entities)currentSection).EntityParse(line);
                                break;
                            case "CLASSES":
                                result = ((Class)currentSection).ClassParse(line);
                                break;
                           case "TABLES":
                                result = ((Table)currentSection).TableParse(line);
                                break;
                               default :
                                break;
                        }
                        break;
    
                }
                row++;
    
                return result;
            }
        }
        public class Header : Section
        {
            public GROUP_CODE groupCode { get; set; }
    
            GROUP_CODE currentGroupCode { get; set; }
            public Dictionary<string, DXF_Header_Variable> dictHeaderVariables;
            DXF_Header_Variable currentVariable = null;
            READ_STATE readState = READ_STATE.GET_GROUP_CODE;
    
            public Result HeaderParse(string line)
            {
    
                Result result = new Result() { status = "OK" };
                switch (readState)
                {
                    case READ_STATE.GET_GROUP_CODE:
                        currentGroupCode = (GROUP_CODE)Enum.Parse(typeof(GROUP_CODE), line);
                        readState = READ_STATE.GET_VARIABLE_NAME;
                        break;
                    case READ_STATE.GET_VARIABLE_NAME:
                        if (line == "ENDSEC")
                        {
                            result.status = line;
                        }
                        else
                        {
                            if (dictHeaderVariables == null) dictHeaderVariables = new Dictionary<string, DXF_Header_Variable>();
                            currentVariable = new DXF_Header_Variable();
                            dictHeaderVariables.Add(line, currentVariable);
                            currentVariable.name = line;
                            readState = READ_STATE.GET_VARIABLE_TYPE;
                        }
                        break;
                    case READ_STATE.GET_VARIABLE_TYPE:
                        groupCode = (GROUP_CODE)Enum.Parse(typeof(GROUP_CODE), line);
                        switch (groupCode)
                        {
                            case GROUP_CODE.ENTITY_TYPE :
                                readState = READ_STATE.GET_VARIABLE_NAME;
                                break;
                            case GROUP_CODE.DXF:
                                readState = READ_STATE.GET_VARIABLE_NAME;
                                break;
                            default:
                                readState = READ_STATE.GET_VARIABLE_VALUES;
                                break;
                        }
                        break;
                    case READ_STATE.GET_VARIABLE_VALUES:
                         switch (groupCode)
                         {
                             case GROUP_CODE.ANGLE:
                                 currentVariable.angle = double.Parse(line);
                                 break;
                             case GROUP_CODE.BOOLEAN :
                                 currentVariable.logic = (line == "0")? false : true;
                                 break;
                             case GROUP_CODE.COLOR_NUMBER:
                                 currentVariable.intValue = int.Parse(line);
                                 break;
                             case GROUP_CODE.DOUBLE_PRECISION:
                                 currentVariable.primaryPoint = double.Parse(line);
                                 break;
                             case GROUP_CODE.ENTITY_HANDLE:
                                 currentVariable.intValue = int.Parse(line);
                                 break;
                             case GROUP_CODE.HARD_POINTER_HANDLE_7:
                                 currentVariable.text = line;
                                 break;
                             case GROUP_CODE.INT_VALUE:
                                 currentVariable.intValue = int.Parse(line);
                                 break;
                             case GROUP_CODE.INT_16:
                                 currentVariable.intValue = int.Parse(line);
                                 break;
                             case GROUP_CODE.LINE_TYPE:
                                 currentVariable.text = line;
                                 break;
                             case GROUP_CODE.LAYER_NAME:
                                 currentVariable.intValue = int.Parse(line);
                                 break;
                             case GROUP_CODE.LINE_WEIGHT:
                                 currentVariable.intValue = int.Parse(line);
                                 break;
                             case GROUP_CODE.NAME:
                                 currentVariable.text = line;
                                 break;
                             case GROUP_CODE.PLOT_STYLE:
                                 currentVariable.intValue = int.Parse(line);
                                 break;
                             case GROUP_CODE.PRIMARY_POINT:
                                 currentVariable.primaryPoint = double.Parse(line);
                                 break;
                             case GROUP_CODE.PRIMARY_TEXT_VALUE:
                                 currentVariable.primaryTextValue = line;
                                 break;
                             case GROUP_CODE.TEXT:
                                 currentVariable.text = line;
                                 break;
                             case GROUP_CODE.TEXT_STYLE_NAME:
                                 currentVariable.text = line;
                                 break;
                             case GROUP_CODE.Y_VALUE:
                                 currentVariable.y = double.Parse(line);
                                 break;
                             case GROUP_CODE.Z_VALUE:
                                 currentVariable.z = double.Parse(line);
                                 break;
                             default :
                                 break;
                         }
                         readState = READ_STATE.GET_VARIABLE_TYPE;
                         break;
                }
    
                return result;
            }
        }
        public class DXF_Header_Variable
        {
            public double angle { get; set; }
            public double primaryPoint { get; set; }
            public double y { get; set; }
            public double z { get; set; }
            public string primaryTextValue { get; set; }
            public string name { get; set; }
            public int intValue { get; set; }
            public string text { get; set; }
            public Boolean logic { get; set; }
        }
        public class Entities : Section
        {
            public GROUP_CODE groupCode { get; set; }
            GROUP_CODE currentGroupCode { get; set; }
            public List<Entity> entities;
            Entity currentEntity = null;
            READ_STATE readState = READ_STATE.GET_GROUP_CODE;
    
            public Result EntityParse(string line)
            {
    
                Result result = new Result() { status = "OK" };
                switch (readState)
                {
                    case READ_STATE.GET_GROUP_CODE:
                        currentGroupCode = (GROUP_CODE)Enum.Parse(typeof(GROUP_CODE), line);
                        readState = READ_STATE.GET_VARIABLE_NAME;
                        break;
                    case READ_STATE.GET_VARIABLE_NAME:
                        if (line == "ENDSEC")
                        {
                            result.status = line;
                        }
                        else
                        {
    
                            if (entities == null) entities = new List<Entity>();
                            currentEntity = new Entity();
                            entities.Add(currentEntity);
                            currentEntity.name = line;
                            readState = READ_STATE.GET_LAYER;
                        }
                        break;
                    case READ_STATE.GET_LAYER:
                        groupCode = (GROUP_CODE)Enum.Parse(typeof(GROUP_CODE), line);
                        readState = READ_STATE.GET_LAYER_NAME;
                        break;
                    case READ_STATE.GET_LAYER_NAME:
                        currentEntity.layerName = int.Parse(line);
                        readState = READ_STATE.GET_VARIABLE_TYPE;
                        break;
                    case READ_STATE.GET_VARIABLE_TYPE:
                        groupCode = (GROUP_CODE)Enum.Parse(typeof(GROUP_CODE), line);
                        if (groupCode == GROUP_CODE.ENTITY_TYPE)
                        {
                            readState = READ_STATE.GET_VARIABLE_NAME;
                        }
                        else
                        {
                            readState = READ_STATE.GET_VARIABLE_VALUES;
                        }
                        break;
                    case READ_STATE.GET_VARIABLE_VALUES:
                        double value = double.Parse(line);
                        switch (groupCode)
                        {
                            case GROUP_CODE.PRIMARY_POINT :
                                currentEntity.primaryPoint = value;
                                break;
                            case GROUP_CODE.Y_VALUE:
                                currentEntity.y = value;
                                break;
                            case GROUP_CODE.Z_VALUE:
                                currentEntity.z = value;
                                break;
    
                            case GROUP_CODE.PRIMARY_POINT_CORNER :
                                currentEntity.primaryPoint = value;
                                break;
                            case GROUP_CODE.Y_VALUE_CORNER :
                                currentEntity.yCorner = value;
                                break;
                            case GROUP_CODE.Z_VALUE_CORNER:
                                currentEntity.zCorner = value;
                                break;
                        }
    
                        readState = READ_STATE.GET_VARIABLE_TYPE;
                        break;
                }
    
                return result;
            }
        }
        public class Entity
        {
            public double primaryPoint { get; set; }
            public double y { get; set; }
            public double z { get; set; }
            public double primaryPointCorner { get; set; }
            public double yCorner { get; set; }
            public double zCorner { get; set; }
            public string name { get; set; }
            public int layerName { get; set; }
        }
        public class Class : Section
        {
            public Dictionary<string, Class_Type> dictClassVariables;
            Class_Type currentClass = null;
            GROUP_CODE currentGroupCode { get; set; }
            string className { get; set; }
            READ_STATE readState = READ_STATE.GET_GROUP_CODE;
    
            public Result ClassParse(string line)
            {
    
                Result result = new Result() { status = "OK" };
                switch (readState)
                {
                    case READ_STATE.GET_GROUP_CODE:
                        currentGroupCode = (GROUP_CODE)Enum.Parse(typeof(GROUP_CODE), line);
                        readState = READ_STATE.GET_VARIABLE_NAME;
                        break;
                    case READ_STATE.GET_VARIABLE_NAME:
                        if (line == "ENDSEC")
                        {
                            result.status = line;
                        }
                        else
                        {
                             readState = READ_STATE.GET_VARIABLE_TYPE;
                        }
                        break;
                    case READ_STATE.GET_VARIABLE_TYPE:
                        currentGroupCode = (GROUP_CODE)Enum.Parse(typeof(GROUP_CODE), line);
                        switch (currentGroupCode)
                        {
                            case GROUP_CODE.ENTITY_TYPE:
                                readState = READ_STATE.GET_VARIABLE_NAME;
                                break;
                            default:
                                readState = READ_STATE.GET_VARIABLE_VALUES;
                                break;
                        }
                        break;
                    case READ_STATE.GET_VARIABLE_VALUES:
                        switch (currentGroupCode)
                        {
                            case GROUP_CODE.PRIMARY_TEXT_VALUE :
                                if (dictClassVariables == null) dictClassVariables = new Dictionary<string,Class_Type>();
                                currentClass = new Class_Type();
                                dictClassVariables.Add(line, currentClass);
                                currentClass.dxfName = line;
                                break;
    
                            case GROUP_CODE.NAME:
                                currentClass.className = line;
                                break;
    
                            case GROUP_CODE.TEXT:
                                currentClass.applicationName = line;
                                break;
    
                            case GROUP_CODE.PROXY_CAPABILITY_FLAG:
                                currentClass.proxyCapabilityFlag  = uint.Parse(line);
                                break;
    
                            case GROUP_CODE.INSTANCE_COUNT:
                                currentClass.instance = int.Parse(line);
                                break;
    
                            case GROUP_CODE.INT_16:
                                currentClass.wasAProxyFlag = (line == "0") ? false : true;
                                break;
    
                            case GROUP_CODE.INT_16_1:
                                currentClass.isAnEntityFlag = (line == "0") ? false : true;
                                break;
    
                            default:
                                break;
                        }
                        readState = READ_STATE.GET_VARIABLE_TYPE;
                        break;
                }
    
                return result;
            }
        }
        public class Class_Type
        {
            public string dxfName { get; set; }
            public string className { get; set; }
            public string applicationName { get; set; }
            public uint proxyCapabilityFlag { get; set; }
            public int instance { get; set; }
            public Boolean wasAProxyFlag { get; set; }
            public Boolean isAnEntityFlag { get; set; }
    
        }
    

    【讨论】:

    • 谢谢,但我不懂Java :-),我只能处理python
    【解决方案3】:

    您的链接不起作用,而是发布文件的几行以显示结构,因为要求人们下载大文件是不好的做法。

    看起来有一个用于处理 dxf 文件的库,名为 ezdxfHere is a link 了解如何从 dxf 文件中提取数据的指南

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-18
      • 2019-02-19
      • 1970-01-01
      相关资源
      最近更新 更多