CAD data acquisition method and device based on reflection mechanism
Through a reflection mechanism-based method, code for obtaining CAD data is automatically generated, which solves the problem of low efficiency in obtaining CAD data in the prior art, and efficient data acquisition and export are realized, ensuring data integrity.
Patent Information
- Application Number
- CN202411232435.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-04
- Publication Date
- 2024-12-06
AI Technical Summary
In the prior art, the acquisition of internal data of CAD software is relatively low, and a large amount of code is required to be written manually. The internal structure of CAD is complex, resulting in a large amount of development work.
Using a reflection mechanism-based method, the type list and target information are obtained by determining the CAD secondary development reflection interface, the function code is constructed, and the program is compiled into an executable program to obtain CAD data.
It improves the efficiency of CAD data acquisition and export, and the generated code is highly complete, able to cover all types, ensuring the integrity and effect of data.
Smart Images

Figure CN119088363A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a CAD data acquisition method and device based on a reflection mechanism. Background Art
[0002] CAD stands for Computer Aided Design, which is a technology that uses computer software to replace manual hand-drawing and drawing. Whether it is an architect, designer or engineer, you may use 2D or 3D CAD software to build the required model. The advantages of CAD software are: efficient drawing speed, accurate design size, reuse of design results, and convenient data storage.
[0003] In the prior art, if you want to obtain the internal data of CAD software, you need to manually write a lot of code and obtain data through the CAD secondary development interface. In addition, the internal structure of CAD is complex, involving thousands of types, resulting in a large amount of development work. It can be seen that the existing CAD data acquisition method is inefficient. Summary of the invention
[0004] The embodiments of this specification provide a CAD data acquisition method and device based on a reflection mechanism to solve the technical problem of how to acquire CAD data more efficiently and effectively.
[0005] To solve the above technical problems, the embodiments of this specification provide the following technical solutions:
[0006] The embodiment of this specification provides a CAD data acquisition method based on a reflection mechanism, the method comprising:
[0007] Determine a CAD secondary development reflection interface, obtain a CAD secondary development type list through the CAD secondary development reflection interface, and obtain target information of each type in the CAD secondary development type list;
[0008] For any type, a corresponding function code is constructed according to the target information of the type, and the function code is used to traverse the associated objects of the type of object and obtain the target information of the type of object and the associated objects;
[0009] The function code is compiled into an executable program, and the executable program is run to obtain CAD data.
[0010] Optionally, obtaining a CAD secondary development type list through the CAD secondary development reflection interface includes:
[0011] A CAD secondary development programming environment is determined, and a CAD secondary development type list is obtained according to a reflection interface provided by the CAD secondary development programming environment.
[0012] Optionally, obtaining target information of each type in the CAD secondary development type list includes:
[0013] For any type in the CAD secondary development type list, the target information of the type is obtained through the CAD secondary development reflection interface; and all parent types of the type are traversed to obtain the target information of the parent type.
[0014] Optionally, obtaining target information of each type in the CAD secondary development type list includes:
[0015] Determine whether the CAD secondary development type list is empty; if not, take out a type from the CAD secondary development type list and perform an information acquisition operation on the type;
[0016] After each execution of the information acquisition operation, repeatedly determining whether the CAD secondary development type list is empty, and taking out a new type when determining that the CAD secondary development type list is not empty, and performing the information acquisition operation for the newly taken out type;
[0017] If after executing the information acquisition operation once, it is determined that the CAD secondary development type list is empty, the acquired information is stored according to a preset rule.
[0018] Optionally, for any type, performing information acquisition operations on the type includes:
[0019] Get the target information of this type, and traverse all parent types of this type to get the target information of all parent types of this type.
[0020] Optionally, for any type, the target information of the type and the target information of the parent type are stored using the name of the type as an index.
[0021] Optionally, for any type, the function code corresponding to the type includes an access function code and a processing function code; wherein the access function code is used to traverse the associated objects of the type of object, and the processing function code is used to obtain the target information of the type of object and the associated objects.
[0022] Optionally, compiling the function code into an executable program includes:
[0023] Build the basic compilation environment for CAD secondary development, and compile the function codes constructed according to various types of target information into executable programs.
[0024] Optionally, for any type, the function code corresponding to the type includes the code of the access function and the code of the processing function, and the input parameters of the access function and the processing function are objects of the type;
[0025] or,
[0026] The target information includes attribute information and method information.
[0027] The embodiment of this specification provides a CAD data acquisition device based on a reflection mechanism, the device comprising:
[0028] An information acquisition module, used to determine a CAD secondary development reflection interface, obtain a CAD secondary development type list through the CAD secondary development reflection interface, and obtain target information of each type in the CAD secondary development type list;
[0029] A code generation module is used to construct a corresponding function code for any type according to the target information of the type, wherein the function code is used to traverse the associated objects of the type of object and obtain the target information of the type of object and the associated objects;
[0030] The execution acquisition module is used to compile the function code into an executable program and run the executable program to acquire CAD data.
[0031] At least one of the above technical solutions adopted in the embodiments of this specification can achieve the following beneficial effects:
[0032] Through the reflection mechanism, the code for obtaining CAD data can be automatically generated. By compiling and running the generated code, the acquisition and export of CAD data can be realized, thereby improving the efficiency of CAD data acquisition and export. In addition, the generated code is highly complete and can cover all types involved in the CAD secondary development interface, thereby realizing the acquisition of all types of CAD information, ensuring the integrity of the acquired and exported data, and improving the effect of CAD data acquisition and export. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions in the embodiments of this specification or the prior art, the drawings required for use in the embodiments of this specification or the prior art description are briefly described below. Obviously, the following only describes the drawings required for use in some embodiments of this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor.
[0034] Figure 1 It is a flowchart of the CAD data acquisition method based on the reflection mechanism in the first embodiment of this specification.
[0035] Figure 2 It is a schematic diagram of the CAD data export process in the first embodiment of this specification.
[0036] Figure 3 It is a flowchart of obtaining a CAD secondary development type list in the first embodiment of this specification.
[0037] Figure 4 It is a schematic diagram of the process of obtaining type target information in the first embodiment of this specification.
[0038] Figure 5 It is a schematic diagram of the code generation and compilation process in the first embodiment of this specification.
[0039] Figure 6 It is a partial code diagram of the first embodiment of this specification.
[0040] Figure 7 This is a schematic diagram of the file exported in the first embodiment of this specification.
[0041] Figure 8 It is a structural diagram of a CAD data acquisition device based on a reflection mechanism in the second embodiment of this specification. DETAILED DESCRIPTION
[0042] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments involved in the specific implementation methods are only part of the embodiments of this application, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the specific implementation methods without making creative work should belong to the scope of protection of this application.
[0043] The first embodiment of this specification (hereinafter referred to as "embodiment one") provides a CAD data acquisition method based on a reflection mechanism. The execution subject of embodiment one can be a terminal (including but not limited to mobile phones, computers, pads, wearable devices, televisions) or a server or an operating system or an application, etc., that is, the execution subject can be various and can be set, used or changed as needed. In addition, a third-party application can also assist the execution subject in executing embodiment one. For example, the method provided in embodiment one can be executed by a server, and an application corresponding to the server can be installed on the terminal (held by the user), and data can be transmitted between the terminal or application and the server, and data can be collected or input or output or processed through the terminal or application, thereby assisting the server in executing the method provided in embodiment one.
[0044] like Figure 1 and Figure 2 As shown, the CAD data acquisition method based on the reflection mechanism provided in the first embodiment includes:
[0045] S101: determining a CAD secondary development reflection interface, obtaining a CAD secondary development type list through the CAD secondary development reflection interface, and obtaining target information of each type in the CAD secondary development type list;
[0046] CAD software secondary development technology refers to the process of customized development using programming languages on existing CAD software platforms. This technology allows users to expand and modify CAD software according to their own needs to meet specific design or engineering requirements. Different CAD software platforms differ in programming languages, development interfaces, and development methods.
[0047] Reflection technology in programming is a powerful programming tool that allows the program to obtain the internal information of a class (such as class properties, methods, constructors, etc.) at runtime, and can dynamically call the object's methods or modify its field values. The uses of reflection technology include: obtaining class meta information, dynamically calling methods, modifying field values, and creating instances. Reflection technology is natively supported in many high-level programming languages, such as Java, C#, Python, and JavaScript.
[0048] In the first embodiment, the CAD secondary development reflection interface can be determined or configured. Among them, the CAD software provides a secondary development interface and specifies the programming language for secondary development. As long as the programming language supports the reflection mechanism, the determination or configuration of the reflection interface (i.e., the CAD secondary development reflection interface) can be completed. CAD software (including but not limited to CATIA, SolidWorks, UG, Creo / ProE) provides support for high-level programming languages, including C#, Java, and VB. These languages all support the reflection mechanism, so that the development or configuration of the CAD secondary development reflection interface can be carried out.
[0049] Through the CAD secondary development reflection interface, a CAD secondary development type list (hereinafter referred to as "type list") can be obtained. Among them, obtaining the CAD secondary development type list through the CAD secondary development reflection interface may include: determining the CAD secondary development programming environment, and obtaining the CAD secondary development type list according to the reflection interface provided by the CAD secondary development programming environment. In other words, the specific implementation method of obtaining the type list can be determined according to the characteristics of the programming environment or language used for CAD secondary development.
[0050] Specifically, based on the CAD secondary development reflection interface, all class definitions provided by the CAD secondary development interface can be obtained by (manually) writing codes to form a type list. Each class definition can also obtain its corresponding target information through the CAD secondary development reflection interface.
[0051] The target information described in the first embodiment may include attribute information and method information, wherein the attribute information includes the attribute type and name, and the method information includes the method name, input parameter list, and output parameter list.
[0052] The CAD secondary development reflection interface provides a unified mechanism for obtaining type attribute information and method information, so that you can traverse the type list, obtain the information of each type, and then manage it according to the type name. For types inherited from parent types, traverse the attributes and methods of all parent types level by level and summarize them under this type.
[0053] The following describes how to obtain a list of types and target information of their types:
[0054] like Figure 3 As shown, the CAD secondary development programming environment or language can be configured or determined. Among them, the CAD software secondary development programming languages include C#, Java, Python, etc., which are all high-level programming languages. C# and Java are compiled languages, and Python is a scripting language.
[0055] The type of the above-mentioned CAD secondary development programming environment or language can be determined, and the type list can be obtained according to the reflection interface (i.e., the interface that can be used to obtain the reflection type) provided by the specific programming language. For example, if the programming language used is C#, the type list can be obtained through the System.Reflection.Assembly interface; if the programming language used is Java, the type list can be obtained through the org.reflections.Reflections interface; if the programming language used is Python, the type list can be obtained through the pkgutil.iter_modules() interface. Among them, the System.Reflection.Assembly interface, the org.reflections.Reflections interface, the pkgutil.iter_modules() interface or other reflection interfaces can be used as CAD secondary development reflection interfaces.
[0056] In the first embodiment, the target information of each type in the type list can be obtained. The step of obtaining the target information of each type in the type list may include: obtaining the target information of any type in the type list through a CAD secondary development reflection interface; and traversing all parent types of the type and obtaining the target information of all parent types of the type.
[0057] The following is a procedural description of how to obtain target information for each type in the type list:
[0058] like Figure 4As shown, after obtaining the type list, determine whether the type list is empty; if not, take out a type from the type list (each time a type is taken out, the number of type lists can be reduced by one), and perform information acquisition operations on the type;
[0059] After each execution of the information acquisition operation, it is repeatedly determined whether the type list is empty, and if it is determined that the type list is not empty, a new type is taken out (the new type refers to a type that has not been taken out before, not a type with different characteristics from the type that has been taken out), and the information acquisition operation is performed on the newly taken out type;
[0060] If after executing an information acquisition operation at a certain time, it is determined that the type list is empty (the number of type lists is zero at this time), the acquired information is stored according to a preset rule.
[0061] For any type taken out from the type list, performing an information acquisition operation on the type may include: acquiring target information of the type, and traversing all parent types of the type to acquire target information of all parent types of the type. Specifically, the target information of the type may be acquired through a CAD secondary development reflection interface, and all parent types of the type may be traversed to acquire target information of all parent types of the type.
[0062] As described above, the acquired information can be stored according to preset rules, for example, all acquired target information can be aggregated and stored according to type name. Specifically, for any type, the target information of the type and the target information of the parent type are stored with the name of the type as the index.
[0063] S103: For any type, construct a corresponding function code according to the target information of the type, wherein the function code is used to traverse the associated objects of the type of object and obtain the target information of the type of object and the associated objects;
[0064] In the first embodiment, for any type in the type list, a corresponding function code can be constructed according to the target information of the type. The function code is used to traverse the associated objects of the type of object and obtain the target information of the type of object and the associated objects. The generated function code can be used to obtain CAD data. Specifically, the function code corresponding to the type may include the code of the access function (referred to as "access function code") and the code of the processing function (referred to as "processing function code"). Both the access function and the processing function can belong to the category of processing functions. Among them, the access function code is used to traverse the associated objects of the type of object, and the processing function code is used to obtain the target information of the type of object and the associated objects. The following is a detailed explanation:
[0065] like Figure 5As shown, for any type, according to the target information of the type (also called "reflection information", i.e., information obtained through the reflection interface), (based on the target information of the type) the access function code is generated by string replacement, splicing and other operations, i.e., the access function code. The incoming parameter of the access function here is the object of the type, which is used to traverse other objects associated with the object. And, according to the target information of the type, (based on the target information of the type) the processing function code is generated by string replacement, splicing and other operations, i.e., the processing function code. The incoming parameter of the processing function here is the object of the type, which is used to obtain the target information of the object of the type and the associated object, and write this information into the file.
[0066] The access function code and the processing function code can be automatically generated by a program (the program can be manually developed). If there is a customized demand for a function code corresponding to a certain type, the function code can be directly modified (including manual modification).
[0067] S105: Compile the function code into an executable program, and run the executable program to obtain CAD data.
[0068] In the first embodiment, the aforementioned function codes (corresponding to each type) can be compiled into an executable program, including: constructing a basic compilation environment for CAD secondary development, and compiling the function codes constructed according to each type of target information into an executable program. Specifically, the constructed function codes corresponding to each type (if manually modified, the manually modified function codes) are copied into the compilation environment, so as to compile the function codes into an executable program, such as Figure 5 The executable program can be called by the CAD software according to the calling rules of CAD secondary development.
[0069] By running the executable program, CAD data can be obtained. Specifically, running the executable program will execute the function codes corresponding to the aforementioned types, traverse the associated objects of each type of object, and obtain the target information of each type of object and its associated objects (all of which belong to the category of CAD data). In addition, the acquired data can be generated into a corresponding file according to a preset operation (such as the above-mentioned write file operation), and the file contains the acquired CAD data, thus realizing the operation of the executable program to acquire and export CAD data.
[0070] The feasibility of the first embodiment is also verified. Specifically, taking CATIA software as an example, CATIA software provides a COM secondary development interface, and the programming language is C#. According to the above specific implementation method, the above code can be automatically generated for acquiring and exporting CATIA data. By compiling and executing the code, objects related to the CATIA feature design module and the generative shape design module can be traversed and their data (including target information) can be exported as an XML file. In this example, the number of automatically generated code lines is 10043 lines, and the code coverage types reach 446, which proves that the complete data acquisition and export of CATIA software can be realized. Figure 6 This is a sample of some automatically generated code. Figure 7 is an example of an exported XML file.
[0071] Embodiment 1 can achieve the following beneficial effects:
[0072] In the first embodiment, by utilizing the reflection characteristics of the high-level programming language and the secondary development interface provided by the CAD software, all types of CAD can be traversed, and different types of data and function interfaces can be obtained in a consistent manner, and then this information is aggregated into a unified data structure, and the data is organized according to a tree structure. Then all nodes of the tree structure are traversed and code generation is automatically realized through string replacement operations. These codes (i.e., the above-mentioned function codes) meet the writing requirements of the CAD secondary development interface, can be compiled into a target program (i.e., the above-mentioned executable program), and finally called by the CAD software to realize traversal of all types of CAD and acquisition and export of CAD internal data.
[0073] Because the code for acquiring CAD data (i.e., CAD secondary development code) can be automatically generated through the reflection mechanism, the acquisition and export of CAD data can be realized by compiling and running the generated code, thereby improving the efficiency of CAD data acquisition and export and reducing the development workload. In addition, the generated code is highly complete and can cover all types involved in the CAD secondary development interface, thereby being able to achieve the acquisition of all types of target information involved in CAD, ensuring the integrity of the acquired and exported data, and improving the effect of CAD data acquisition and export.
[0074] For some CAD types that require special processing, the code automatically generated by the emission technology can be directly modified manually, so that manual coding and automatically generated code can exist at the same time, taking into account development efficiency and customization requirements. In addition, for each type, the corresponding function code is generated, so that the code generated in Example 1 can be divided into multiple functions according to type, supporting customized modifications to individual functions, and further improving the freedom of CAD data acquisition and export.
[0075] Embodiment 1 can be used to acquire and export CAD software data, and has broad application prospects in multiple fields including design, manufacturing, and assembly.
[0076] like Figure 8 As shown, the second embodiment of this specification provides a CAD data acquisition device based on a reflection mechanism corresponding to the method provided in the first embodiment, and the device includes:
[0077] The information acquisition module 202 is used to determine a CAD secondary development reflection interface, obtain a CAD secondary development type list through the CAD secondary development reflection interface, and obtain target information of each type in the CAD secondary development type list;
[0078] The code generation module 204 is used to construct a corresponding function code for any type according to the target information of the type, and the function code is used to traverse the associated objects of the type of object and obtain the target information of the type of object and the associated objects;
[0079] The execution acquisition module 206 is used to compile the function code into an executable program and run the executable program to acquire CAD data.
[0080] Optionally, obtaining a CAD secondary development type list through the CAD secondary development reflection interface includes:
[0081] A CAD secondary development programming environment is determined, and a CAD secondary development type list is obtained according to a reflection interface provided by the CAD secondary development programming environment.
[0082] Optionally, obtaining target information of each type in the CAD secondary development type list includes:
[0083] For any type in the CAD secondary development type list, the target information of the type is obtained through the CAD secondary development reflection interface; and all parent types of the type are traversed to obtain the target information of the parent type.
[0084] Optionally, obtaining target information of each type in the CAD secondary development type list includes:
[0085] Determine whether the CAD secondary development type list is empty; if not, take out a type from the CAD secondary development type list and perform an information acquisition operation on the type;
[0086] After each execution of the information acquisition operation, repeatedly determining whether the CAD secondary development type list is empty, and taking out a new type when determining that the CAD secondary development type list is not empty, and performing the information acquisition operation for the newly taken out type;
[0087] If after executing the information acquisition operation once, it is determined that the CAD secondary development type list is empty, the acquired information is stored according to a preset rule.
[0088] Optionally, for any type, performing information acquisition operations on the type includes:
[0089] Get the target information of this type, and traverse all parent types of this type to get the target information of all parent types of this type.
[0090] Optionally, for any type, the target information of the type and the target information of the parent type are stored using the name of the type as an index.
[0091] Optionally, for any type, the function code corresponding to the type includes an access function code and a processing function code; wherein the access function code is used to traverse the associated objects of the type of object, and the processing function code is used to obtain the target information of the type of object and the associated objects.
[0092] Optionally, compiling the function code into an executable program includes:
[0093] Build the basic compilation environment for CAD secondary development, and compile the function codes constructed according to various types of target information into executable programs.
[0094] Optionally, for any type, the function code corresponding to the type includes the code of the access function and the code of the processing function, and the input parameters of the access function and the processing function are objects of the type;
[0095] or,
[0096] The target information includes attribute information and method information.
[0097] The second embodiment can achieve the same beneficial effects as the first embodiment, and the above embodiments can be used in combination.
[0098] The above is only an embodiment of this specification and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A CAD data acquisition method based on reflection mechanism, characterized in that: The method comprises: Determine a CAD secondary development reflection interface, obtain a CAD secondary development type list through the CAD secondary development reflection interface, and obtain target information of each type in the CAD secondary development type list; For any type, a corresponding function code is constructed according to the target information of the type, and the function code is used to traverse the associated objects of the type of object and obtain the target information of the type of object and the associated objects; The function code is compiled into an executable program, and the executable program is run to obtain CAD data.
2. The method according to claim 1, characterized in that The list of CAD secondary development types obtained through the CAD secondary development reflection interface includes: A CAD secondary development programming environment is determined, and a CAD secondary development type list is obtained according to a reflection interface provided by the CAD secondary development programming environment.
3. The method according to claim 1, characterized in that Obtaining target information of each type in the CAD secondary development type list includes: For any type in the CAD secondary development type list, the target information of the type is obtained through the CAD secondary development reflection interface; and all parent types of the type are traversed to obtain the target information of the parent type.
4. The method according to claim 1, characterized in that Obtaining target information of each type in the CAD secondary development type list includes: Determine whether the CAD secondary development type list is empty; if not, take out a type from the CAD secondary development type list and perform an information acquisition operation on the type; After each execution of the information acquisition operation, repeatedly determining whether the CAD secondary development type list is empty, and taking out a new type when determining that the CAD secondary development type list is not empty, and performing the information acquisition operation for the newly taken out type; If after executing the information acquisition operation once, it is determined that the CAD secondary development type list is empty, the acquired information is stored according to a preset rule.
5. The method according to claim 4, characterized in that For any type, the information acquisition operations performed on the type include: Get the target information of this type, and traverse all parent types of this type to get the target information of all parent types of this type.
6. The method according to any one of claims 3 to 5, characterized in that For any type, the target information of the type and the target information of the parent type are stored using the name of the type as an index.
7. The method according to claim 1, characterized in that For any type, the function code corresponding to the type includes an access function code and a processing function code; wherein the access function code is used to traverse the associated objects of the type of object, and the processing function code is used to obtain the target information of the type of object and the associated objects.
8. The method according to claim 1, characterized in that Compiling the function code into an executable program includes: Build the basic compilation environment for CAD secondary development, and compile the function codes constructed according to various types of target information into executable programs.
9. The method according to claim 1, characterized in that For any type, the function code corresponding to the type includes the code of the access function and the code of the processing function, and the input parameters of the access function and the processing function are objects of the type; or, The target information includes attribute information and method information.
10. A CAD data acquisition device based on reflection mechanism, characterized in that: The device comprises: An information acquisition module, used to determine a CAD secondary development reflection interface, obtain a CAD secondary development type list through the CAD secondary development reflection interface, and obtain target information of each type in the CAD secondary development type list; A code generation module is used to construct a corresponding function code for any type according to the target information of the type, wherein the function code is used to traverse the associated objects of the type of object and obtain the target information of the type of object and the associated objects; The execution acquisition module is used to compile the function code into an executable program and run the executable program to acquire CAD data.
