A CAD valve, instrument data bidirectional synchronization method, system and storage medium based on dynamic block and extended data
Patent Information
- Application Number
- CN202610912689.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-24
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2046-06-24
AI Technical Summary
[0013]鉴于以上所述现有技术的不足,本发明的目的在于提供一种基于动态块与扩展数据的CAD阀门、仪表数据双向同步方法、系统及存储介质,用于解决现有技术中CAD阀门、仪表数据管理中存在数据提取不完整、无法双向同步、编辑操作不便且数据一致性差的问题
[0052]本申请通过完整提取CAD阀门、仪表动态块的常规属性与扩展数据Xdata,解决了现有技术数据提取不完整的问题;
Smart Images

Figure CN122451970B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer-aided design technology, and in particular relates to a method, system and storage medium for bidirectional synchronization of CAD valve and instrument data based on dynamic blocks and extended data. Background Technology
[0002] Currently, valves and instruments are the two most frequently used items in P&ID (Production and Inspection). In the engineering field, the management of valve and instrument data within P&ID drawings primarily employs two methods:
[0003] First, we rely on the native functions of CAD to manually edit the attributes of individual dynamic attribute blocks one by one, and then manually record them into an Excel list to complete the data organization.
[0004] Secondly, existing third-party CAD plugins are used to achieve one-way export of valve and instrument attributes (CAD→Excel), and then the modified data in Excel is manually written back to the CAD drawings through manual verification.
[0005] The main idea of patent application CN114386129A is to use a CAD API to traverse valve blocks and instrument blocks in drawings, extract common attributes such as block dimensions and numbers, and export the data to Excel format for list preparation. The main steps are: plugin loading → block identification and filtering → attribute extraction and deduplication → Excel export. This solution only achieves one-way data migration from CAD to Excel, eliminating the need for manual data entry and simplifying the initial manual data entry work for list preparation.
[0006] The existing technology has the following obvious drawbacks and shortcomings, which are also the core problems that this invention needs to solve:
[0007] 1. Limited extraction dimensions and incomplete project information: Only the regular visible attributes of the block are extracted, and the extended data Xdata bound to the block is not supported. Key project parameters such as model, specifications, material, and installation method cannot be obtained. The exported data cannot be directly used for procurement and construction and still needs to be supplemented manually.
[0008] 2. One-way export only, no write-back mechanism: It only supports one-way export from CAD to Excel. Data modified in Excel cannot be automatically written back to update the CAD block. A large number of valves and instruments need to be manually modified one by one, which has extremely low synchronization efficiency and is prone to errors.
[0009] 3. Lack of batch and linked editing, cumbersome operation: It only supports viewing and exporting the attributes of a single block, and does not provide batch editing or linked editing functions; it uses a preview panel for interaction, which requires frequent switching of the interface, making it impossible to edit while viewing the drawing, resulting in a poor user experience.
[0010] 4. Lack of unified mapping and verification leads to data inconsistency: The lack of a two-way mapping and real-time verification mechanism between blocks and Excel makes it easy for drawings and lists to be "two separate entities," resulting in inconsistent specifications and incorrect quantities, increasing project risks and rework costs.
[0011] In summary, the prior art solution represented by patent application CN114386129A has the following technical obstacles: it only supports one-way attribute value copying from the CAD drawing database to external files, lacking a reverse mapping and write-back mechanism anchored by the unique identifier of the drawing entity; furthermore, it is limited by the modal interaction paradigm, with editing operations and CAD drawing database access operating in a serial blocking mode. Therefore, the prior art fails to solve the core technical problem of how to achieve consistent bidirectional flow of attribute data between the CAD drawing database and external files, using the unique identifier of the drawing entity as the matching key, without blocking CAD drawing database access.
[0012] Therefore, there is an urgent need for a technical solution that can fully extract the regular attributes and extended data Xdata of valve and instrument dynamic blocks, support multiple convenient editing methods, realize bidirectional data synchronization between CAD and external files, and ensure data consistency. Summary of the Invention
[0013] In view of the shortcomings of the prior art described above, the purpose of this invention is to provide a method, system and storage medium for bidirectional synchronization of CAD valve and instrument data based on dynamic blocks and extended data, in order to solve the problems of incomplete data extraction, inability to achieve bidirectional synchronization, inconvenient editing operations and poor data consistency in the management of CAD valve and instrument data in the prior art.
[0014] To achieve the above and other related objectives, the first aspect of the present invention provides a method for bidirectional synchronization of CAD valve and instrument data based on dynamic blocks and extended data, comprising the following steps:
[0015] Data extraction steps: Traverse the valve and / or instrument dynamic blocks in the CAD drawing, and extract the regular attributes, extended data Xdata, and handle of each dynamic block;
[0016] Multiple editing methods: Provides multiple editing methods that do not block the main CAD interface, allowing users to modify and temporarily save the extracted data; the editing methods include at least bidirectional linked editing of CAD tables and non-modal window editing;
[0017] Two-way synchronization steps: Perform the first-direction synchronization from CAD to external files, and the second-direction synchronization from external files to CAD;
[0018] The first direction synchronization includes: exporting the handle, regular attributes, and extended data Xdata of each dynamic block to an external file;
[0019] The second direction synchronization includes: traversing the valve and instrument dynamic blocks in the drawing through the CAD application programming interface, counting the number of dynamic blocks and the handle set; parsing the external file through the file reading interface, counting the number of valid data entries and the handle list, and verifying that the handles are not missing or duplicated; if the number of dynamic blocks is inconsistent with the number of valid data entries or the handle verification fails, write-back is prohibited and a prompt is displayed; otherwise, using the handle as the unique matching key, the external file data is written back in batches to the regular attributes and extended data Xdata of the corresponding dynamic block through the CAD application programming interface.
[0020] In some embodiments of the present invention, the nonmodal window editing includes:
[0021] A non-modal window pops up, displaying complete data for all valve and / or instrument dynamic blocks in a list format. This window uses a non-modal mechanism to allow the CAD main thread and the editing thread to run in parallel without blocking the CAD main operation.
[0022] When a user modifies a data item in the window, the data item is marked as dirty data and the rendering display style of the corresponding data item is changed based on this status.
[0023] When the user clicks the refresh button, the dirty data state is cleared, all data in the window is restored to the state after the last confirmation, and the default rendering style is restored;
[0024] When a user selects any row of data in the window and clicks the positioning button, the CAD interface viewport will automatically pan and zoom to the position of the dynamic block corresponding to that row of data in the drawing.
[0025] When the user clicks the confirmation button, all changes in the window will be batch updated to the corresponding dynamic block attributes in the CAD drawing.
[0026] In some embodiments of the present invention, the bidirectional linkage editing of the CAD table includes:
[0027] Generate a structured table in the CAD drawing consisting of single lines and single-line text, which displays the handles, general properties and extended data Xdata of all valves and / or instrument dynamic blocks;
[0028] Users can directly modify data in the table and batch update the attributes of the corresponding dynamic blocks in the CAD drawing by matching the handle through the table import function;
[0029] It supports one-click refresh of the table display content by matching the handle when the attributes of dynamic blocks in CAD drawings are changed in other ways, thereby realizing bidirectional synchronous linkage of data between CAD dynamic blocks and tables.
[0030] In some embodiments of the present invention, the external file is an Excel file, and when exported, a list containing a handle column, a block type column, a regular attribute column, and an extended data Xdata column is generated according to a preset template.
[0031] In some embodiments of the present invention, the extended data Xdata includes at least one or more of the following custom information parameters: model, specifications, installation method, and material.
[0032] In some embodiments of the present invention, the multi-mode editing step further includes a single block attribute editing mode: displaying all attributes of a single dynamic block selected by the user in the CAD side panel, and directly updating the attributes of the dynamic block after receiving the user's modification instruction.
[0033] In some embodiments of the present invention, in the multi-mode editing step, the modified data is temporarily stored in memory. Specifically, a temporary cache of hash table or dictionary structure is constructed based on the aforementioned {handle-field value} mapping table, using the handle of each dynamic block as a unique key. The regular attributes and extended data Xdata of each block are stored in key-value pairs to ensure that the modified data corresponds one-to-one with the CAD drawing block, without confusion or loss.
[0034] In some embodiments of the present invention, when the second direction synchronization writes back the extended data Xdata, it adopts a key-value pair traversal update method instead of replacing the entire extended data Xdata dictionary; the system only updates the preset engineering fields such as model, specifications, material, and installation method, and retains the extended data Xdata that already exists in the CAD dynamic block and is written by other software, so as to avoid the write-back operation from damaging the graphic data.
[0035] A second aspect of the present invention provides a bidirectional synchronization system for CAD valve and instrument data based on dynamic blocks and extended data, comprising:
[0036] Initialization module: Used to load into CAD software and generate operation panel;
[0037] Data extraction module: used to traverse the valve and / or instrument dynamic blocks in the drawing, and extract the regular attributes, extended data Xdata and handle of each dynamic block;
[0038] Editing interaction module: used to provide multiple editing interfaces that do not block the main CAD interface, receive user modifications to the extracted data and temporarily save them; the editing interface includes at least a two-way linkage editing interface for CAD tables and a non-modal window editing interface;
[0039] Two-way synchronization module: used to export the handle, general attributes and extended data Xdata of each dynamic block to an external file, and to write back the data from the external file in batches to the general attributes and extended data Xdata of the corresponding dynamic block in the CAD drawing, using the handle as the unique matching key;
[0040] Verification module: Before writing back, it traverses the valve and instrument dynamic blocks in the current drawing through the CAD application interface to count the number of dynamic blocks and the handle set; it parses the external file through the file reading interface to count the number of valid data entries and the handle list, and verifies that there are no missing or duplicate handles; if the number of dynamic blocks is inconsistent with the number of valid data entries or the handle verification fails, writing back is prohibited and a prompt is displayed; if the verification passes, the bidirectional synchronization module is allowed to perform writing back.
[0041] In some embodiments of the present invention, the non-modal window editing interface in the editing interaction module includes the following sub-functions:
[0042] Modify the marker function: After the user modifies a data item in the window, the data item is marked as dirty data, and the rendering display style of the corresponding data item is changed based on the dirty data status;
[0043] Refresh Undo Sub-function: When the user clicks the refresh button, the dirty data state is cleared, all data in the window is restored to the state after the last confirmation, and the rendering style is restored to the default.
[0044] Graphical Positioning Sub-function: After the user selects any row of data in the window and clicks the positioning button, the CAD viewport will automatically position itself to the graphic position of the dynamic block corresponding to that row.
[0045] Batch Confirmation Sub-function: After the user clicks the Confirm button, all changes in the window will be updated in batch to the corresponding dynamic block attributes of the CAD drawing.
[0046] In some embodiments of the present invention, the CAD table bidirectional linkage editing interface in the editing interaction module includes:
[0047] Table generation sub-function: Generates a structured table in CAD drawings that consists of single lines and single rows of text and can be linked bidirectionally, displaying the handles, general attributes and extended data Xdata of all valves and / or instrument dynamic blocks;
[0048] Table import sub-function: Receives the table selected by the user, matches it by handle, and then updates the attributes of the corresponding dynamic blocks in the CAD drawing in batches;
[0049] The table update sub-function re-traverses the latest attributes of the dynamic blocks in the drawing, matches and refreshes the table display content by handle, and realizes two-way data synchronization and linkage between CAD dynamic blocks and tables.
[0050] A third aspect of the present invention provides a computer-readable storage medium for storing a computer program that, when executed by a processor, implements the above-described method.
[0051] As described above, the present invention has the following beneficial effects:
[0052] This application solves the problem of incomplete data extraction in the prior art by fully extracting the regular attributes and extended data Xdata of CAD valve and instrument dynamic blocks;
[0053] By providing multiple editing methods that do not block the main CAD interface, the convenience and efficiency of user operation are improved;
[0054] Meanwhile, by using the handle as a unique matching key, efficient two-way data synchronization between CAD and external files is achieved. With the addition of a quantity verification mechanism, the data consistency between CAD drawings and external lists is effectively guaranteed, thereby reducing engineering risks and rework costs. Attached Figure Description
[0055] Figure 1 This is a flowchart illustrating the workflow of the present invention.
[0056] Figure 2 A schematic diagram shown is presented as an example file;
[0057] Figure 3 This is a schematic diagram of the generated table interface;
[0058] Figure 4 This is a diagram showing the non-modal window editing interface;
[0059] Figure 5 This is a screenshot showing the interface for exporting an Excel list. Detailed Implementation
[0060] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention.
[0061] The first aspect of this invention provides a method for bidirectional synchronization of CAD valve and instrument data based on dynamic blocks and extended data, comprising the following steps:
[0062] Data extraction steps: In response to user operation commands, traverse the dynamic blocks named valves and / or instruments in the current drawing through the CAD application programming interface, extract the general attributes, bound extended data Xdata, and handle of each dynamic block in the CAD drawing.
[0063] Multiple Editing Methods: This feature provides various editing methods, employing either a non-modal window mechanism or multi-threaded parallel processing. This allows the CAD main thread and editing operation thread to execute in parallel, ensuring real-time accessibility to the CAD graphics database and preventing blocking of CAD view operations. Users can modify extracted data, and the modified data is temporarily stored in memory. The editing methods include at least bidirectional linked editing of CAD tables and non-modal window editing. Specifically, bidirectional linked editing of CAD tables supports: automatic table refresh when CAD block attributes change, and reverse updating of CAD block attributes when table data is modified, achieving bidirectional data synchronization between blocks and tables.
[0064] Two-way synchronization steps: Perform the first-direction synchronization from CAD to external files, and the second-direction synchronization from external files to CAD.
[0065] The first direction synchronization includes exporting the handle, regular attributes, and extended data Xdata of each dynamic block to an external file.
[0066] The second direction synchronization includes: first, reading the external file, removing header rows and blank rows to obtain valid data, counting the number of valve data entries, instrument data entries, and handle totals in the external file, and verifying whether handles are missing or duplicated; simultaneously, counting the number of valve dynamic blocks and instrument dynamic blocks in the current CAD drawing; if the number of valves, instruments, or handles in the external file does not match the number in the current CAD drawing, or if handles are missing / duplicated, then write-back is prohibited and an error message is displayed; if all verifications are successful, then using the handle as the unique matching key, the data in the external file is written back in batches to the regular attributes and extended data Xdata of the corresponding dynamic blocks in the CAD drawing.
[0067] In the second-direction synchronization, when writing back extended data, a key-value pair traversal update method is used: only the field values in the preset engineering field set are updated, while the extended data already existing in the CAD dynamic block and written by other applications are preserved from being overwritten or deleted. The preset engineering field set includes model, specifications, installation method, and material.
[0068] In this embodiment, during the data extraction step, the BlockReference entities in the current drawing are traversed through the CAD application interface. Each block name is checked to determine whether it is a preset "valve" or "instrument" to identify a valid dynamic block. For each valid dynamic block, the regular and dynamic attributes are read through the AttributeCollection attribute set. At the same time, the TypedValue key-value pairs of the extended data Xdata are read according to the registered application name RegApp to extract engineering parameters such as model, specifications, material, and installation method. The unique handle of each dynamic block in the CAD drawing is obtained, and a {handle-field value} mapping table is established with the handle as the unique key, which serves as the data basis for subsequent editing and synchronization.
[0069] This embodiment provides at least two editing methods that do not block the main CAD interface during the multi-mode editing process. Users can modify the extracted data, and the modified data is temporarily stored in memory. The editing interface uses an independent floating window, which does not occupy the focus of the main CAD program during operation. Users can perform other operations on the CAD drawing while editing the data. Modified data is temporarily stored in a temporary data structure, awaiting user confirmation.
[0070] In this embodiment, the handle is used as the unique matching key in the bidirectional synchronization step to achieve a precise one-to-one data correspondence between the CAD file and the external file. The synchronization operation can be triggered by the user or executed automatically when preset conditions are met.
[0071] The first direction synchronization exports the handle, regular attributes, and extended data (Xdata) of each dynamic block to an external file, including structured file formats such as .xlsx.
[0072] The second-direction synchronization performs a quantity verification before writing back: it parses the number of valid records in the external file through the file reading interface, and simultaneously counts the total number of dynamic blocks in the drawing that meet the name criteria through the CAD API. If the quantity is inconsistent, an error message is output and the write back is terminated to avoid data inconsistency; if the quantity is consistent, it matches by handle and updates the regular attributes and extended data Xdata of the corresponding dynamic blocks in batches through the CAD API.
[0073] This implementation method fully extracts the regular attributes and extended data Xdata of dynamic blocks, solving the problem of incomplete data extraction; it adopts multiple editing methods that do not block the main interface, improving the ease of operation; it uses the handle as the unique matching key and combines it with quantity verification to ensure that the drawings and external file data are consistent, reducing engineering risks and rework costs.
[0074] In some embodiments of the present invention, the non-modal window editing method includes: popping up a non-modal window to display complete data of all valves and / or instrument dynamic blocks in a list format. The window uses a non-modal mechanism to allow the CAD main thread and the editing thread to run in parallel without blocking the main CAD operation. The non-modal window is implemented using the System.Windows.Forms.Form class and is displayed in a non-modal manner using the Application.ShowModelessDialog(form) method, without suspending the main CAD thread. Users can perform zooming, panning, selection, and other operations on the CAD interface while editing data.
[0075] After a user modifies a data item within the window, that data item is marked as dirty data, and the rendering display style of the corresponding data item is changed based on this state. The system dynamically updates the text color attribute by capturing cell edit events or value change events of data-bound controls, visually marking the modified content, making it easier for users to quickly identify the modification points and reducing the editing error rate.
[0076] When the user clicks the refresh button, the dirty data state is cleared, restoring all data in the window to the state after the last confirmation, and restoring the default rendering style. The system maintains a data snapshot; when the user clicks refresh, unconfirmed changes are discarded, and data is reloaded from the snapshot, enabling one-click undoing of all unconfirmed changes and simplifying the process of recovering from accidental modifications.
[0077] After a user selects any row of data in the window and clicks the "Locate" button, the CAD interface viewport automatically pans and zooms to the position of the corresponding dynamic block in the drawing. The system retrieves the geometric position information of the dynamic block based on the selected row, calls the CAD API viewport operation function, and displays the dynamic block completely in the center of the viewport, quickly establishing the correspondence between data and graphics and improving verification efficiency.
[0078] After the user clicks the confirmation button, all changes in the window are batch updated to the corresponding dynamic block attributes in the CAD drawing. The system iterates through the modified data items, constructs a transaction using the CAD API by handle, and commits it all at once, ensuring the atomicity and efficiency of the update, and realizing batch modification confirmation.
[0079] The non-modal window editing method in this embodiment improves the convenience, accuracy and efficiency of batch editing of valve and instrument data, and solves the problems of single editing method, inconvenient operation and difficulty in ensuring data consistency.
[0080] In some embodiments of the present invention, the bidirectional linkage editing method for CAD tables includes: generating a structured table in the CAD drawing consisting of single lines and single-line text. The table is row-based, with each row corresponding to a valve or instrument dynamic block. The first column is a handle, and subsequent columns correspond to regular attributes and extended data (Xdata) in a preset field order. The table is drawn using the CAD API, with cell borders formed by polylines (line objects) and cell content filled with single-line text (text objects). Line objects and text objects in the same cell are grouped together to achieve overall selection and editing. By setting the starting coordinates, row height, and column width, the coordinates of the upper left and lower right corners of each cell are calculated row by row and column by column, and the borders are drawn and text is written sequentially. This method adapts to the characteristics of native CAD graphics, resulting in good compatibility and strong versatility. The table centrally displays complete data, allowing users to view and manage it uniformly within the CAD environment without switching external programs.
[0081] This method allows users to directly modify data within the table. Through the table import function, after the user selects a table object, the system parses the content of all text objects within the table area, matches them by handle, and batch updates the attributes of the corresponding dynamic blocks in the CAD drawing. Users can directly edit the content of table cells, and the system identifies field values based on the text position and row / column correspondence, matches them by handle, and batch writes them back to the corresponding dynamic blocks, improving data modification efficiency.
[0082] This method also supports table update functionality: when the dynamic block attributes are changed through other means, the user can trigger a table update, and the system will re-extract the latest data and refresh the table content according to the handle, so that the table and graphic data remain consistent in real time.
[0083] The aforementioned two-way interactive editing of CAD tables enables two-way interaction between table data and dynamic block attributes, conforms to CAD operation habits, reduces interface switching, improves data synchronization efficiency and accuracy, and ensures the reliability of engineering design data.
[0084] In some embodiments of the present invention, the external file is an Excel file, and when exported, a list containing a handle column, a block type column, a regular attribute column, and an extended data Xdata column is generated according to a preset template.
[0085] In some embodiments of the present invention, the extended data Xdata includes at least one or more custom information parameters such as model, specifications, installation method, and material.
[0086] In some embodiments of the present invention, the multi-mode editing step further includes a single block attribute editing mode: displaying all attributes of a single dynamic block selected by the user in the CAD side panel, and directly updating the attributes of the dynamic block after receiving the user's modification instruction.
[0087] The single block attribute editing mode is used to quickly modify the attributes of a single selected dynamic block. After the user selects a dynamic block, the system loads and displays all the block's regular attributes and extended data (Xdata) in the CAD side panel. The CAD side panel is a dockable or floating window that does not obstruct the main drawing area. The panel updates the corresponding block attributes immediately upon receiving modification commands, providing instant feedback, simplifying the single block editing path, and improving operational flexibility.
[0088] This editing method complements the bidirectional linkage editing of CAD tables and the non-modal window editing, forming a complete editing system covering everything from rapid single-block modifications to batch data processing.
[0089] A second aspect of the present invention provides a CAD valve and instrument data bidirectional synchronization system based on dynamic blocks and extended data, including an initialization module, a data extraction module, an editing interaction module, a bidirectional synchronization module, and a verification module.
[0090] The initialization module is used to load the system into the CAD software and generate an operation panel in the CAD interface, allowing users to directly call functions within the CAD software without frequently switching to external software.
[0091] The data extraction module is used to respond to user operation commands, traverse the dynamic blocks named valves and / or instruments in the current drawing through the CAD application interface, extract the regular attributes, extended data Xdata, and handles of each dynamic block, and obtain the complete custom information parameters required for the project.
[0092] The editing interaction module provides at least two editing interfaces, employing a non-modal window mechanism or multi-threaded parallel processing to ensure the CAD main thread and editing thread execute in parallel, maintain real-time access to the CAD drawing database, receive user modifications to extracted data, and temporarily store the modified data. The editing interface includes a two-way linked CAD table editing interface and a non-modal window editing interface, allowing users to perform operations such as panning and zooming of CAD drawings while editing data.
[0093] The bidirectional synchronization module is used to perform export operations from CAD to external files and import / write-back operations from external files to CAD. The export operation exports the handle, general attributes, and extended data (Xdata) of each dynamic block to an external file. The import / write-back operation uses the handle as a unique matching key to batch write back the external file data to the CAD drawing, achieving bidirectional data flow. Specifically, when writing back the extended data (Xdata), a key-value pair traversal update method is used, updating only preset project fields and preserving other existing extended data (Xdata) in the dynamic block from being overwritten.
[0094] The verification module is used to read the external file before importing and writing back, and after excluding header rows and blank lines, count the valid data. It counts the number of valve data entries, instrument data entries, and total handles in the external file, and verifies whether handles are missing or duplicated. At the same time, it counts the total number of valve dynamic blocks and instrument dynamic blocks in the current CAD drawing. If the valves, instruments, or handles in the external file are inconsistent with those in the current CAD drawing, or if handles are missing / duplicated, the write-back is prohibited and an error message is displayed. If all verifications pass, the bidirectional synchronization module is allowed to perform the write-back based on handle matching.
[0095] This system achieves complete bidirectional synchronization of valve instrument data by fully extracting regular attributes and extended data (Xdata), accurately matching handles, performing pre-quantity verification, and using a non-blocking editing interface. This solves the problems of incomplete data extraction, low synchronization efficiency, inconvenient operation, and difficulty in ensuring consistency, thereby improving the efficiency of engineering data management and reducing engineering risks.
[0096] The data extraction module accurately identifies the target dynamic block and extracts information completely, avoiding the omission of key engineering information; the handle ensures one-to-one precise matching; the editing interaction module eliminates the blocking defect of modal windows; and the verification module prevents erroneous write-back and ensures data consistency.
[0097] The two-way synchronization module supports both export and write-back operations. Modified external files can be automatically written back in batches by handle, improving synchronization efficiency. The data temporary storage mechanism allows for adjustments before confirmation, reducing the impact of erroneous modifications. This system provides reliable assurance for the entire workflow of P&ID drawing data application.
[0098] In some embodiments of the present invention, the non-modal window editing interface in the editing interaction module includes a modification mark sub-function, a refresh and undo sub-function, a graphic positioning sub-function, and a batch confirmation sub-function.
[0099] Modify marker sub-function: After a user modifies a data item in the window, the data item is marked as dirty data, and the rendering display style of the corresponding data item is changed based on this status.
[0100] The refresh undo sub-function: When the user clicks the refresh button, the dirty data state is cleared, the window data is restored to the state after the last confirmation, and the rendering style is restored to the default. The system saves a data snapshot, and when refresh is clicked, it reloads from the snapshot, realizing one-click rollback of unconfirmed changes and simplifying the error correction process.
[0101] Graphical Positioning Sub-function: When a user selects any row of data in the window and clicks the positioning button, the CAD viewport automatically pans and zooms to the corresponding dynamic block graphic position, quickly establishing a data-graphic association, facilitating verification, and saving search time.
[0102] Batch Confirmation Sub-function: After the user clicks the confirmation button, all changes in the window are batch updated to the corresponding dynamic block attributes of the CAD drawing. The system iterates through the modified items and updates them in batches via the CAD API, improving the efficiency of modification synchronization.
[0103] The above sub-functions work together to further optimize the batch editing experience and improve the convenience, accuracy and efficiency of non-modal window editing.
[0104] In some embodiments of the present invention, the CAD table bidirectional linkage editing interface in the editing interaction module includes a table generation sub-function, a table import sub-function, and a table update sub-function.
[0105] Table generation sub-function: Generates a structured table in CAD drawings that consists of single lines and single rows of text and can be linked bidirectionally. It displays the handles, general attributes and extended data Xdata of all valves and / or instrument dynamic blocks. The table is lightweight and easy to manage, and the complete data can be viewed without switching external programs.
[0106] The table import sub-function receives user modifications in a table, matches them by handle, and then batch updates the attributes of the corresponding dynamic blocks in the CAD drawing, ensuring accurate and efficient data updates.
[0107] The table update sub-function re-traverses the latest attributes of the dynamic blocks in the drawing, matches and refreshes the table display content by handle, and realizes two-way data synchronization and linkage between CAD dynamic blocks and tables.
[0108] The above sub-functions work together to enable bidirectional linkage between dynamic blocks and table data within CAD, simplifying the editing process, improving operational fluency, ensuring data consistency, and optimizing the experience of managing valve and instrument data in P&ID drawings.
[0109] A third aspect of this invention provides a computer-readable storage medium for storing a computer program that, when executed by a processor, implements the aforementioned method for bidirectional synchronization of CAD valve and instrument data based on dynamic blocks and extended data. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0110] The present invention will be further described in detail below with reference to the accompanying drawings. This embodiment is implemented based on the technical solution of the present invention, and provides detailed implementation methods and specific operation processes, but the scope of protection of the present invention is not limited to the following embodiment.
[0111] 6.1 Implementation conditions:
[0112] 1. Software environment: AutoCAD 2012 or later, Microsoft Office software;
[0113] 2. Drawing files: P&ID drawings for a certain project, which contain dynamic blocks named valves and instruments, and the regular attributes and extended data Xdata of the dynamic blocks have been fully configured;
[0114] 3. Functionality: such as Figure 1 As shown, the workflow of this invention enables the implementation and verification of four core functions: single block attribute editing, bidirectional linkage editing of CAD tables, non-modal window editing, and bidirectional synchronization between CAD and Excel.
[0115] 6.2 Implementation steps:
[0116] 1. Open the target drawing:
[0117] Open the P&ID drawing named "F-01 Production Water Tank" using AutoCAD 2020. The drawing contains several valve and instrument dynamic blocks. The regular attributes and extended data (Xdata) of each dynamic block have been fully assigned values. Figure 2 As shown.
[0118] 2. Plugin loading and initialization:
[0119] Enter the command "netload" in the CAD command line to load the eBOM plugin assembly "CADXdata.dll" and complete the plugin registration and initialization; enter the start command "CADXT" in the CAD command line to load and display the "CAD-XATA-TOOLS" operation panel in the CAD interface, which integrates all function buttons.
[0120] 3. Data extraction:
[0121] After the user triggers the corresponding function button, the plugin traverses the current drawing through the CAD API, identifies dynamic blocks named valves and instruments, extracts the regular attributes, extended data Xdata, and graphic handles of each dynamic block, and establishes a data mapping relationship using the handle as a unique identifier.
[0122] 4. Editing individual block attributes:
[0123] Clicking the "Get Information" button on the operation panel will prompt the user to select the target object. After selecting a valve or instrument dynamic block in the drawing, the panel information area will display all the block's regular attributes and extended data (Xdata) in real time. After modifying the corresponding parameters in the information area, clicking the "Confirm Modification" button will directly update the attribute values of the selected dynamic block.
[0124] If the user selects an object that is not a valve or instrument dynamic block, the CAD command line will display a prompt message: "You have not selected a valve or instrument. Please select again."
[0125] 5. Two-way linked editing of CAD tables:
[0126] Clicking the "Export Table" button prompts the command line to specify the insertion point. After the user selects the location in the CAD drawing area, the system automatically generates a structured table consisting of single lines and single rows of text. The table includes the handles, general attributes, and extended data (Xdata) of all valves and instrument dynamic blocks. Figure 3 As shown.
[0127] After a user directly edits the content of a table cell, they can click the "Import Table" button and select the target table. The system will match the handles and write the table data back to the corresponding dynamic block in batches. If the dynamic block attributes are modified in other ways, the user can click the "Update Table" button and select the target table. The system will then re-extract the drawing data and refresh the table content to keep the table and drawing data consistent.
[0128] During the editing process, the plugin uses a hash table (dictionary) with handles as keys as a temporary memory storage structure. Data modified by the user in a non-modal window or CAD table is first stored in this temporary cache, and then written to the CAD drawing database in batches after the user confirms it, thus avoiding performance loss and data errors caused by frequent writes.
[0129] 6. Non-modal window editing:
[0130] Clicking the "Show List" button will bring up a non-modal editing window. The window displays all valve and instrument dynamic block data in a list format. This window does not obstruct the main CAD interface, allowing users to simultaneously perform operations such as zooming, panning, and selecting on the drawing. Figure 4 As shown.
[0131] When a user modifies a data item in the window, the corresponding text is automatically marked in red for easy identification of the modified content. Clicking the "Confirm Modification" button will cause the system to batch update the modified content to the corresponding dynamic block in the CAD module and display a notification indicating that the modification is complete. Clicking the "Refresh Valve List" button will discard any unconfirmed modifications and restore the system to the previous confirmed state, with the text color returning to its default value. Selecting any row of data in the list and clicking the "Locate" button will cause the CAD viewport to automatically pan and zoom to the position of the corresponding dynamic block.
[0132] 7. Two-way synchronization between CAD and Excel:
[0133] (1) Export operation:
[0134] Clicking the "Export to Excel" button will bring up a file save dialog box. The default filename and storage path are the same as the current CAD drawing. After user confirmation, the system will export all dynamic block handles, general attributes, and extended data (Xdata) as a .xlsx file according to the preset template. A save completion prompt will appear after the export is complete. Figure 5 As shown.
[0135] (2) Import write-back operation:
[0136] Click the Excel import button and select the modified Excel file; the system first reads the Excel file, excludes the header row and blank rows, and counts the number of valid data rows, and counts the number of valve data rows, instrument data rows, and handles of all data in the external file; at the same time, it counts the total number of valve dynamic blocks and instrument dynamic blocks in the current CAD drawing.
[0137] If the number of valves, instruments, or handles in the external file is inconsistent with the current CAD drawing, or if there are missing or duplicate handles, write-back will be prohibited and a corresponding error message will pop up.
[0138] If all validations pass, the Excel data will be batch-written back to the corresponding dynamic block using the handle as the unique matching key. After the write-back is complete, an import completion prompt will pop up.
[0139] As a preferred implementation, the system can further verify whether the handle column is missing, whether the block type is consistent, whether the Excel file comes from other drawings, and whether the Xdata field format is valid. If any of the above anomalies are found, the write-back will be terminated and a prompt will be displayed.
[0140] When writing Excel or spreadsheet data back to the CAD dynamic block, incremental updates and non-overwriting are used for the extended data Xdata: by traversing preset key values (model, specification, material, etc.), only the values of the corresponding fields are modified, without deleting or overwriting the extended data Xdata written by other applications, thus ensuring the compatibility and integrity of the graphic data.
[0141] This embodiment fully realizes the functions of data extraction, multi-mode editing, and bidirectional synchronization throughout the entire process. It can simultaneously extract the regular attributes of dynamic blocks and extended data Xdata, and supports three modes: single editing, table linkage editing, and non-modal batch editing. It uses handle precise matching and quantity verification to ensure that the data of CAD graphics, CAD tables, and Excel files are consistent. It can be directly applied to P&ID drawing engineering data management in fields such as chemical industry, power, water supply and drainage, and oil and gas, and meets the data needs of the entire process of procurement, construction, and operation and maintenance.
[0142] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in the present invention should still be covered by the claims of the present invention.
Claims
1. A method for bidirectional synchronization of CAD valve and instrument data based on dynamic blocks and extended data, characterized in that, Includes the following steps: Data extraction steps: Traverse the valve and / or instrument dynamic blocks in the CAD drawing, and extract the regular attributes, extended data Xdata, and handle of each dynamic block; Multiple editing methods: Provides multiple editing methods that do not block the main CAD interface, allowing users to modify and temporarily save the extracted data; the editing methods include at least bidirectional linked editing of CAD tables and non-modal window editing; Two-way synchronization steps: Perform the first-direction synchronization from CAD to external files, and the second-direction synchronization from external files to CAD; The first direction synchronization includes: exporting the handle, regular attributes, and extended data Xdata of each dynamic block to an external file; the second direction synchronization includes: traversing the valve and instrument dynamic blocks in the drawing through the CAD application programming interface, counting the number of dynamic blocks and the handle set; parsing the external file through the file reading interface, counting the number of valid data entries and the handle list, and verifying that the handles are not missing or duplicated; if the number of dynamic blocks is inconsistent with the number of valid data entries or the handle verification fails, write-back is prohibited and a prompt is displayed; otherwise, using the handle as the unique matching key, the external file data is written back in batches to the regular attributes and extended data Xdata of the corresponding dynamic block through the CAD application programming interface.
2. The method according to claim 1, characterized in that, The non-modal window editing includes: A non-modal window pops up, displaying complete data for all valve and / or instrument dynamic blocks in a list format. This window uses a non-modal mechanism to allow the CAD main thread and the editing thread to run in parallel without blocking the CAD main operation. When a user modifies a data item in the window, the data item is marked as dirty data and the rendering display style of the corresponding data item is changed based on this status. When the user clicks the refresh button, the dirty data state is cleared, all data in the window is restored to the state after the last confirmation, and the default rendering style is restored; When a user selects any row of data in the window and clicks the positioning button, the CAD interface viewport will automatically pan and zoom to the position of the dynamic block corresponding to that row of data in the drawing. When the user clicks the confirmation button, all changes in the window will be batch updated to the corresponding dynamic block attributes in the CAD drawing.
3. The method according to claim 1, characterized in that, The bidirectional collaborative editing of CAD tables includes: Generate a structured table in the CAD drawing consisting of single lines and single-line text, which displays the handles, general properties and extended data Xdata of all valves and / or instrument dynamic blocks; Users can directly modify data in the table and batch update the attributes of the corresponding dynamic blocks in the CAD drawing by matching the handle through the table import function; It supports one-click refresh of the table display content by matching the handle when the attributes of dynamic blocks in CAD drawings are changed in other ways, thereby realizing bidirectional synchronous linkage of data between CAD dynamic blocks and tables.
4. The method according to claim 1, characterized in that, The external file is an Excel file, which generates a list containing handle columns, block type columns, general attribute columns, and extended data Xdata columns according to a preset template during export.
5. The method according to claim 1, characterized in that, The extended data Xdata includes at least one or more of the following custom information parameters: model, specifications, installation method, and material.
6. The method according to claim 1, characterized in that, The multi-mode editing steps also include a single block attribute editing mode: displaying all attributes of a single dynamic block selected by the user in the CAD side panel, and directly updating the attributes of the dynamic block after receiving the user's modification command.
7. A two-way synchronization system for CAD valve and instrument data based on dynamic blocks and extended data, characterized in that, include: Initialization module: Used to load into CAD software and generate operation panel; Data extraction module: used to traverse the valve and / or instrument dynamic blocks in the drawing, and extract the regular attributes, extended data Xdata and handle of each dynamic block; Editing interaction module: used to provide multiple editing interfaces that do not block the main CAD interface, receive user modifications to extracted data and temporarily save them; the editing interface includes at least a two-way linkage editing interface for CAD tables and a non-modal window editing interface; Two-way synchronization module: used to export the handle, general attributes and extended data Xdata of each dynamic block to an external file, and to write back the data from the external file in batches to the general attributes and extended data Xdata of the corresponding dynamic block in the CAD drawing, using the handle as the unique matching key; Verification module: Before writing back, it traverses the valve and instrument dynamic blocks in the current drawing through the CAD application interface to count the number of dynamic blocks and handle set; it parses the external file through the file reading interface to count the number of valid data entries and handle list, and verifies that there are no missing or duplicate handles; if the number of dynamic blocks is inconsistent with the number of valid data entries or the handle verification fails, it will prohibit writing back and prompt an error message. If the verification passes, the bidirectional synchronization module is allowed to perform a write-back.
8. The system according to claim 7, characterized in that, The non-modal window editing interface in the editing interaction module includes the following sub-functions: Modify the marker function: After the user modifies a data item in the window, the data item is marked as dirty data, and the rendering display style of the corresponding data item is changed based on the dirty data status; Refresh Undo Sub-function: When the user clicks the refresh button, the dirty data state is cleared, all data in the window is restored to the state after the last confirmation, and the rendering style is restored to the default. Graphical Positioning Sub-function: After the user selects any row of data in the window and clicks the positioning button, the CAD viewport will automatically position itself to the graphic position of the dynamic block corresponding to that row. Batch Confirmation Sub-function: After the user clicks the Confirm button, all changes in the window will be updated in batch to the corresponding dynamic block attributes of the CAD drawing.
9. The system according to claim 7, characterized in that, The two-way interactive editing interface for CAD tables in the editing interaction module includes: Table generation sub-function: Generates a structured table in CAD drawings that consists of single lines and single rows of text and can be linked bidirectionally, displaying the handles, general attributes and extended data Xdata of all valves and / or instrument dynamic blocks; Table import sub-function: Receives the table selected by the user, matches it by handle, and then updates the attributes of the corresponding dynamic blocks in the CAD drawing in batches; The table update sub-function re-traverses the latest attributes of the dynamic blocks in the drawing, matches and refreshes the table display content by handle, and realizes two-way data synchronization and linkage between CAD dynamic blocks and tables.
10. A computer-readable storage medium, characterized in that, Used to store a computer program, which, when executed by a processor, implements the method as described in any one of claims 1-6.
Citation Information
Patent Citations
AutoCAD-based block attribute identification and export method
CN114386129A
Integrated CAD drawing set drawing template system and method thereof
CN119598581A
Electric power system two-dimensional drawing-three-dimensional drawing interactive display method and system
CN121597092A