A python-based CAD engineering drawing output system and method

CN122987138APending Publication Date: 2026-10-27CHINA POWER CONSTR GRP ARCHITECTURAL PLANNING & DESIGN INST CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611143808.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-30
Publication Date
2026-10-27

AI Technical Summary

Technical Problem

一种基于Python的CAD工程图纸出图系统及方法,及其相关技术,以解决现有技术工作效率和制图质量低等技术问题或其组合

Benefits of technology

(1)数字化CAD制图技术已全面替代了工程设计行业中的传统图板制图方式,而Python也因其灵活性和完善的库生态系统在自动化办工领域吸引了大量的关注。本发明将CAD工程图纸的全部出图信息分类汇总,并形成出图信息表,在用户对出图信息表进行编辑保存后,对CAD工程图纸进行图框信息文本处理和PDF格式转换,其中出图信息表的形成和图纸的出图操作通过利用Python技术对CAD绘图软件进行控制来完成,为CAD工程图纸的出图问题提供了新的解决方案。这不仅实现了图框信息处理与PDF格式转换两项工作的批量化、自动化、一体化,同时为出图信息的集中校核提供了便利,使得设计人员可以更便捷、准确地完成CAD工程图纸的出图任务,从而提高工作效率和制图质量。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122987138A_ABST
    Figure CN122987138A_ABST
Patent Text Reader

Abstract

The application discloses a CAD engineering drawing output system and method based on Python and belongs to the technical field of engineering drawing output. The technical problem to be solved is low work efficiency and low drawing quality in the prior art. The CAD engineering drawing file preprocessing module is configured to preprocess all CAD engineering drawing files to be output by a user to meet specific output format requirements; the drawing control information generation module is configured to acquire all information data required for output and write the information data into a table file to form a drawing information table file; and the frame information text processing and PDF format conversion module is configured to read data rows in the drawing information table in sequence, perform frame information text processing on the CAD engineering drawing to be output, and perform PDF format conversion until the output work of all drawings is completed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of engineering drawing output technology, and in particular to a Python-based CAD engineering drawing output system and method. Background Technology

[0002] Thanks to the continuous improvement of computer hardware performance and the increasing maturity of computer-aided design (CAD) technology, the modern engineering design industry has achieved a comprehensive transformation from traditional drawing board drafting to digital CAD drafting.

[0003] In the CAD drafting process, after the project drawings are completed, they need to be output, including text processing of title block information (drawing name, drawing number, date, etc.) and PDF format conversion. However, in reality, project drawings often undergo multiple changes, and once the design information is modified, the drawings need to be re-output. Manual operation is inefficient and prone to errors and omissions, affecting work efficiency and drafting quality. Currently, the conventional output technology mainly uses a combination of text association mechanisms and batch printing functions. That is, firstly, attribute blocks with variable parameters are predefined in CAD drawing software (such as AutoCAD), and the title block information text is dynamically updated by modifying the block attribute values. Then, the built-in batch printing tool is called to convert the CAD engineering drawings into PDF format files.

[0004] Conventional technologies have the following shortcomings: First, the automation level of the drawing frame information text processing workflow is insufficient. When editing the drawing frame information text, it is still necessary to manually open the CAD engineering drawing file and edit each attribute block sequentially, which is time-consuming and labor-intensive. Second, the distributed storage architecture leads to verification difficulties. Since project drawings are usually stored in multiple CAD engineering drawing files, a centralized drawing verification mechanism cannot be formed before PDF format conversion. Third, the drawing output workflow has gaps; that is, the drawing frame information text processing and PDF format conversion are two independent stages, failing to form an integrated drawing output workflow.

[0005] Therefore, it is necessary to provide a Python-based CAD engineering drawing output system and method. By forming an automated and integrated drawing output process and a centralized drawing information verification mechanism, designers can complete drawing output tasks more conveniently and accurately, thereby improving work efficiency and drawing quality. Summary of the Invention

[0006] The purpose of this invention is to provide: A Python-based CAD engineering drawing output system and method, and related technologies, to solve the technical problems of low work efficiency and low drawing quality in existing technologies, or a combination thereof.

[0007] In the first aspect, the present invention provides: a CAD engineering drawing output system based on Python.

[0008] include: The CAD engineering drawing file preprocessing module is configured to preprocess all CAD engineering drawing files to be output by the user in order to meet specific output format requirements. The drawing control information generation module is configured to acquire all the information data required for drawing and write it into a table file to form a drawing information table file; The module for processing title block information text and converting PDF format is configured to sequentially read the data rows in the drawing information table, process the title block information text of the CAD engineering drawings to be drawn, and convert them to PDF format until the drawing work of all drawings is completed.

[0009] The specific output format must meet the following requirements: The graphic elements in the title block are inserted into the layout space of the CAD engineering drawing file as external references and are located on a separate layer; The lower left corner of the rectangular outer frame in the CAD engineering drawing file, which serves as an external reference, is located at the origin of the coordinate system. All CAD engineering drawing files are stored in the same directory, and the drawing file names are prefixed with serial numbers according to the order of drawing output; When the drawing frame elements of a CAD engineering drawing file are located in multiple layout spaces, the names of the layout spaces are prefixed with a serial number according to the drawing order. When multiple title block elements are inserted into a single layout space in a CAD engineering drawing file, the external reference insertion points of the title block elements are arranged from left to right according to the drawing order.

[0010] The output control information generation module includes a user input unit, an output information table file generation unit, an output information generation unit, and an output information editing unit; The user input unit is configured to allow users to input the file directory where CAD engineering drawing files are stored, the layer name where the drawing frame elements in the CAD engineering drawing files are located, the virtual printer name, and the print style name; The drawing information table file generation unit is configured to generate a drawing information table file with default header information and save it to the CAD engineering drawing file directory; The drawing information generation unit is configured to acquire and generate the drawing information for each drawing and write it into the drawing information table; The output information table editing unit is configured so that users can edit and save the output information data in the output information table file according to the output target.

[0011] The specific input of the virtual printer name and print style name includes the following steps: Create a blank CAD file in CAD software; Retrieve all virtual printer names and print style names available in the CAD software; Users select and enter the desired virtual printer name and print style name.

[0012] The first row of the drawing information table is the header row, and the other rows are data rows. The header row includes the file information header, the drawing information header, the printing information header, and the drawing frame information header.

[0013] Users can modify the plotting information in all data rows of the plotting information table according to the plotting target, or modify or add plotting information headers to meet their personalized needs.

[0014] The module for text processing and PDF conversion of drawing frame information includes the creation of a PDF drawing file directory, reading of drawing information, acquisition of drawing frame elements, setting of text layers and text styles, processing of drawing frame information, setting of printer parameters, and conversion of CAD engineering drawings to PDF format.

[0015] On the other hand, this invention provides a Python-based method for generating CAD engineering drawings, using a Python-based CAD engineering drawing generation system, including the following steps: S1. Preprocess the CAD engineering drawing files, including drawing and inserting drawing frame elements, naming the CAD engineering drawing files, and naming the layout space of the CAD engineering drawing files; S2. Generate the output information table and add the output information for each CAD engineering drawing; S3. Edit and save the drawing information table according to the predetermined drawing output target; add drawing frame information text to each CAD engineering drawing according to the drawing information in the drawing information table, and convert it to PDF format; merge all the drawing files after PDF format conversion to complete the drawing output work.

[0016] Specifically, in step S2, the method for generating the output plotting information is as follows: S201. Based on the CAD engineering drawing file directory entered by the user, use the listdir() function in the os library to get all file names in the directory; S202. Use the path.splitext() function in the os library to filter out the names of CAD engineering drawing files in the directory and form a list of CAD engineering drawing files; S203. Determine if the CAD engineering drawing file list is empty; S204. If the list of CAD engineering drawing files is not empty, then traverse the list of CAD engineering drawing files and obtain the file name of a single CAD engineering drawing file; otherwise, the user re-enters the file directory. S205. Use the Documents.Open() method in the win32com.client module to open the CAD engineering drawing file in the CAD software; S206. Using the layout.Block property in the win32com.client module, obtain all the frame elements located under the user-input frame element layer and form a frame element list. S207. Traverse the list of graphic elements in the title block and obtain a single graphic element in the title block; S208. Store the obtained file directory, file name, title block layer name, printer name, print style name and other default generated output information into a list to form the output information corresponding to a single title block element. Then, use the concat() function in the pandas library to add a row below the last row of the output information table and store the output information list in the append row according to the order of the table header. S209. Determine whether the traversal of all elements in the drawing frame element list has been completed; S210. If the drawing frame element list has completed the traversal of all elements, determine whether the traversal of all elements in the CAD engineering drawing file list has been completed; otherwise, return to step S107 to continue traversing the drawing frame element list. S211. If all CAD engineering drawing files have been traversed, use the to_excel() function in the pandas library to save the drawing information table file; otherwise, continue traversing the list of CAD engineering drawing files.

[0017] Specifically, S3 includes the following steps: S301. Use the mkdir() function in the os library to create a PDF drawing file directory to store all PDF drawing files; S302. Use the read_excel() function in the pandas library to read all data rows of the plot information table file and form a plot information list. Each element in the list is a row of data from the plot information table. S303. Traverse the drawing information list to obtain the drawing information for a single drawing; S304. Obtain file information and drawing information from the drawing information list; S305. Use the Documents property in the win32com.client module to get a list of all open files in the CAD software, and then iterate through the file list to determine whether the CAD engineering drawing file has been opened in the CAD software. S306. If the CAD engineering drawing file is not open, use the Documents.Open() method in the win32com.client module to open the CAD engineering drawing file, and then use the layout.Block property in the win32com.client module to get all the drawing elements located under the drawing frame layer in the file, and store them in the drawing frame element list in the order of drawing output. S307. Use the Document.Layers and Document.TextStyles properties in the win32com.client module to obtain a list of all text layer names and text style names in the CAD engineering drawing file, and determine whether the text layers and text styles have been created in the CAD engineering drawing file. S308. If the text layer and text style have already been created, use the layout.Block property and Delete() method in the win32com.client module to get and delete all text elements located under the text layer; otherwise, use the Layers.Add() method and TextStyles.Add() method in the win32com.client module to create the text layer and text style, and use the TextStyle.fontFile property and TextStyle.bigFontFile property to set the text font and text size. S309. Retrieve the drawing frame elements corresponding to the output information from the drawing frame element list; S310. Obtain the title frame information from the drawing information list; S311. Use the Block.AddText() function in the win32com.client module to generate and insert text primitives according to the coordinates of the insertion point; S312. Obtain printing information from the drawing information list; S313. Use the ConfigName property in the win32com.client module to obtain the printer object, and use the StyleSheet property, SetCustomScale() method and CanonicalMediaName property to set the print style, print scale and print paper parameters. S313. Use the InsertionPoint property in the win32com.client module to get the insertion point of the drawing frame element, and use the SetWindowToPlot() method to set the print area according to the insertion point of the drawing frame element and the paper size. S314. Use the PlotToFile() method in the win32com.client module to convert the CAD engineering drawings to PDF format and save them to the PDF drawing file directory. S315. Determine whether the traversal of all elements in the output information list has been completed; S316. If the output information list has been traversed to all elements, use the write() method in the PdfWriter library to merge all PDF drawing files; otherwise, return to step S303 to continue traversing the output information list.

[0018] The present invention has at least the following beneficial effects: (1) Digital CAD drafting technology has completely replaced the traditional drawing board drafting method in the engineering design industry, and Python has also attracted a lot of attention in the field of automated office work due to its flexibility and complete library ecosystem. This invention classifies and summarizes all the drawing information of CAD engineering drawings and forms a drawing information table. After the user edits and saves the drawing information table, the drawing frame information text processing and PDF format conversion of the CAD engineering drawings are performed. The formation of the drawing information table and the drawing output operation are completed by using Python technology to control the CAD drawing software, providing a new solution to the drawing output problem of CAD engineering drawings. This not only realizes the batch, automation and integration of drawing frame information processing and PDF format conversion, but also provides convenience for the centralized verification of drawing information, enabling designers to complete the drawing output task of CAD engineering drawings more conveniently and accurately, thereby improving work efficiency and drafting quality.

[0019] (2) This invention allows users to add headers and data to the plot information table, and users can customize the text font and height insertion point coordinates to meet users' personalized needs for plot information text.

[0020] (3) The present invention sets the printing area based on the coordinates of the insertion point of the graphic element in the drawing frame and the size of the drawing. Users can input the corresponding size for each drawing to achieve the goal of printing drawings of any size. Attached Figure Description

[0021] Figure 1 This is a flowchart of the system of the present invention.

[0022] Figure 2 This is a flowchart of the drawing output control information generation module of the present invention.

[0023] Figure 3 This is a flowchart of the drawing information generation unit of the present invention.

[0024] Figure 4This is a flowchart of the text processing and PDF format conversion module for the image frame information of the present invention. Detailed Implementation

[0025] The following non-limiting embodiments are intended to enable those skilled in the art to gain a more comprehensive understanding of the present invention, but do not limit the invention in any way. The following content is merely an exemplary description of the scope of protection claimed by the present invention, and those skilled in the art can make various changes and modifications to the present invention based on the disclosed content, and such changes should also fall within the scope of protection claimed by the present invention.

[0026] The present invention will be further described below by way of specific embodiments. Unless otherwise specified, all instruments, devices, equipment, reagents, products, etc., used in the embodiments of the present invention are obtained through conventional commercial means.

[0027] Example 1 like Figure 1 As shown, this embodiment provides a Python-based CAD engineering drawing output system, including a CAD engineering drawing file preprocessing module, an output control information generation module, and a drawing frame information text processing and PDF format conversion module. The CAD engineering drawing file preprocessing module is configured to preprocess all CAD engineering drawing files to be output to meet specific output format requirements, providing a foundation for the normal execution of subsequent processes. The output control information generation module is configured to acquire all information data required for output and write it into a table file to form an output information table file, facilitating parameter support for subsequent processes. The drawing frame information text processing and PDF format conversion module is configured to sequentially read the data rows in the output information table, perform drawing frame information text processing on the CAD engineering drawings to be output, and perform PDF format conversion until all drawings are output. The drawing frame information text processing and PDF format conversion module includes the creation of a PDF drawing file directory, reading output information, acquiring drawing frame elements, setting text layers and text styles, processing drawing frame information, setting printer parameters, and converting CAD engineering drawings to PDF format.

[0028] In the CAD engineering drawing file preprocessing module, the specific output format requirements are as follows: (1) The drawing frame elements are inserted into the layout space of the CAD engineering drawing file in the form of external references and are located on a separate layer to ensure accurate positioning of the drawing area when outputting; (2) In the CAD engineering drawing file used as an external reference, the lower left corner of the rectangular outer drawing frame is located at the origin of the coordinate system to ensure that the insertion point of the drawing frame element coincides with the lower left corner of the rectangular outer drawing frame; (3) All CAD engineering drawing files are stored in the same directory, and the drawing file names are prefixed with serial numbers according to the output order (i.e., the drawing arrangement order) (e.g., 00_, 01_, 02_). (4) When the frame elements of a CAD engineering drawing file are located in multiple layout spaces, the names of the layout spaces are prefixed with serial numbers (such as 00_, 01_, 02_, ...) according to the drawing order, so as to ensure that the order of selecting layout spaces when drawing is consistent with the drawing order; (5) When multiple frame elements are inserted in a single layout space of a CAD engineering drawing file, the external reference insertion points of the frame elements are arranged from left to right according to the drawing order, so as to ensure that the order of selecting frame elements when drawing is consistent with the drawing order.

[0029] like Figure 2 As shown, the drawing control information generation module includes a user input unit, a drawing information table file generation unit, a drawing information generation unit, and a drawing information table editing unit.

[0030] The user input unit is configured to retrieve the directory of the CAD engineering drawing file, the layer name of the drawing frame element in the CAD engineering drawing, the virtual printer name, and the print style name entered by the user. Specifically, the `input()` function is used to retrieve the directory of the CAD engineering drawing file and the layer name of the drawing frame element. The specific steps for retrieving the virtual printer name and print style name entered by the user include: creating a blank CAD file in the CAD software using the `Documents.Add()` method in the `win32com.client` module; retrieving all available virtual printer names and print style names in the CAD software using the `GetPlotDeviceNames()` method in the `win32com.client` module; and retrieving the virtual printer name and print style name selected by the user using the `input()` function.

[0031] The drawing information table file generation unit is configured to use the `read_csv()` function from the pandas library to read the template file, then use the `to_excel()` function to generate a drawing information table file (drawing information table.xlsx) with default header information, and save it to the CAD engineering drawing file directory. The first row of the drawing information table is the header row, and the other rows are data rows. The header row contains header information, including file information header (named "File Directory" and "File Name"), drawing information header (named "Drawing Dimension", "Drawing Frame Layer Name", "Text Layer Name", "Text Style Name", "Text Font Name", and "Text Large Font Name"), print information header (named "Printer Name", "Print Paper Name", "Print Style Name", and "Print Scale"), and drawing frame information header (named "Drawing Name", "Drawing Name Insertion Point", "Drawing Name Text Height"; "Drawing Number", "Drawing Number Insertion Point", "Drawing Number Text Height"; "Date", "Date Insertion Point", and "Date Text Height").

[0032] The data categories in each column of the information table are as follows: File Directory: The directory containing all CAD engineering drawing files. File Name: The filename of the CAD engineering drawing file. Drawing Size: The size of the drawing paper. Drawing Frame Layer Name: The name of the layer containing the drawing frame element of the CAD engineering drawing file. Text Layer Name: The name of the layer containing the drawing frame information text. Text Style Name: The text style name of the drawing frame information text. Text Font Name: The text font name of the drawing frame information text. Large Text Font Name: The large text font name of the drawing frame information text. Printer Name: The name of the virtual printer used for converting CAD engineering drawings to PDF format. Print Style Name: The print style name used for PDF format conversion. Print Paper Name: The paper name in the virtual printer used for PDF format conversion. Print Scale: The print scale used for PDF format conversion. Drawing Name: The drawing name in the drawing frame information. Drawing Name Insertion Point: The coordinates of the drawing name text insertion point in the CAD engineering drawing relative to the lower left corner of the rectangular drawing frame element. Drawing Name Text Height: The text height of the drawing name text in the drawing frame information. Drawing Number: The drawing number in the drawing frame information. Drawing number insertion point: The coordinates of the drawing number text insertion point in a CAD engineering drawing relative to the lower left corner of the rectangular drawing frame element. Drawing number text height: The text height of the drawing number text in the drawing frame information. Date: The drawing date in the drawing frame information. Date insertion point: The coordinates of the date text insertion point in a CAD engineering drawing relative to the lower left corner of the rectangular drawing frame element. Date text height: The text height of the date text in the drawing frame information.

[0033] The file directory and file name in the output information are the file directory and file name of the CAD engineering drawing file corresponding to the drawing frame element. The drawing frame layer name, printer name, and print style name are information entered by the user. The drawing size, text layer name, text style name, text font name, text large font name, print paper name, print scale, and drawing frame text are default data. The default data can be customized by the user.

[0034] The drawing information generation unit is configured to acquire and generate the drawing information for each drawing and write it into the drawing information table.

[0035] The drawing information table editing unit is configured for users to manually edit and save the drawing information data in the drawing information table file according to the drawing target. Users can modify the drawing information in all data rows of the drawing information table according to the drawing target, and can also modify or add title block information headers to meet personalized user needs. However, the header of each type of title block information must be, in order, the text name, the corresponding text insertion point, and the corresponding text height. This invention gathers all drawing information into the drawing information table, and each data row in the table contains all the drawing information for a drawing, facilitating centralized verification of the drawing information by users and improving the efficiency of drawing verification.

[0036] Example 2 This embodiment provides a method for generating CAD engineering drawings based on Python, specifically including the following steps: S1. Preprocess the CAD engineering drawing files, including drawing and inserting drawing frame elements, naming the CAD engineering drawing files, and naming the layout space of the CAD engineering drawing files.

[0037] S2, such as Figure 3 As shown, generate a drawing information table and add drawing information for each CAD engineering drawing; the specific method for generating the drawing information is as follows: S201. Based on the CAD engineering drawing file directory entered by the user, use the listdir() function in the os library to get the names of all files in the directory.

[0038] S202. Using the path.splitext() function in the os library, filter out the names of CAD engineering drawing files with the extension ".dwg" in the directory to form a list of CAD engineering drawing files.

[0039] S203. Determine if the list of CAD engineering drawing files is empty.

[0040] S204. If the list of CAD engineering drawing files is not empty, then iterate through the list of CAD engineering drawing files and obtain the file name of a single CAD engineering drawing file; otherwise, the user re-enters the file directory.

[0041] S205. Use the Documents.Open() method in the win32com.client module to open the CAD engineering drawing file in the CAD software.

[0042] S206. Using the layout.Block property in the win32com.client module, obtain all the graphic elements in the graphic element layer below the user input graphic element layer, and form a list of graphic elements in the graphic element layer.

[0043] S207. Traverse the list of graphic elements in the title block and obtain a single graphic element in the title block.

[0044] S208. Store the obtained file directory, file name, title block layer name, printer name, print style name and other default generated output information into a list to form the output information corresponding to a single title block element. Then, use the concat() function in the pandas library to add a row below the last row of the output information table and store the output information list in the append row in the order of the table header.

[0045] S209. Determine whether the traversal of all elements in the drawing frame element list has been completed.

[0046] S210. If the traversal of all elements in the drawing frame element list has been completed, determine whether the traversal of all elements in the CAD engineering drawing file list has been completed; otherwise, return to step S107 to continue traversing the drawing frame element list.

[0047] S211. If all CAD engineering drawing files have been traversed, use the to_excel() function in the pandas library to save the drawing information table file; otherwise, continue traversing the list of CAD engineering drawing files.

[0048] S3, such as Figure 4 As shown, according to the predetermined drawing output target, the drawing information table is edited and saved; according to the drawing information in the drawing information table, drawing frame information text is added to each CAD engineering drawing, and PDF format is converted; all PDF format converted drawing files are merged to complete the drawing output work, which specifically includes the following steps: S301. Use the mkdir() function in the os library to create a PDF drawing file directory to store all PDF drawing files.

[0049] S302. Use the read_excel() function in the pandas library to read all data rows of the plotting information table file and form a plotting information list. Each element in the list is a row of data from the plotting information table.

[0050] S303. Traverse the drawing information list to obtain the drawing information for a single drawing.

[0051] S304. Obtain file information and drawing information from the drawing information list.

[0052] S305. Use the Documents property in the win32com.client module to get a list of all open files in the CAD software, then iterate through the file list to determine whether the CAD engineering drawing file has been opened in the CAD software.

[0053] S306. If the CAD engineering drawing file is not open, use the Documents.Open() method in the win32com.client module to open the CAD engineering drawing file, and then use the layout.Block property in the win32com.client module to get all the drawing elements located under the drawing frame layer in the file, and store them in the drawing frame element list in the order of drawing output.

[0054] S307. Use the Document.Layers and Document.TextStyles properties in the win32com.client module to obtain a list of all text layer names and text style names in the CAD engineering drawing file, and determine whether the text layers and text styles have been created in the CAD engineering drawing file.

[0055] S308. If the text layer and text style have already been created, use the layout.Block property and Delete() method in the win32com.client module to get and delete all text elements located under the text layer. Otherwise, use the Layers.Add() and TextStyles.Add() methods in the win32com.client module to create the text layer and text style, and use the TextStyle.fontFile and TextStyle.bigFontFile properties to set the text font and text size.

[0056] S309. Retrieve the drawing frame elements corresponding to the drawing information from the drawing frame element list.

[0057] S310. Obtain the drawing frame information from the drawing information list.

[0058] S311. Use the Block.AddText() function in the win32com.client module to generate and insert text primitives according to the coordinates of the insertion point.

[0059] S312. Obtain printing information from the drawing information list.

[0060] S313. Use the ConfigName property in the win32com.client module to obtain the printer object, and use the StyleSheet property, SetCustomScale() method and CanonicalMediaName property to set the print style, print scale and print paper parameters.

[0061] S313. Use the InsertionPoint property in the win32com.client module to obtain the insertion point of the drawing frame element, and use the SetWindowToPlot() method to set the print area according to the insertion point of the drawing frame element and the paper size.

[0062] S314. Use the PlotToFile() method in the win32com.client module to convert the CAD engineering drawings to PDF format and save them to the PDF drawing file directory.

[0063] S315. Determine whether the traversal of all elements in the output information list has been completed.

[0064] S316. If the output information list has been traversed to all elements, use the write() method in the PdfWriter library to merge all PDF drawing files; otherwise, return to step S303 to continue traversing the output information list.

[0065] Compared with traditional technologies, this invention has the following advantages: (1) Digital CAD drafting technology has completely replaced the traditional drawing board drafting method in the engineering design industry, and Python has also attracted a lot of attention in the field of automated office work due to its flexibility and complete library ecosystem. This invention classifies and summarizes all the drawing information of CAD engineering drawings and forms a drawing information table. After the user edits and saves the drawing information table, the drawing frame information text processing and PDF format conversion of the CAD engineering drawings are performed. The formation of the drawing information table and the drawing output operation are completed by using Python technology to control the CAD drawing software, providing a new solution to the drawing output problem of CAD engineering drawings. This not only realizes the batch, automation and integration of drawing frame information processing and PDF format conversion, but also provides convenience for the centralized verification of drawing information, enabling designers to complete the drawing output task of CAD engineering drawings more conveniently and accurately, thereby improving work efficiency and drafting quality.

[0066] (2) This invention allows users to add headers and data to the plot information table, and users can customize the text font and height insertion point coordinates to meet users' personalized needs for plot information text.

[0067] (3) The present invention sets the printing area based on the coordinates of the insertion point of the graphic element in the drawing frame and the size of the drawing. Users can input the corresponding size for each drawing to achieve the goal of printing drawings of any size.

[0068] Finally, it should be noted that the above content is only used to illustrate the technical solution of the present invention, and is not intended to limit the scope of protection of the present invention. Simple modifications or equivalent substitutions made by those skilled in the art to the technical solution of the present invention do not depart from the essence and scope of the technical solution of the present invention.

Claims

1. A Python-based CAD engineering drawing output system, characterized in that, include: The CAD engineering drawing file preprocessing module is configured to preprocess all CAD engineering drawing files to be output by the user in order to meet specific output format requirements. The drawing control information generation module is configured to acquire all the information data required for drawing and write it into a table file to form a drawing information table file; The module for processing title block information text and converting PDF format is configured to sequentially read the data rows in the drawing information table, process the title block information text of the CAD engineering drawings to be drawn, and convert them to PDF format until the drawing work of all drawings is completed.

2. The CAD engineering drawing output system based on Python according to claim 1, characterized in that, The specific output format must meet the following requirements: The graphic elements in the title block are inserted into the layout space of the CAD engineering drawing file as external references and are located on a separate layer; The lower left corner of the rectangular outer frame in the CAD engineering drawing file, which serves as an external reference, is located at the origin of the coordinate system. All CAD engineering drawing files are stored in the same directory, and the drawing file names are prefixed with serial numbers according to the order of drawing output; When the drawing frame elements of a CAD engineering drawing file are located in multiple layout spaces, the names of the layout spaces are prefixed with a serial number according to the drawing order. When multiple title block elements are inserted into a single layout space in a CAD engineering drawing file, the external reference insertion points of the title block elements are arranged from left to right according to the drawing order.

3. The CAD engineering drawing output system based on Python according to claim 1, characterized in that, The drawing control information generation module includes a user input unit, a drawing information table file generation unit, a drawing information generation unit, and a drawing information editing unit; The user input unit is configured to allow users to input the file directory where CAD engineering drawing files are stored, the layer name where the drawing frame elements in the CAD engineering drawing files are located, the virtual printer name, and the print style name; The drawing information table file generation unit is configured to generate a drawing information table file with default header information and save it to the CAD engineering drawing file directory; The drawing information generation unit is configured to acquire and generate the drawing information for each drawing and write it into the drawing information table; The output information table editing unit is configured so that users can edit and save the output information data in the output information table file according to the output target.

4. The CAD engineering drawing output system based on Python according to claim 3, characterized in that, The specific input of the virtual printer name and print style name includes the following steps: Create a blank CAD file in CAD software; Retrieve all virtual printer names and print style names available in the CAD software; Users select and enter the desired virtual printer name and print style name.

5. The CAD engineering drawing output system based on Python according to claim 1, characterized in that, The first row of the drawing information table is the header row, and the other rows are data rows. The header row includes the file information header, the drawing information header, the printing information header, and the drawing frame information header.

6. The CAD engineering drawing output system based on Python according to claim 1, characterized in that, Users can modify the plotting information in all data rows of the plotting information table according to the plotting target, or modify or add plotting information headers to meet their personalized needs.

7. The CAD engineering drawing output system based on Python according to claim 1, characterized in that, The module for text processing and PDF conversion of drawing frame information includes the creation of a PDF drawing file directory, reading of drawing information, acquisition of drawing frame elements, setting of text layers and text styles, processing of drawing frame information, setting of printer parameters, and conversion of CAD engineering drawings to PDF format.

8. A method for generating CAD engineering drawings based on Python, characterized in that, The process of using a Python-based CAD engineering drawing output system according to any one of claims 1-7 includes the following steps: S1. Preprocess the CAD engineering drawing files, including drawing and inserting drawing frame elements, naming the CAD engineering drawing files, and naming the layout space of the CAD engineering drawing files; S2. Generate the output information table and add the output information for each CAD engineering drawing; S3. Edit and save the drawing information table according to the predetermined drawing output target; add drawing frame information text to each CAD engineering drawing according to the drawing information in the drawing information table, and convert it to PDF format; merge all the drawing files after PDF format conversion to complete the drawing output work.

9. A method for generating CAD engineering drawings based on Python according to claim 8, characterized in that, In step S2, the specific method for generating the output plot information is as follows: S201. Based on the CAD engineering drawing file directory entered by the user, use the listdir() function in the os library to get all file names in the directory; S202. Use the path.splitext() function in the os library to filter out the names of CAD engineering drawing files in the directory and form a list of CAD engineering drawing files; S203. Determine if the CAD engineering drawing file list is empty; S204. If the list of CAD engineering drawing files is not empty, then traverse the list of CAD engineering drawing files and obtain the file name of a single CAD engineering drawing file; otherwise, the user re-enters the file directory. S205. Use the Documents.Open() method in the win32com.client module to open the CAD engineering drawing file in the CAD software; S206. Using the layout.Block property in the win32com.client module, obtain all the frame elements located under the user-input frame element layer and form a frame element list. S207. Traverse the list of graphic elements in the title block and obtain a single graphic element in the title block; S208. Store the obtained file directory, file name, title block layer name, printer name, print style name and other default generated output information into a list to form the output information corresponding to a single title block element. Then, use the concat() function in the pandas library to add a row below the last row of the output information table and store the output information list in the append row according to the order of the table header. S209. Determine whether the traversal of all elements in the drawing frame element list has been completed; S210. If the drawing frame element list has completed the traversal of all elements, determine whether the traversal of all elements in the CAD engineering drawing file list has been completed; otherwise, return to step S107 to continue traversing the drawing frame element list. S211. If all CAD engineering drawing files have been traversed, use the to_excel() function in the pandas library to save the drawing information table file; otherwise, continue traversing the list of CAD engineering drawing files.

10. A method for generating CAD engineering drawings based on Python according to claim 8, characterized in that, S3 specifically includes the following steps: S301. Use the mkdir() function in the os library to create a PDF drawing file directory to store all PDF drawing files; S302. Use the read_excel() function in the pandas library to read all data rows of the plot information table file and form a plot information list. Each element in the list is a row of data from the plot information table. S303. Traverse the drawing information list to obtain the drawing information for a single drawing; S304. Obtain file information and drawing information from the drawing information list; S305. Use the Documents property in the win32com.client module to get a list of all open files in the CAD software, and then iterate through the file list to determine whether the CAD engineering drawing file has been opened in the CAD software. S306. If the CAD engineering drawing file is not open, use the Documents.Open() method in the win32com.client module to open the CAD engineering drawing file, and then use the layout.Block property in the win32com.client module to get all the drawing elements located under the drawing frame layer in the file, and store them in the drawing frame element list in the order of drawing output. S307. Use the Document.Layers and Document.TextStyles properties in the win32com.client module to obtain a list of all text layer names and text style names in the CAD engineering drawing file, and determine whether the text layers and text styles have been created in the CAD engineering drawing file. S308. If the text layer and text style have already been created, use the layout.Block property and Delete() method in the win32com.client module to get and delete all text elements located under the text layer; otherwise, use the Layers.Add() method and TextStyles.Add() method in the win32com.client module to create the text layer and text style, and use the TextStyle.fontFile property and TextStyle.bigFontFile property to set the text font and text size. S309. Retrieve the drawing frame elements corresponding to the output information from the drawing frame element list; S310. Obtain the title frame information from the drawing information list; S311. Use the Block.AddText() function in the win32com.client module to generate and insert text primitives according to the coordinates of the insertion point; S312. Obtain printing information from the drawing information list; S313. Use the ConfigName property in the win32com.client module to obtain the printer object, and use the StyleSheet property, SetCustomScale() method and CanonicalMediaName property to set the print style, print scale and print paper parameters. S313. Use the InsertionPoint property in the win32com.client module to get the insertion point of the drawing frame element, and use the SetWindowToPlot() method to set the print area according to the insertion point of the drawing frame element and the paper size. S314. Use the PlotToFile() method in the win32com.client module to convert the CAD engineering drawings to PDF format and save them to the PDF drawing file directory. S315. Determine whether the traversal of all elements in the output information list has been completed; S316. If the output information list has been traversed to all elements, use the write() method in the PdfWriter library to merge all PDF drawing files; otherwise, return to step S303 to continue traversing the output information list.