A CAD text style font batch replacement method, system and storage medium

By adaptively recognizing and batch updating CAD text styles and fonts, the problem of cumbersome operation and poor compatibility in existing technologies has been solved, achieving efficient and reliable text style and font replacement, which is suitable for unattended processing in single-document and multi-document scenarios.

CN122113841AActive Publication Date: 2026-05-29HUNAN PROVINCIAL COMM PLANNING SURVEY & DESIGN INST CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HUNAN PROVINCIAL COMM PLANNING SURVEY & DESIGN INST CO LTD
Filing Date
2026-04-28
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

In CAD graphic design, existing technologies for replacing text styles and fonts are cumbersome and inefficient. In multi-document scenarios, manual intervention is required, which can easily lead to omissions, errors, poor compatibility, and an inability to accurately identify SHX fonts and Windows fonts, resulting in replacement deviations and display anomalies.

Method used

An adaptive font recognition mode is adopted. By obtaining the text style list, the normal font field and the large font field are identified, the target font parameters are obtained and the extension is processed, the font field is updated in batches, and the entmod and entupd functions are used to force the update. Combined with the graphics refresh, a two-level priority mechanism of ObjectDBX priority and normal opening degradation is adopted to achieve unattended batch processing.

Benefits of technology

It enables precise batch replacement of CAD text styles and fonts, improves compatibility and reliability, reduces operational complexity, adapts to different CAD versions, and supports unattended processing in single-document and multi-document scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122113841A_ABST
    Figure CN122113841A_ABST
Patent Text Reader

Abstract

The application provides a CAD character style font batch replacement method, system and storage medium, which comprises the following steps: obtaining a character style list of a CAD graph file; identifying font modes of each character style according to a normal font field and a large font field in each character style; obtaining target font parameters input by a user and performing automatic extension name processing on the target font parameters; batch updating the normal font field and the large font field of each character style according to the processed target font parameters and the font mode identification result; and when switching from an SHX large font mode to an SHX normal mode or a Windows font mode, explicitly setting the large font field as an empty string. The application solves the problem that some CAD versions follow old large font parameters due to the absence of DXF group code 4, resulting in abnormal font display; and at the same time, through a font type adaptive identification mechanism, the replacement deviation caused by font type confusion is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer-aided design technology, specifically to a method, system, and storage medium for batch replacement of CAD text styles and fonts, applicable to batch replacement of CAD text styles and fonts in single-document and multi-document scenarios. Background Technology

[0002] In the process of CAD graphic design, editing and standardization, the font settings of text styles directly affect the display standardization, readability and cross-version compatibility of graphics. When it is necessary to uniformly adjust the text style font in one or more CAD graphics, the existing technology has many shortcomings.

[0003] In existing technologies, CAD text style font replacement mostly relies on manual modification of text styles one by one. This process is cumbersome and inefficient, especially when dealing with multiple documents and styles, resulting in extremely high labor costs and a high risk of omissions and errors. Some existing batch replacement methods still have significant technical flaws: First, they cannot accurately identify SHX fonts and Windows fonts, easily leading to font type confusion and replacement errors; second, during the replacement process, large font fields (corresponding to DXF group code 4) are often deleted, and some CAD versions, due to the absence of this group code, will retain the old large font parameters, causing abnormal font display and poor compatibility; third, batch processing of multiple documents requires manual intervention, making unattended operation impossible, and the process is prone to interruption due to file opening failures, missing parameters, etc.; fourth, inputting target font parameters is cumbersome, easily leading to replacement failures due to incorrect extensions or missing parameters, resulting in insufficient reliability.

[0004] Therefore, there is an urgent need for a method, system, and storage medium for batch replacement of CAD text styles and fonts that can achieve accurate batch replacement, improve compatibility and reliability, and reduce operational complexity, in order to overcome the shortcomings of existing technologies. Summary of the Invention

[0005] The purpose of this invention is to provide a method for batch replacement of CAD text styles and fonts, aiming to solve the technical problems of low replacement efficiency, poor compatibility, the need for manual intervention for multiple documents, and the susceptibility to display anomalies in existing technologies. The specific technical solution is as follows: A method for batch replacement of font styles in CAD text, including: Retrieve the list of text styles from the CAD drawing file, where the text styles include a regular font field and a large font field; Based on the normal font field and large font field in each text style, identify the font mode of each text style; Obtain the target font parameters input by the user and automatically process the file extension of the target font parameters; Based on the processed target font parameters and font pattern recognition results, batch update the ordinary font field and large font field for each text style; Specifically, when switching from SHX large font mode to SHX normal mode or Windows font mode, the large font field is explicitly set to an empty string.

[0006] Preferably, the text style list in the CAD drawing file is obtained, specifically: Get the style name string input by the user, and parse the style name string to get a list of text styles; If the user does not enter a style name string, the system will automatically iterate through all text styles in the current CAD drawing file and generate a list of text styles.

[0007] Preferably, the font pattern of each text style is identified based on the "normal font" and "large font" fields in each text style. Specifically: Iterate through the list of text styles and check the normal font field of each text style. If the normal font field contains the .shx suffix, then check the large font field. If the large font field is not empty, the text style is determined to be in SHX large font mode. If the large font field is empty, the text style is determined to be in SHX normal mode. If the normal font field does not contain the .shx suffix, the text style is determined to be in Windows font mode.

[0008] Preferably, the target font parameters input by the user are obtained, and the file extension of the target font parameters is automatically processed, specifically: The user is prompted to enter the target font type, which can be an SHX font or a Windows font. If the target font type is an SHX font, the user will be further prompted to enter the target font mode and the target font name. The target font mode is either SHX normal mode or SHX large font mode. If the target font type is a Windows font, then only prompt the user to enter the target font name; Automatically handle the file extension of the target font name based on the target font type.

[0009] Preferably, the regular font field and large font field for each text style are updated, specifically: Iterate through the list of text styles, combine the font pattern recognition results corresponding to each text style with the target font parameters, and update the ordinary font field of each text style one by one; according to the target font parameters, update the large font field synchronously or explicitly set the large font field to an empty string; During the update process, the corresponding fields in the text style symbol table are modified using the entmod function, and the entupd function is called to force an update of the object; after all text styles are updated, a graphic refresh operation is performed.

[0010] Preferably, when switching to SHX large font mode: check if the large font field of the text style exists; if it does not exist, add it and assign it the default or user-input large font name; if it already exists, replace its value; set the large font field through the vla-put-bigfontfile function and update the normal font field through VLA object methods; When switching to SHX normal mode: the vla-put-fontfile function is used to modify the normal font field to the font name with the .shx extension, and the large font field is explicitly set to an empty string through symbol table operations; When switching to Windows font mode: The vla-SetFont function modifies the normal font field to the Windows font name and removes the .shx suffix. The vla-put-bigfontfile function is wrapped with the vl-catch-all-apply function to pass an empty string to the big font field in an attempt to clear it. At the same time, the big font field is explicitly set to an empty string through symbol table operations.

[0011] Preferably, when there are two or more CAD drawing files to be processed: Prioritize opening CAD drawing files in ObjectDBX mode for text style replacement; If the ObjectDBX method fails to open the file, save the original values ​​of the current system variables cmddia and expert, set cmddia=0 and expert=5, open the CAD drawing file in vla-open mode to replace the text style, and restore the original values ​​of cmddia and expert after the replacement is successful. If both of the above methods fail to open the file, mark the CAD drawing file as failed and continue processing the next CAD drawing file.

[0012] This invention also provides a CAD text style font batch replacement system, which employs the aforementioned CAD text style font batch replacement method. The system includes: The mode selection module provides users with single-document processing mode and multi-document processing mode to choose from. It receives the user's mode selection command and jumps to the corresponding processing flow. The file and style acquisition module, in single-document processing mode, acquires the text style list of the currently opened single CAD drawing file; in multi-document processing mode, it acquires the list of CAD drawing files in the target folder specified by the user, and acquires the text style list of each CAD drawing file one by one. The font recognition module iterates through each text style in the text style list and identifies the font pattern of the text style; The parameter input and processing module receives the target font parameters input by the user and automatically processes the file extension of the target font parameters; The font replacement module replaces each text style in the text style list according to the target font parameters in single document processing mode; in multi-document processing mode, it opens each CAD drawing file in the CAD drawing file list one by one according to the preset priority opening method, and replaces the text styles in the text style list according to the target font parameters. The result output module receives the processing results from the font replacement module and displays the results.

[0013] The present invention also provides a CAD text style font batch replacement system, including a memory and a processor. The memory stores a computer program, and the processor executes the CAD text style font batch replacement method when running the computer program.

[0014] The present invention also provides a storage medium storing a computer program, which, when run, executes the CAD text style font batch replacement method.

[0015] The application of the technical solution of the present invention has the following beneficial effects: This invention employs a technical design that explicitly sets the large font field to an empty string instead of deleting it. This solves the problem of some CAD versions using the old large font parameters due to the missing DXF group code 4, resulting in abnormal font display. It adapts to different versions of CAD software, expanding the applicability of the technical solution. At the same time, through a font type adaptive recognition mechanism, it avoids replacement deviations caused by font type confusion, further improving compatibility.

[0016] This invention eliminates the need for manual modification of text styles one by one, enabling batch replacement of single and multiple documents. The multi-document mode employs a two-tier priority mechanism of ObjectDBX priority and normal opening degradation, combined with system variable adjustment to suppress pop-ups, achieving fully unattended batch processing, significantly reducing manual intervention costs, improving processing efficiency, and adapting to large-scale CAD graphic file optimization scenarios. The single-document mode supports precise selection of target styles, avoiding invalid operations and further improving the targeting of processing.

[0017] This invention avoids replacement failures caused by incorrect or missing parameters by intelligently processing target font parameters (i.e., automatic addition / removal of extensions and automatic invocation of default large font names); it modifies the corresponding fields in the text style symbol table by calling the entmod function and forces an update of the object display by calling the entupd function, combined with real-time graphic refresh, ensuring that the replacement effect can be verified immediately; the failure recording and log generation functions in multi-document mode enable traceability of the processing process and troubleshooting of anomalies, improving the reliability of batch processing.

[0018] This invention simplifies the user operation process, supports users to accurately filter the target text styles that need to be replaced, and intelligently processes the target font parameters, eliminating the need for users to remember complex parameter rules; it offers flexible mode switching to adapt to different scenarios such as single documents and multiple documents; and its optional review and verification design balances operational accuracy and flexibility, lowers the user's operating threshold, and is suitable for users of different professional levels.

[0019] In addition to the objectives, features, and advantages described above, the present invention has other objectives, features, and advantages. The invention will now be described in further detail with reference to the figures. Attached Figure Description

[0020] The accompanying drawings, which form part of this application, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an undue limitation of the invention. In the drawings: Figure 1 This is a flowchart of the method for batch replacement of CAD text styles and fonts in the case of single document processing in Example 1; Figure 2 This is a flowchart of the method for batch replacement of CAD text styles and fonts in the case of multi-document processing in Example 6. Detailed Implementation

[0021] To facilitate understanding of the present invention, a more complete description is provided below, along with preferred embodiments. However, the present invention can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided to provide a thorough and complete understanding of the disclosure of the present invention.

[0022] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.

[0023] Example 1: See Figure 1This embodiment focuses on a single-document processing scenario and specifically describes the implementation process of a method for batch replacing CAD text styles and fonts. The specific steps are as follows: Retrieve the list of text styles from the CAD drawing file, where the text styles include a regular font field and a large font field; Based on the normal font field and large font field in each text style, identify the font mode of each text style; Obtain the target font parameters input by the user and automatically process the file extension of the target font parameters; Based on the processed target font parameters and font pattern recognition results, batch update the ordinary font field and large font field for each text style; Specifically, when switching from SHX large font mode to SHX normal mode or Windows font mode, the large font field is explicitly set to an empty string.

[0024] To facilitate subsequent understanding, this embodiment will first explain some of the terms involved: Group Code 3: The ordinary font file name field in the DXF group code stores the ordinary font name (i.e., the ordinary font field); for SHX fonts, it stores the font name, such as txt.shx; for Windows fonts, it stores the font name, such as: Fangsong; where .shx represents the extension.

[0025] Group Code 4: The large font file name field (i.e., the large font field) in the DXF group code is only used in SHX large font mode and stores large font file names such as fsdb.shx.

[0026] SHX Normal Mode: Group code 3 is xxx.shx, and group code 4 is empty text style mode.

[0027] SHX Large Font Mode: Group code 3 is xxx.shx, and group code 4 is yyy.shx.

[0028] Windows font mode (i.e. Windows TrueType mode): Group 3 is the font name (without extension), and Group 4 is an empty text style mode.

[0029] ObjectDBX: AutoCAD's backend database access technology, which allows reading and writing DWG files without opening the graphical interface.

[0030] vla-put-bigfontfile: This function sets the large font field (SHX large font) in the text style.

[0031] vla-put-fontfile: This function sets the normal font field in the text style to an SHX font.

[0032] vla-SetFont: This function sets the normal font field in the text style to a Windows font.

[0033] vl-catch-all-apply: In Visual Lisp, this means to safely execute a function, catching exceptions without interrupting the program.

[0034] entmod: Represents the AutoLISP primitive operation function, which modifies the DXF group code data of primitives and writes it back to the graphics database.

[0035] entupd: Represents the AutoLISP primitive operation function, which displays the content modified by entmod.

[0036] regenall: This is an AutoCAD command that regenerates all viewport drawings.

[0037] redrawall: This AutoCAD command redraws all viewports (refreshes the display).

[0038] vla-open: This refers to a method of programmatically opening a DWG drawing file in an application (such as VisualLISP, VBA, etc.) through the ActiveX automation interface provided by AutoCAD.

[0039] Preferably, the text style list in the CAD drawing file is obtained, specifically: Get the style name string input by the user (supports multiple name inputs separated by commas and semicolons), parse the style name string, extract the individual text style names contained therein, and form a list of text styles; If the user does not enter any style name string, the system will automatically iterate through all text styles in the current CAD drawing file, read the core parameters of each text style one by one, and the core parameters include at least the text style name, the normal font field, and the large font field, and generate a text style list containing all editable text styles.

[0040] The method of obtaining the text style list in this embodiment can flexibly define the scope of font replacement. It supports users to accurately select target replacement styles and avoid invalid operations on styles that do not need to be replaced. It also supports full coverage of all editable styles, meeting the core needs of users to make batch and unified modifications, and effectively improving the targeting and processing efficiency of replacement operations.

[0041] Furthermore, this embodiment can use the VLA programming interface to call the corresponding function to obtain the text style set of the currently opened CAD drawing file, traverse the set and extract the core parameters of each text style, generate a text style list and complete temporary storage, laying the data foundation for subsequent font recognition, parameter replacement and other steps, ensuring the accuracy and completeness of field acquisition, avoiding abnormalities in the subsequent replacement process due to missing fields or acquisition errors, and providing reliable data support for the entire replacement process.

[0042] Optionally, the generated list of text styles can be displayed in the CAD command line as a checklist for user review. If the user finds an error in the list, they can actively terminate the current operation and restart the process. This design can reduce the probability of replacement failure due to errors in the style list, ensuring that subsequent replacement operations are strictly executed according to the user's expectations, balancing operational accuracy and flexibility.

[0043] Preferably, the font pattern of each text style is identified based on the "normal font" and "large font" fields in each text style. Specifically: Iterate through the list of text styles and check the normal font field of each text style. If the normal font field contains the .shx suffix, then check the large font field. If the large font field is not empty, the text style is determined to be in SHX large font mode. If the large font field is empty, the text style is determined to be in SHX normal mode. If the normal font field does not contain the .shx suffix, the text style is determined to be in Windows font mode.

[0044] This operation enables adaptive and accurate recognition of font patterns, effectively solving technical problems such as font pattern confusion and incomplete recognition in existing technologies. It provides accurate judgment basis for subsequent replacement operations, ensuring the consistency and rigor of the entire replacement logic.

[0045] After font pattern recognition is completed, the recognition results are stored synchronously to provide data support for subsequent steps. Optionally, the recognition results can be categorized by text style name and displayed in the command line in the form of a list for users to review and verify, further reducing recognition errors and avoiding problems such as subsequent parameter processing errors and fonts not displaying correctly after replacement due to font pattern recognition errors, thus significantly improving the success rate of replacement operations.

[0046] Preferably, the target font parameters input by the user are obtained, and the file extension of the target font parameters is automatically processed, specifically: The user is prompted to enter the target font type, which can be an SHX font or a Windows font. If the target font type is an SHX font, the user will be further prompted to enter the target font mode and the target font name. The target font mode is either SHX normal mode or SHX large font mode. If the target font type is a Windows font (i.e., the target font mode is Windows font mode), then only prompt the user to enter the target font name; Automatically handle the file extension of the target font name based on the target font type.

[0047] Specifically, the system automatically processes the extension of the target font name based on the target font type selected by the user: if the target font type is an SHX font, the .shx suffix is ​​automatically added; if the target font type is a Windows font, any existing .shx suffix is ​​automatically removed, ensuring that the target font can be correctly recognized by the CAD software, avoiding problems such as replacement failure and abnormal font display caused by incorrect extensions, and improving the success rate and stability of replacement.

[0048] Furthermore, if the user selects the SHX large font mode but does not enter a large font name, the system automatically calls the preset default large font name. Preferably, in this embodiment, the preset default large font name is fsdb.shx. This eliminates the need for additional user operations, improves ease of operation, and avoids program interruption due to user omissions in input. The effect is to reduce user operation steps, avoid process interruption due to missing parameters, improve operational smoothness, and ensure the integrity of the SHX large font mode replacement without requiring the user to memorize or query default parameters.

[0049] The processed target font parameters are automatically synchronized and stored. Optionally, they can be displayed in the command line as a list for users to review and verify. If users find any errors in the parameters, they can actively return to the parameter input stage to re-enter them. This parameter processing flow can reduce the complexity of user operations, avoid input errors caused by users' unfamiliarity with font parameter rules, ensure the accuracy of target font parameters, and provide reliable support for subsequent batch replacement operations.

[0050] Preferably, the "normal font" and "large font" fields for each text style are updated in batches, specifically: The obtained list of text styles is traversed. For each text style, the corresponding ordinary font field is updated one by one, combining its font pattern recognition result and target font parameters. If the target font mode (i.e., the target font parameter) is SHX large font mode, the large font field is updated synchronously to the large font name entered by the user or the system default. If the target font mode is SHX normal mode or Windows font mode, explicitly set the large font field to an empty string instead of deleting the field to avoid some CAD versions using the old large font parameters due to missing group codes, which would cause abnormal font display.

[0051] Furthermore, when switching to SHX large font mode (regardless of whether the current mode is SHX normal or Windows font mode): the system automatically checks whether the large font field of the text style, i.e., the corresponding DXF group code 4, exists; if it does not exist, the large font field is added and assigned the value of a preset default large font name or a large font name entered by the user; if it already exists, the value of the large font field is replaced; at the same time, the large font parameters are set synchronously through the vla-put-bigfontfile function in the VLA object method, and the normal font attributes are updated through the VLA object method (the vla-put-fontfile function is used to update the normal font attributes when the current mode is SHX normal, and the vla-SetFont function is used to update the normal font attributes when the current mode is Windows font), thus achieving dual-path synchronization between symbol table operations and VLA methods, ensuring that the object and the symbol table are consistent.

[0052] Furthermore, when switching to SHX normal mode (regardless of whether the current mode is SHX large font mode or Windows font mode): First, a new normal SHX font is set using the vla-put-fontfile function in the VLA object method. Then, the group code 4 of the text style is explicitly set to an empty string only through symbol table operations, without calling the vla-put-bigfontfile function (to avoid errors caused by passing an empty string in some AutoCAD versions). At the same time, group code 3 is modified to the SHX font name with the .shx extension, thus clearing the large font definition and avoiding compatibility issues caused by missing group codes or VLA anomalies.

[0053] Furthermore, when switching to Windows font mode (regardless of whether the current mode is SHX normal mode or SHX large font mode): the Windows font is set through the vla-SetFont function in the VLA object method, and the empty string of the vla-put-bigfontfile function is wrapped with the error-catching function vl-catch-all-apply to try to clear the large font attribute (the program will not be interrupted even if it fails). At the same time, group code 4 is explicitly set to an empty string through symbol table operations, forming a double insurance mechanism. Finally, group code 3 is modified to the Windows font name (automatically removing any .shx suffix that may have been mistakenly added), ensuring that the symbol table and the VLA object are ultimately consistent.

[0054] During the update process, the corresponding fields in the text style symbol table are modified using the entmod function, and the entupd function is called to force an update of the object to ensure that the field updates take effect. After all text styles are updated, the regenall and redrawall commands are executed to refresh the graphics and ensure that the replacement effect is displayed in real time.

[0055] During the update process, for text styles not found in the text style list, the system automatically records the skipped information, ensuring the overall replacement process is not interrupted and the stability of the operation is guaranteed. After the replacement is completed, the system counts the number of successfully modified text styles and the number of missing text styles, displaying the list in the command line to indicate to the user that the replacement operation is complete, facilitating user tracking of the replacement status. This design ensures the continuity of the replacement process, preventing the entire operation from being interrupted due to the absence of individual styles, while also allowing users to clearly understand the replacement results, facilitating subsequent verification and supplementary operations.

[0056] Specifically, this step involves replacing text styles based on the correspondence between the text style list and the target font parameters (i.e., the replacement requirements). For example, if the title text style in the text style list is identified as SHX normal mode, and the target font parameters are set to set the title text style to Windows font mode, then this step will update and replace the title text style from SHX normal mode to Windows font mode.

[0057] This step enables batch and precise updates of text style font parameters, solves the compatibility problem of mode switching between different CAD versions, ensures that the replacement operation is effective and visible in real time, significantly improves the success rate and efficiency of replacement, and ensures that the replaced font can be displayed normally in different CAD versions, thus expanding the scope of application.

[0058] This embodiment of the CAD text style font batch replacement method strictly follows the core process of obtaining a text style list—identifying font patterns—obtaining target font parameters—batch updating fields. Through the design of the technical solution itself, it achieves accurate and efficient batch font replacement in a single-document scenario. The core technical effects are as follows: First, by flexibly obtaining a text style list, adaptively identifying font patterns, and intelligently processing target font parameters, it effectively avoids technical problems such as font type confusion, parameter input errors, and ineffective replacement in existing technologies, ensuring the continuity and accuracy of the replacement process; Second, by explicitly setting the large font field to an empty string instead of deleting it, it effectively solves the problem of missing group code 4 (large font field) in some CAD versions. This addresses the technical pain point of using outdated large font parameters, which leads to abnormal font display, and improves compatibility with different CAD versions. Thirdly, it ensures parameter updates take effect by calling the entmod and entupd functions, and refreshes the drawing in real time using the regenall and redrawall commands, guaranteeing immediate verification of the replacement effect. Fourthly, it eliminates the need for users to manually modify text styles one by one, significantly reducing operational complexity and improving replacement efficiency. Simultaneously, the optional design review and verification feature balances operational accuracy and flexibility, ensuring the consistency of text style and font replacement within a single document. This meets users' core need for batch optimization of text styles in single documents, technically solving the problems of low efficiency, poor compatibility, and error-proneness in existing single-document font replacement.

[0059] Example 2: This embodiment uses the method of Embodiment 1 to modify all styles in a single document to Windows fonts, as detailed below: Initial state: The current CAD drawing file contains 15 text styles, including annotations, titles, annotations, table headers, and table titles. Some of these are in SHX normal mode, and some are in large font SHX mode.

[0060] User actions: 1. Enter the start command in the CAD software command line to start the CAD text style font batch replacement program; 2. The program prompts the user to enter the name of the text style to be replaced. The user presses Enter directly (without entering any style name), triggering the full style replacement command; 3. The program automatically traverses the current CAD drawing file, extracts the names of all 15 text styles, and displays them in the command line. The user confirms after verifying that everything is correct. 4. The program prompts the user to select the target font type. The user selects 2 - Windows font (i.e., Windows font mode). 5. The user enters the target Windows font name as "Fangsong". After confirming that the input parameters are correct, the preliminary operation is completed.

[0061] Program execution process: The first layer (recognition layer): The program first reads the DXF group code 3 (ordinary font field) and group code 4 (large font field) of the first text style (i.e., comment), identifies the style as SHX ordinary mode through suffix verification, and displays the font name: txt.shx (SHX font) on the command line. Subsequently, it completes the font mode recognition of all 15 styles in sequence. The second layer (judgment layer): Based on the target font type (Windows font) selected by the user, the program automatically determines that the target state is Windows font mode and clearly indicates that all styles need to be uniformly converted to this mode; The third layer (control layer): The program executes batch replacement operations according to the collaborative logic, as follows: 1. Iterate through the 15 text styles in the current CAD drawing file, and call the vla-SetFont function for each style to set the font to SimSun uniformly; 2. Simultaneously modify the DXF group code 3 of the corresponding style in the text style symbol table, update it to SimSun, and ensure that the parameters are consistent with the actual font settings; 3. For the original SHX large font mode style, its DXF group code 4 (large font field) is explicitly set to an empty string instead of being directly deleted, to avoid display abnormalities caused by some CAD versions using old parameters due to missing group codes; 4. Call the entmod function to write the updated parameters into the text style symbol table, and simultaneously call the entupd function to force an update of the text style object to ensure that all parameter modifications take effect; 5. Execute the regenall and redrawall commands to refresh all viewports of the drawing so that the replacement effect is displayed in real time; 6. After the replacement is complete, the program counts that 15 styles have been successfully modified and pops up a message box to indicate: Text style replacement complete! 15 styles successfully modified.

[0062] Experimental Results: All 15 text styles in the current CAD drawing file were uniformly replaced with the Windows font Fangsong. Users no longer need to enter the style name individually, achieving one-click full modification of text styles and significantly improving operational efficiency. The collaborative mechanism of the recognition layer, judgment layer, and control layer ensures the accuracy of the Windows font settings. At the same time, by explicitly setting group code 4 to an empty string, compatibility issues between different CAD versions are effectively avoided, ensuring that all text styles display correctly after replacement, without garbled characters or parameter residue.

[0063] Example 3: This embodiment uses the method of Embodiment 1 to switch the text style in the SHX normal mode of a single document to the SHX large font mode, as follows: Initial state: The text style title is SHX normal mode, group code 3 = simplex.shx, group code 4 = empty; User operation: The user selects SHX large font mode and enters the normal font fsdb_e.shx or the large font fsdb.shx; Program execution process: First layer (recognition layer): The program reads the DXF group code 3 and group code 4 of the title text style, identifies the style as an SHX font through suffix verification, and clarifies that the current style mode is SHX normal mode.

[0064] The second layer (judgment layer): Based on the user's selected SHX large font mode and the input target font parameters, the program automatically determines that the target state is SHX large font mode, and clearly indicates that both normal font and large font need to be set simultaneously, and that the group code 4 parameters need to be completed.

[0065] The third layer (control layer): The program executes the switching operation according to the coordination logic, as follows: 1. Call the vla-put-fontfile function to set the normal font of the title text style to fsdb_e.shx; 2. Call the vla-put-bigfontfile function to set the large font of the title text style to fsdb.shx; 3. Simultaneously modify the DXF group code 3 of the title text style in the text style symbol table, update it to fsdb_e.shx, and ensure that the parameters are consistent with the actual settings; 4. The program detects that the DXF group code 4 for the title text style is missing, automatically adds group code 4 and sets its value to fsdb.shx to avoid the large font setting being invalid due to the missing group code; 5. Call the entmod function to write the updated parameters into the text style symbol table, and simultaneously call the entupd function to force an update of the text style object to ensure that all parameter modifications take effect; 6. Execute the regenall and redrawall commands to refresh all viewports of the drawing so that the replacement effect is displayed in real time; 7. Processing result: The text style of the title was successfully switched to SHX large font mode, with DXF group code 3=fsdb_e.shx and DXF group code 4=fsdb.shx. The large font setting is working normally.

[0066] The three-layer collaborative mechanism (i.e., recognition layer, judgment layer, and control layer) in this embodiment ensures a complete closed loop from font pattern recognition and target pattern judgment to specific operation control. It effectively solves the technical defect of existing tools ignoring group code 4 when switching to large font mode, which leads to the invalidation of large font settings, and ensures the accuracy and effectiveness of mode switching.

[0067] Example 4: This embodiment uses the method of Embodiment 1 to switch the text style in a single document from SHX large font mode to SHX normal mode, as follows: Initial state: The title text style is SHX large font mode, group code 3=fsdb_e.shx, group code 4=fsdb.shx; User operation: The user selects SHX normal mode and enters the target normal font name simplex.shx.

[0068] Program execution process: First layer (recognition layer): The program reads the DXF group code 3 and group code 4 of the title text style, and identifies the style as an SHX font through suffix verification, thus confirming that the current style mode is the large font SHX mode.

[0069] The second layer (judgment layer): Based on the user's selection of SHX normal mode and the input target font parameters, the program automatically determines that the target state is SHX normal mode, clearly states that a normal font needs to be set and the large font needs to be cleared, and that group code 4 needs to be avoided.

[0070] The third layer (control layer): The program executes the switching operation according to the coordination logic, as follows: 1. Call the vla-put-fontfile function to set the font of the title text style to simplex.shx; 2. Do not call vla-put-bigfontfile (to avoid empty string parameter errors), clear the large font only through symbol table operations; 3. Simultaneously modify the DXF group code 3 of the title text style in the text style symbol table, update it to simplex.shx, and ensure that the parameters are consistent with the actual settings; 4. Instead of deleting the DXF group code 4 (large font field), explicitly set it to an empty string to avoid the risk of missing group code; 5. Call the entmod function to write the updated parameters into the text style symbol table, and simultaneously call the entupd function to force an update of the text style object to ensure that all parameter modifications take effect; 6. Execute the regenall and redrawall commands to refresh all viewports of the drawing so that the replacement effect is displayed in real time; 7. Processing results: The title text style was successfully switched to SHX normal mode, DXF group code 4 was explicitly cleared, there were no missing group codes, and the file was displayed normally in different CAD versions after being saved and reopened, with good compatibility and no VLA error was triggered.

[0071] This embodiment adopts a design that explicitly sets DXF group code 4 (large font field) to an empty string instead of deleting it, and does not call vla-put-bigfontfile to avoid empty string parameter errors. It only completes the clearing independently through symbol table operations, which effectively avoids the display abnormality problem caused by some CAD versions using old parameters due to missing group codes. At the same time, it avoids automation errors that may be caused by VLA clearing and solves the compatibility defects of the prior art.

[0072] Example 5: This embodiment uses the method of Embodiment 1 to perform adaptive font type recognition and verification in a single document, as detailed below: Scenario 1 (Windows font recognition and processing): The current text style is SHX normal mode (group code 3=txt.shx, group code 4=empty), and the program displays the font name as: txt.shx; The user selects a Windows font and enters FangSong.shx (the extension is added by mistake); Finally, the program automatically removes the.shx suffix and correctly sets it to FangSong.

[0073] Scenario 2 (SHX font recognition and processing): The current text style is in Windows font mode (group code 3 = FangSong, group code 4 = empty), and the program displays the font name: FangSong; The user selects an SHX font and enters fsdb_e (the extension is not added); Finally, the program automatically adds the.shx suffix and correctly sets it to fsdb_e.shx.

[0074] The verification through this embodiment shows that users do not need to memorize the font naming rules, and the program can automatically process the extensions, avoiding setting failures caused by incorrect input formats, which reflects the core advantage of adaptive font type recognition.

[0075] Embodiment 6: Refer to Figure 2 , this embodiment provides a method for batch replacing CAD text style fonts in a multi-document batch processing scenario. The difference between the method of this embodiment and that of Embodiment 1 is that it adds a two-layer priority mechanism of ObjectDBX priority and normal open downgrade in the multi-document scenario, and the whole process does not require manual intervention to ensure that the batch processing process is not interrupted. The specific implementation process is as follows: Step 1: Obtain the target font parameters input by the user; This step is the same as the way of obtaining the target font parameters in Embodiment 1. Specifically: Prompt the user to input the target font type, and the target font type is an SHX font or a Windows font; If the target font type is an SHX font, further prompt the user to input the target font mode and the target font name, and the target font mode is SHX normal mode or SHX big font mode; If the target font type is a Windows font (that is, the target font mode is Windows font mode), only prompt the user to input the target font name; According to the target font type, automatically process the extension of the target font name.

[0076] For the parts not elaborated in this step, please refer to Embodiment 1.

[0077] Step 2: Select the target folder and obtain the file list; This step is to obtain the list of CAD graphic files to be processed from the selected target folder. Specifically: A pop-up folder selection dialog box allows the user to select the target folder containing the CAD drawing files to be processed; The process iterates through the target folder selected by the user, filters out all CAD drawing files with the .dwg extension, generates a list of CAD drawing files to be processed, and simultaneously excludes non-DWG format files to avoid misprocessing other file types. This operation enables batch filtering and unified management of CAD drawing files to be processed, avoiding the tedious operation of selecting files one by one by the user, greatly improving the convenience of batch processing of multiple documents. At the same time, excluding non-target files avoids file corruption or invalid operations caused by misprocessing, ensuring the security of batch processing.

[0078] The generated list of CAD drawing files is displayed in the command line as a list, indicating the total number of files and the name and path of each file. The user is prompted to confirm whether to batch process all files in the list. If the user selects no, the program terminates; if the user selects yes, the process proceeds to the next step. This verification step is a necessary prerequisite for batch processing, which can prevent batch errors caused by the user selecting the wrong folder or file, and ensure the accuracy of batch processing.

[0079] Step 3: Batch process each CAD drawing file; Specifically, the list of CAD drawing files generated in step 2 is traversed, and a replacement operation is performed on each CAD drawing file one by one. A two-level priority mechanism of ObjectDBX priority and normal opening demotion is adopted to achieve the whole process without manual intervention and ensure that the batch processing flow is not interrupted. The specific implementation process is as follows: First, try to open the current CAD drawing file without a user interface using ObjectDBX. If the opening is successful, perform the following operations in sequence: obtain the text style list of the CAD drawing file, identify the font mode of each text style, and batch update the text style field according to the target font parameters (i.e., the replacement operation process in Example 1) to complete the batch replacement operation of the current CAD drawing file; after the replacement is completed, save the CAD drawing file and close it, mark the file as successfully processed, and continue to process the next file.

[0080] If opening via ObjectDBX fails, it automatically downgrades to normal opening mode. Simultaneously, it saves the original values ​​of the current CAD system variables cmddia and expert, sets cmddia=0 to close the command dialog box, and sets expert=5 to suppress all pop-up prompts (including those indicating missing external references). It then opens the current CAD drawing file in normal vla-open mode and performs the following operations in sequence: obtains the text style list of the CAD drawing file, identifies the font mode of each text style, and batch updates the text style field according to the target font parameters (i.e., the replacement operation process in Example 1) to complete the batch replacement operation of the current CAD drawing file. After replacement, it saves and closes the CAD drawing file, restores the original values ​​of the system variables cmddia and expert, marks the file as successfully processed, and continues processing the next file.

[0081] If both of the aforementioned methods of opening fail, the CAD drawing file is marked, and its name, path, and reason for failure are recorded. The overall batch processing flow is not interrupted, and the next file is processed.

[0082] Preferably, a dual-level priority mechanism is used to maximize the success rate of opening files, avoid interruptions in the batch processing flow, significantly improve batch processing efficiency, and reduce the cost of manual intervention by users; at the same time, it ensures that the replacement process for each file is completely consistent with the single-document mode, guarantees the uniformity of the replacement effect of multiple files, avoids replacement deviations caused by different processing methods, and achieves the effect of unattended operation.

[0083] Step 4: Output batch processing results; Specifically, after all files have been processed, the batch processing results are automatically output. The specific implementation process is as follows: The system calculates the total number of files processed in batches, the number of files processed successfully, and the number of files processed unsuccessfully. If any files failed to process, it lists the name, path, and specific reason for each failure to facilitate subsequent troubleshooting by the user. The system displays the batch processing statistics in a list format on the command line and pops up a window to notify the user that the batch processing is complete.

[0084] Preferably, a batch processing log file is generated and saved to the target folder. The log file records the processing time, processing status, and replacement details (including the number of styles successfully modified) for each file, so that users can trace and verify them later.

[0085] By providing clear feedback on the overall status of batch processing, users can quickly grasp the processing results. At the same time, through log files and failure reason records, users can easily troubleshoot problems with failed files and perform manual supplementary processing, thereby improving the completeness and practicality of batch processing, further reducing user operating costs, and balancing unattended automation with result traceability.

[0086] This embodiment provides a method for batch replacing font styles in CAD text across multiple documents, which has the following advantages: First, we continue to use the core technology design of explicitly setting the string to an empty string instead of deleting the large font field, and simultaneously solve the compatibility problem of different CAD versions in the scenario of batch processing of multiple documents. This avoids abnormal font display caused by missing group code 4 after batch processing, and ensures the uniformity of the replacement effect of all files. Secondly, it adopts a two-level priority mechanism of ObjectDBX first and normal opening downgrade, combined with cmddia, expert system variable temporary adjustment and pop-up suppression technology, to realize unattended automatic processing of multiple documents throughout the process, and solves the pain points of existing multi-document replacement that require manual file-by-file operation, easy process interruption and low efficiency from a technical point of view. Third, by using technologies such as intelligent processing of target font parameters, automatic file filtering, and automatic recording of anomalies, the irreversible risks of batch replacement are avoided, ensuring the stability of the batch processing process. Even if some files fail to open, the overall process is not interrupted, thus improving the reliability of batch processing. Fourth, by calling the entmod and entupd functions, the field updates are ensured to take effect. Combined with log generation technology, the processing results are made traceable, which not only ensures unattended automation, but also solves the problems of difficulty in verifying results and troubleshooting anomalies after batch processing. Fifth, it eliminates the need for manual user intervention in the multi-file processing process, significantly improving the efficiency of font replacement in multiple documents and reducing labor costs. It is suitable for large-scale CAD graphic file batch optimization scenarios, realizing the core requirements of unattended and efficient batch replacement, while solving the technical problems of poor compatibility, insufficient stability, and weak traceability in existing multi-document batch processing.

[0087] Example 7: This embodiment uses the method of Embodiment 6 to verify the two-level priority mechanism of ObjectDBX priority and normal opening degradation in a multi-document processing scenario, as follows: Initial state: The folder with the storage path D:\Project Drawings contains 150 DWG files (i.e., CAD drawing files), among which the DWG file named 04-1 Left Bridge Layout Drawing.dwg has a missing external reference; User actions: Enter the target font in Windows font mode, the font name is SimHei, and select the target folder; Program execution process: First priority: For each CAD drawing file in the file list, try to open it in ObjectDBX mode first; create an ObjectDBX object, try to open the current CAD drawing file, if the opening is successful, get the list of all text styles of the CAD drawing file, perform batch font replacement operation, save the file and close it, and mark it as processed successfully; Second priority: A CAD drawing file named "04-1 Left Bridge Layout Drawing.dwg" failed to open with ObjectDBX due to a missing external reference, and the program automatically performed a downgrade process. (1) Save the original values ​​of the current system variables cmddia and expert; (2) Set cmddia=0 to close the command dialog box, and set expert=5 to suppress all prompts (including prompts for missing external references); (3) Silently open the file using the normal vla-open method; (4) Obtain a list of all text styles in the file and perform a font replacement operation; (5) Save the file and close it, restoring the original values ​​of the system variables cmddia and expert; (6) Mark the file as successfully processed and continue processing the next file; Third priority: If both ObjectDBX and normal opening methods fail, record the file name, mark it as a processing failure, and continue processing the next file without interrupting the overall batch processing flow.

[0088] Processing result: Successfully processed: 148 files; Processing failed: 2 files (actually corrupted or unopenable files); A pop-up window displays that 148 / 150 files were successfully processed, and lists the failed files for users to troubleshoot later.

[0089] As can be seen, the dual-level priority mechanism in this embodiment takes into account both processing efficiency and success rate. The first level, ObjectDBX, ensures the speed of batch processing, while the second level, normal opening combined with dialog box suppression, ensures the success rate of processing special files. This achieves fully automatic batch processing without human intervention and solves the problem of process interruption caused by the lack of external references in the prior art.

[0090] Example 8: This embodiment provides a batch replacement system for CAD text styles and fonts. The system incorporates two batch replacement methods from Embodiments 1 and 6, and offers selection between single-document and multi-document processing modes, including: The mode selection module provides users with single-document processing mode and multi-document processing mode to choose from. It receives the user's mode selection command and jumps to the corresponding processing flow. The file and style acquisition module, in single-document processing mode, acquires the text style list of the currently opened single CAD drawing file; in multi-document processing mode, it acquires the list of CAD drawing files in the target folder specified by the user, and acquires the text style list of each CAD drawing file one by one. The font recognition module iterates through each text style and identifies the font pattern of the text style based on the ordinary font field and the large font field in the text style; The parameter input and processing module receives the target font parameters input by the user and automatically processes the file extension according to the target font type. The font replacement module directly updates the normal font field and large font field of each text style in batches according to the target font parameters in single document processing mode; in multi-document processing mode, it adopts a two-level priority mechanism of ObjectDBX priority and normal opening degradation, opens each CAD drawing file in the file list one by one, and completes the replacement of the target text style in each CAD drawing file. The result output module receives the processing results from the font replacement module and displays the results.

[0091] Example 9: This embodiment provides a CAD text style font batch replacement system, including a memory and a processor. The memory stores a computer program, and when the processor runs the computer program, it executes the CAD text style font batch replacement method in Embodiment 1 or Embodiment 6.

[0092] Example 10: This embodiment provides a storage medium storing a computer program, which, when run, executes the CAD text style font batch replacement method in Embodiment 1 or Embodiment 6.

[0093] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for batch replacement of font styles in CAD text, characterized in that, include: Retrieve the list of text styles from the CAD drawing file, where the text styles include a regular font field and a large font field; Based on the normal font field and large font field in each text style, identify the font mode of each text style; Obtain the target font parameters input by the user and automatically process the file extension of the target font parameters; Based on the processed target font parameters and font pattern recognition results, batch update the ordinary font field and large font field for each text style; Specifically, when switching from SHX large font mode to SHX normal mode or Windows font mode, the large font field is explicitly set to an empty string.

2. The method for batch replacement of CAD text style fonts according to claim 1, characterized in that, To retrieve the list of text styles from a CAD drawing file, specifically: Get the style name string input by the user, and parse the style name string to get a list of text styles; If the user does not enter a style name string, the system will automatically iterate through all text styles in the current CAD drawing file and generate a list of text styles.

3. The method for batch replacement of CAD text style fonts according to claim 1, characterized in that, Based on the "normal font" and "large font" fields in each text style, the font mode of each text style is identified, specifically: Iterate through the obtained list of text styles and check the normal font field of each text style. If the normal font field contains the .shx suffix, then further check the large font field. If the large font field is not empty, the text style is determined to be SHX large font mode. If the large font field is empty, the text style is determined to be SHX normal mode. If the regular font field does not contain the .shx suffix, then the text style is determined to be Windows font mode.

4. The method for batch replacement of CAD text style fonts according to claim 1, characterized in that, Obtain the target font parameters input by the user, and automatically process the file extension of the target font parameters, specifically: The user is prompted to enter the target font type, which can be an SHX font or a Windows font. If the target font type is an SHX font, the user will be further prompted to enter the target font mode and the target font name. The target font mode is either SHX normal mode or SHX large font mode. If the target font type is a Windows font, then only prompt the user to enter the target font name; Automatically handle the file extension of the target font name based on the target font type.

5. The method for batch replacement of CAD text style fonts according to claim 1, characterized in that, Update the "Normal Font" and "Large Font" fields for each text style, specifically: Iterate through the list of text styles, and update the ordinary font field of each text style one by one by combining the font pattern recognition result corresponding to each text style with the target font parameters; Based on the target font parameters, either update the large font field synchronously or explicitly set the large font field to an empty string; During the update process, the corresponding fields in the text style symbol table are modified using the entmod function, and the entupd function is called to force an update of the object; after all text styles are updated, a graphic refresh operation is performed.

6. The method for batch replacement of CAD text style fonts according to claim 5, characterized in that: When switching to SHX large font mode: Check if the large font field of the text style exists; if it does not exist, add it and assign it the default or user-input large font name; if it already exists, replace its value. The large font field is set using the vla-put-bigfontfile function, and the regular font field is updated using VLA object methods; When switching to SHX normal mode: the vla-put-fontfile function is used to modify the normal font field to the font name with the .shx extension, and the large font field is explicitly set to an empty string through symbol table operations; When switching to Windows font mode: The vla-SetFont function modifies the normal font field to the Windows font name and removes the .shx suffix. The vla-put-bigfontfile function is wrapped with the vl-catch-all-apply function to pass an empty string to the big font field in an attempt to clear it. At the same time, the big font field is explicitly set to an empty string through symbol table operations.

7. The method for batch replacement of CAD text style fonts according to claim 1, characterized in that, When there are two or more CAD drawing files to be processed: Prioritize opening CAD drawing files in ObjectDBX mode for text style replacement; If the ObjectDBX method fails to open the file, save the original values ​​of the current system variables cmddia and expert, set cmddia=0 and expert=5, open the CAD drawing file in vla-open mode to replace the text style, and restore the original values ​​of cmddia and expert after the replacement is successful. If both of the above methods fail to open the file, mark the CAD drawing file as failed and continue processing the next CAD drawing file.

8. A batch font replacement system for CAD text styles, characterized in that, The system employs the batch replacement method for CAD text style fonts as described in claim 7. The system includes: The mode selection module provides users with single-document processing mode and multi-document processing mode to choose from. It receives the user's mode selection command and jumps to the corresponding processing flow. The file and style acquisition module, in single-document processing mode, acquires the text style list of the currently opened single CAD drawing file; in multi-document processing mode, it acquires the list of CAD drawing files in the target folder specified by the user, and acquires the text style list of each CAD drawing file one by one. The font recognition module iterates through each text style in the text style list and identifies the font pattern of the text style; The parameter input and processing module receives the target font parameters input by the user and automatically processes the file extension of the target font parameters; The font replacement module replaces each text style in the text style list according to the target font parameters in single document processing mode; in multi-document processing mode, it opens each CAD drawing file in the CAD drawing file list one by one according to the preset priority opening method, and replaces the text styles in the text style list according to the target font parameters. The result output module receives the processing results from the font replacement module and displays the results.

9. A batch font replacement system for CAD text styles, characterized in that, It includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the CAD text style font batch replacement method as described in any one of claims 1-7 when running the computer program.

10. A storage medium, characterized in that, The storage medium stores a computer program, which, when run, executes the CAD text style font batch replacement method as described in any one of claims 1-7.