Method for reading and XML conversion based on STP file format
Through JavaScript and regular expression technology, the data loss and inefficiency in STP file to XML format conversion is solved, and efficient and accurate three-dimensional model data exchange is achieved, suitable for complex engineering design and manufacturing fields.
Patent Information
- Application Number
- CN202411003306.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2024-11-08
AI Technical Summary
In the prior art, the conversion technology of STP file to XML format is immature, and there are problems such as data loss, low conversion efficiency and unreasonable XML structure, which is difficult to meet the needs of data exchange for complex three-dimensional models.
Code is written in JavaScript high-level language, using FileReader API to read STP files, match data entities through regular expressions, and retype the data header information with the matching data, and finally save it as a well-structured XML file.
It realizes efficient and accurate conversion of STP files to XML format, improves the efficiency and accuracy of data exchange, reduces development costs, and allows users to easily extract key information from three-dimensional models, and is suitable for engineering design, manufacturing and simulation fields.
Smart Images

Figure CN118916523A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer graphics processing, three-dimensional model data exchange and data conversion, and in particular, to a method for reading and converting STP (Standard for the Exchange of Product Model Data) file format into XML (Extensible Markup Language). The technology realizes the conversion of STP graphics exchange files into XML files, which is conducive to extracting effective data using XML data mining technology to form a data warehouse for user-specific software and various engineering software. Background Art
[0002] STP file format, as a widely used data exchange standard in CAD (computer-aided design) and other 3D modeling software, facilitates the sharing of 3D model data between different software. STP files can record key information such as the geometry, structure, and material of 3D models in detail, so they have important applications in engineering design, manufacturing, simulation and other fields.
[0003] With the continuous development of information technology and the deepening of global collaboration, the demand for cross-platform and cross-system exchange and sharing of 3D model data is increasing. XML, as a markup language, has good readability, scalability and cross-platform, and has become one of the universal formats for data exchange. Converting STP files to XML format can greatly improve the circulation and operability of data between different systems and applications.
[0004] At present, although there are some STP file viewing and conversion tools on the market, most of them focus on converting STP to other 3D formats or for specific CAD systems, while the technology of directly converting STP to XML format is not mature. In addition, the existing conversion methods often have problems such as data loss, low conversion efficiency, and unreasonable XML structure, which makes it difficult to meet the complex 3D model data exchange requirements.
[0005] Therefore, developing an efficient, accurate and structured STP to XML conversion method is of great significance for improving the exchange efficiency of 3D model data, ensuring data integrity and promoting multi-platform collaboration. Based on this demand, the present invention proposes a STP file format reading and XML conversion method, aiming to solve the deficiencies in the current technology and contribute to the technical development of related fields. Summary of the invention
[0006] In view of the above problems existing in the prior art, the main purpose of the present invention is to provide a method for reading and converting to XML based on the STP file format, which can accurately and efficiently read the data in the STP file and convert it into an XML format with a clear structure and easy to parse. Through this conversion, users can more conveniently extract and use the key information in the STP file without in-depth study of the complex STP format specifications.
[0007] The technical solution of the present invention is as follows:
[0008] A method for reading and converting to XML based on STP file format, comprising the following steps:
[0009] S1: accept input STP data format text;
[0010] S2: Read the data header information of the STP file;
[0011] S3: Use regular expressions to match entity data in the data portion of the STP file;
[0012] S4: Re-layout the data header information and the matched data, and obtain the layout result;
[0013] S5: Save the typesetting result as an XML file.
[0014] In the step S1, the receiving of the input STP data format text is specifically: using FileReader API to receive the input STP file in the JavaScript high-level language code.
[0015] In the step S2, the reading of the data header information of the STP file specifically includes:
[0016] Declare a header variable, read the data content of the STP file from the beginning until the file reads the character ENDSEC, and save the read header information in the header variable.
[0017] In step S3, the use of regular expressions to match entity data in the STP file data portion specifically includes:
[0018] S301: Write corresponding regular expressions according to the storage specifications of various entity data in the STP data format, and use the regular expressions to match the corresponding entity data in the STP file;
[0019] S302: Integrate various attribute style data of the same entity according to the result matched by the regular expression;
[0020] S303: storing the integrated entity data into different entity arrays according to different entity types.
[0021] In step S4, the data header information and the matched data are rearranged and a layout result is obtained, which specifically includes:
[0022] S401: Create an XML document body;
[0023] S402: Write the content of the file header variable into the XML file body;
[0024] S403: Write the contents of each entity array into the XML file body in sequence.
[0025] In step S5, the typesetting result is saved as an XML file, specifically:
[0026] The XML file body after the data content is written is saved in XML file format.
[0027] The XML file body after the data content is written is saved in the XML file format, specifically: the XML file body after the data content is written is saved in the XML file format using a programming language.
[0028] The XML file body after data content is written is saved in XML file format using a programming language. Specifically, the Blob object is used in combination with the URL.createObjectURL() method in the JavaScript high-level language code to save the XML file body as an XML file.
[0029] The present invention has the following advantages and beneficial effects:
[0030] 1. The present invention provides a method for reading and converting to XML based on the STP file format, which is universal, flexible and extensible; because regular expressions are used for data matching, the present invention can process various standard and non-standard STP files and has strong universality. At the same time, users can customize regular expressions as needed to adapt to different data extraction requirements, which reflects the flexibility of the present invention. In addition, the present invention can also expand and optimize functions as needed to meet more complex data processing scenarios;
[0031] 2. Through the conversion method of the present invention, users can easily convert STP files into XML format, thereby taking advantage of XML's readability and scalability to improve the efficiency and accuracy of data exchange. This has important application value in the fields of engineering design, manufacturing, simulation, etc. that require frequent exchange of 3D model data;
[0032] 3. The converted XML file has a good format and clear structure, making it very easy for user-specific software and various engineering software to extract valid data. There is no need to spend a lot of time studying the various identifiers and file structures of the STP file, which greatly reduces the development cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 A flowchart of a method for reading and converting to XML based on the STP file format is provided in an embodiment of the present invention.
[0034] Figure 2 This is a partial entity data diagram of the original STP file.
[0035] Figure 3 This is a partial data diagram after conversion into XML file format. DETAILED DESCRIPTION
[0036] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. The components of the embodiments of the present invention described and shown in the drawings herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0037] The present invention will be further described below with reference to the accompanying drawings and specific embodiments.
[0038] like Figures 1 to 3 As shown: The method for reading and converting to XML based on the STP file format according to the embodiment of the present invention comprises the following steps:
[0039] S1: accept input STP data format text;
[0040] S2: Read the data header information of the STP file;
[0041] S3: Use regular expressions to match entity data in the data portion of the STP file;
[0042] S4: Re-layout the data header information and the matched data, and obtain the layout result;
[0043] S5: Save the typesetting result as an XML file.
[0044] A method for reading STP file data and converting it into an XML file provided by an embodiment of the present invention relates to STP file data processing and conversion in the field of engineering technology, especially for STP files generated by various CAD / CAM / CAE systems, including receiving an input STP data format text provided by a manufacturing execution system, using a regular expression to match the content of the entire STP file, re-formatting the matched results, and finally outputting them as a file in XML format. This is the conversion from STP format to XML format.
[0045] The method for reading STP file data and converting it into an XML file provided by the embodiment of the present invention can effectively process various standard and non-standard STP files, and has universality, flexibility, extensibility and portability. The converted XML file has a good format and a clear structure, making it very easy for user-specific software and various engineering software to extract valid data, without spending a lot of time studying various identifiers and file structures of STP files, thereby reducing development costs.
[0046] An embodiment of the present invention provides a method for reading STP file data and converting it into an XML file. In step S1, the receiving of input STP data format text specifically includes: using FileReader API in a JavaScript high-level language code to receive the input STP file.
[0047] The STP file is: STP (Standard for the Exchange of Product model data) is a standard for product model data exchange, which defines a format for exchanging 3D model data and related information between different computer-aided design (CAD) systems. It is formulated by ISO, and the specific text encoding specification is ISO 10303-21. STP files describe product data through a clear text encoding structure, so that CAD software from different manufacturers can understand and exchange data with each other, and support cross-system collaboration and integration.
[0048] The STP file header data is from the initial start identifier ISO-10303-21 of the STP file to the end identifier ENDSEC, including the file name, timestamp, author, organization, preprocessing version, original system and authorization information.
[0049] An embodiment of the present invention provides a method for reading STP file data and converting it into an XML file. In step S2, the data header information of the STP file is read, specifically including:
[0050] Declare a header variable, read the data content of the STP file from the beginning until the file reads the character ENDSEC, and save the read header information in the header variable.
[0051] That is, declare a header variable and read the data of the STP file. Keep writing the read STP file data into the header variable until the identifier ENDSEC is encountered, and the data writing ends. At this time, all the file header data has been saved.
[0052] An embodiment of the present invention provides a method for reading STP file data and converting it into an XML file. In step S3, the entity data of the STP file data part is matched using a regular expression, specifically including:
[0053] S301: Write corresponding regular expressions according to the storage specifications of various entity data in the STP data format, and use the regular expressions to match the corresponding entity data in the STP file;
[0054] S302: Integrate various attribute style data of the same entity according to the result matched by the regular expression;
[0055] S303: storing the integrated entity data into different entity arrays according to different entity types.
[0056] Different entities in the STP file have different data storage specifications. You need to write corresponding regular expressions according to the storage specifications of various entity data in the STP data format, and use regular expressions to match the corresponding entity data in the STP file. Store the results of regular expression matching in different arrays. After waiting for all regular expression matches to be completed, extract various attribute style data belonging to the same entity from different arrays for integration. Store the integrated entity data in different entity arrays according to different entity types.
[0057] Specifically, in the STP file, the regular expression for the center coordinates of the circle is " / #(\d+)=CARTESIA N_POINT\('\',\((-?\d+\.?\d*),(-?\d+\.?\d*),(-?\d+\.?\d*)\)\); / g", and the regular expression for the radius of the circle is " / #(\d+)=CIRCLE\('([^']+)',#(\d+),([\d\.]+)\); / g". The regular expressions for other entity data can also be written according to the STP data storage specification. By matching the regular expressions, the entity data in the STP file can be obtained.
[0058] An embodiment of the present invention provides a method for reading STP file data and converting it into an XML file. In step S4, the data header information and the matched data are rearranged and the layout result is obtained, which specifically includes:
[0059] S401: Create an XML document body;
[0060] S402: Write the content of the file header variable into the XML file body;
[0061] S403: Write the contents of each entity array into the XML file body in sequence.
[0062] Declare a variable as the body of the XML file. Write the contents of the file header variable into the body of the XML file according to the XML data specification. Write the contents of each entity array into the body of the XML file in order according to the XML data specification. The XML data format is: XML Extensible Markup Language, as a subset of the broader standard general markup language, is a markup language used to mark electronic files to make them structured; XML is independent of the operating system, programming language, and development platform, and can realize data interaction between different systems and languages. In the XML data format text, nodes are the basic units that make up an XML file. XML files are composed of nodes, the first of which is called the "root node". Each XML file must and can only contain one root node, and all other nodes must be child nodes of the root node, and each child node can also have its own child nodes. Each node contains a node name and (optional) a node value.
[0063] An embodiment of the present invention provides a method for reading STP file data and converting it into an XML file. In step S5, the typesetting result is saved as an XML file, specifically:
[0064] The XML file body after the data content is written is saved as an XML file format. The XML file body after the data content is written is saved as an XML file format using a programming language. Specifically, the Blob object is used in conjunction with the URL.createObjectURL() method in the JavaScript high-level language code to save the XML file body as an XML file.
[0065] Through the conversion method of the present invention, users can easily convert STP files into XML format, thereby taking advantage of the readability and scalability of XML to improve the efficiency and accuracy of data exchange. This has important application value for engineering design, manufacturing, simulation and other fields that require frequent exchange of 3D model data. At the same time, due to the readability and scalability advantages of XML format, users can more easily extract and use key information in STP files, which provides convenience for applications in engineering design, manufacturing, simulation and other fields.
[0066] The embodiment of the present invention provides a method for reading and converting XML based on the STP file format, which is universal, flexible and extensible; because regular expressions are used for data matching, the present invention can process various standard and non-standard STP files and has strong universality. At the same time, users can customize regular expressions as needed to adapt to different data extraction requirements, which reflects the flexibility of the present invention. In addition, the present invention can also expand and optimize functions as needed to meet more complex data processing scenarios;
[0067] At the technical implementation level, the present invention relates to the data processing and conversion of STP files in the field of engineering technology, especially STP files generated by CAD / CAM / CAE systems. By receiving the input STP data format text, using regular expressions to match and re-format the file content, and finally outputting a well-structured and well-formatted XML file. This process not only simplifies data extraction work, but also reduces development costs, so that users do not need to deeply study the various identifiers and complex file structures of STP files.
[0068] Finally, it should be noted that the above-described embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some or all of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for reading and converting to XML based on STP file format, characterized in that: The following steps are involved: ; S1: accept input STP data format text; S2: Read the data header information of the STP file; S3: Use regular expressions to match entity data in the data portion of the STP file; S4: Re-layout the data header information and the matched data, and obtain the layout result; S5: Save the typesetting result as an XML file.
2. The method for reading and converting to XML based on the STP file format according to claim 1, characterized in that: In the step S1, the receiving of the input STP data format text is specifically: using FileReader API to receive the input STP file in the JavaScript high-level language code.
3. The method for reading and converting to XML based on the STP file format according to claim 1, characterized in that: In the step S2, the reading of the data header information of the STP file specifically includes: Declare a header variable, read the data content of the STP file from the beginning until the file reads the character ENDSEC, and save the read header information in the header variable.
4. The method for reading and converting to XML based on the STP file format according to claim 1, characterized in that: In step S3, the use of regular expressions to match entity data in the STP file data portion specifically includes: S301: Write corresponding regular expressions according to the storage specifications of various entity data in the STP data format, and use the regular expressions to match the corresponding entity data in the STP file; S302: Integrate various attribute style data of the same entity according to the result matched by the regular expression; S303: storing the integrated entity data into different entity arrays according to different entity types.
5. The method for reading and converting to XML based on the STP file format according to claim 1, characterized in that: In step S4, the data header information and the matched data are rearranged and a layout result is obtained, which specifically includes: S401: Create an XML document body; S402: Write the content of the file header variable into the XML file body; S403: Write the contents of each entity array into the XML file body in sequence.
6. The method for reading and converting to XML based on the STP file format according to claim 1, characterized in that: In step S5, the typesetting result is saved as an XML file, specifically: The XML file body after the data content is written is saved in XML file format.
7. The method for reading and converting to XML based on the STP file format according to claim 6, characterized in that: The XML file body after the data content is written is saved in the XML file format, specifically: the XML file body after the data content is written is saved in the XML file format using a programming language.
8. The method for reading and converting to XML based on the STP file format according to claim 7, characterized in that: The XML file body after data content is written is saved in XML file format using a programming language. Specifically, the Blob object is used in combination with the URL.createObjectURL() method in the JavaScript high-level language code to save the XML file body as an XML file.
Citation Information
Patent Citations
Method for generating word document in templated mode
CN111159995A
Conversion method of processing data based on STEP file
CN112699427A
Data Exchange System for Exchange Data among Heterogeneous Systems, and
KR1020110026973A
IN814CH2014A
