Full-primitive dynamic random coloring method and system

Through the dynamic random coloring method of all primitives, the primitive coloring in CAD drawings is automatically processed, solving the problem of manual primitive coloring that takes time and is prone to errors, and achieving efficient, flexible and compatible primitive coloring effects.

CN120495442APending Publication Date: 2025-08-15SHENZHEN SKE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510526848.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-24
Publication Date
2025-08-15

AI Technical Summary

Technical Problem

In the prior art, when manually shading CAD drawings, it consumes a lot of time and energy, and is prone to omissions or errors, especially in complex drawings.

Method used

The dynamic random coloring method of all primitives is adopted. Automatic coloring is achieved by initializing parameters, obtaining exclusion layer lists, generating layer and primitive type filters, filtering primitives, generating random seeds and performing dynamic random coloring, combining the parameter initialization module, layer filtering module, element filtering module, random seed generation module and primitive coloring module.

Benefits of technology

Improves shading efficiency, enhances flexibility and compatibility, reduces the tedious process of manual operation, and facilitates debugging and maintenance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120495442A_ABST
    Figure CN120495442A_ABST
Patent Text Reader

Abstract

The invention discloses a full-primitive dynamic random coloring method. The method comprises the following steps: initializing parameters; obtaining an excluded layer list; generating a layer filter and a primitive type filter; primitives are screened; generating random seeds; dynamically and randomly coloring; time consumption is calculated, and the environment is recovered. The invention further provides a full-primitive dynamic random coloring system which comprises a parameter initialization module, a layer screening module, a primitive screening module, a random seed generation module, a primitive coloring module and an environment recovery module. Through the scheme, the coloring efficiency can be improved, different coloring schemes can be flexibly selected, the compatibility is high, and maintenance and debugging are convenient.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer graphics processing technology, and in particular to a method and system for dynamically and randomly coloring all graphic elements in a CAD drawing. Background Art

[0002] CAD drawings play a vital role in product design. From product design to production, CAD drawings are an extremely important step. During the CAD drawing design process, in order to distinguish lines, surfaces, components, parts, and primitives of different types or functions, it is necessary to color these lines, surfaces, components, parts, and primitives. The most common coloring method is manual coloring.

[0003] The process of manual coloring is as follows: first, select the lines, surfaces, components, parts, primitives, etc. that need to be colored, and then select the corresponding color. This method is simple to operate, but when encountering complex CAD drawings with surfaces, components, parts, and primitives, they need to be selected and colored one by one. This method not only consumes a lot of time and energy, but is also prone to omissions or errors.

[0004] Therefore, in view of the above problems, it is necessary to design a coloring method and system to overcome the above defects. Summary of the Invention

[0005] The main purpose of this application is to provide a method and system for dynamic random coloring of all primitives, which can efficiently and flexibly perform dynamic random coloring of all primitives in CAD drawings, improve the efficiency and visualization effect of primitive coloring, and meet the changes in different design requirements and scenarios.

[0006] To achieve the above objectives, the present application proposes a method for dynamic random coloring of all primitives, which includes the following steps:

[0007] Step 1: Initialize parameters;

[0008] Step 2: Get the excluded layer list;

[0009] Step 3: Generate layer filters and primitive type filters;

[0010] Step 4: Filter the graphics elements;

[0011] Step 5: Generate a random seed;

[0012] Step 6: Dynamic random coloring.

[0013] The initialization parameters specifically include initializing the running counter to 0, obtaining the current CAD document object, recording the current command echo settings and graphics regeneration mode, recording the program start time, obtaining the CAD software version, and checking whether the current CAD document has been saved.

[0014] Getting the exclusion layer list includes the following steps:

[0015] Define the function getExcludedLayers, which accepts the CAD document object doc as a parameter;

[0016] Inside the function, get the document's layer collection through the getExcludedLayers function;

[0017] Iterate over the layer collection and for each layer, check its frozen, locked, and open status; if the layer is frozen, locked, or closed, add its name to the list of excluded layers;

[0018] Returns a list of excluded layers.

[0019] In step 3, a layer filter is generated based on the exclusion layer list. If the exclusion layer list is not empty, the exclusion layer names are connected with commas and preceded by a symbol. If the exclusion layer list is empty, the layer filter is set to empty, indicating that all layers are selected.

[0020] At the same time, define the primitive type filter, which is a list containing logical operators and primitive type information, and is used to exclude some primitive types that do not need to be colored.

[0021] In step 4, the element set that meets the conditions is filtered out according to the element type filter. If the filtering is successful, the length of the element set is obtained, which represents the total number of filtered objects. Then, the filtered elements are further processed to exclude the elements in the exclusion layer, obtain a list of valid element names, and calculate the number of valid elements.

[0022] The generation of the random seed in step 5 includes the following factors: user running time, running counter, CAD document file size, number of valid primitives, coordinate eigenvalues and document save status. The random seed is then generated through the linear congruential algorithm, and finally the global running counter is incremented.

[0023] Before dynamic random coloring, enable the undo flag, turn off command echo and graphics regeneration mode, and if the valid primitive name list is not empty and the number of valid primitives is greater than 0, perform dynamic random coloring on each valid primitive. The specific steps are as follows:

[0024] Traverse the list of valid primitive names;

[0025] For each primitive, generate a new random seed based on the current random seed and calculate the color index, which ranges from 1 to 255.

[0026] Depending on the version and type of CAD software, choose different methods to set the color of the graphics element.

[0027] After step six, it is necessary to calculate the time consumption and restore the environment; calculate the total time consumption of the program, then end the undo mark, restore the command echo and graphics regeneration mode, and prompt the user to re-run the program again.

[0028] This design dynamically and randomly colors all primitives in an automated manner, avoiding the tedious process of manually setting the colors of primitives one by one, greatly improving the coloring efficiency, enhancing the flexibility of primitive coloring, and having strong compatibility, making it easier for users to debug and maintain.

[0029] A full-element dynamic random shading system, comprising:

[0030] The parameter initialization module is responsible for initializing various parameters required for program operation, including the running counter, CAD document object, command echo settings, graphics regeneration mode, start time, CAD software version, whether it is ZWCAD, and document save status;

[0031] The layer filtering module includes the getExcludedLayers function, which is used to obtain the excluded layer list and generate a layer filter based on the excluded layer list;

[0032] The element screening module uses the element type filter to filter out the element set that meets the conditions, and further excludes the elements in the exclusion layer to obtain a list of valid element names and the number of valid elements;

[0033] The random seed generation module generates random seeds based on factors such as user running time, running counter, CAD document file size, number of valid primitives and document save status, and updates the running counter;

[0034] The primitive coloring module dynamically and randomly colors valid primitives and sets the primitive colors in different ways according to the CAD software version and type;

[0035] The environment recovery module calculates the total time consumed by the program, ends the undo mark, restores the command echo and graphics regeneration mode, and prompts the user to run the program again.

[0036] The primitive shading module consists of the following parts:

[0037] Initialization part: including opening undo groups, closing command echo and automatic regeneration, and outputting startup prompts;

[0038] Selection set check part: Check whether the selection set exists and whether the number of entities is greater than 0. If the conditions are met, the entity processing flow will be entered; otherwise, a prompt will be output that no valid object was found;

[0039] Entity processing: a. Loop processing, looping through each entity in the selection set; b. Random seed update, updating the random seed for each entity; c. Color index generation, generating a color index between 1 and 255 based on the random seed; d. Version compatibility processing, selecting different coloring methods according to the CAD version;

[0040] Result output part: calculate and output processing time;

[0041] Ending part: End the undo group and restore system parameters.

[0042] In this design, the parameter initialization module provides basic parameters for subsequent modules, the layer screening module and the primitive screening module are responsible for screening out the primitives that need to be colored, the random seed generation module provides random seeds for primitive coloring, the primitive coloring module dynamically and randomly colors the primitives, and the environment recovery module calculates the time consumption and restores the program running environment after the coloring is completed. Through the system designed in this way, the coloring efficiency can be improved, different coloring schemes can be flexibly selected, the compatibility is strong, and it is easy to maintain and debug. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.

[0044] Figure 1 The full-element dynamic random coloring system diagram designed for this purpose;

[0045] Figure 2 The logic diagram for the dynamic random coloring of all elements in this design.

[0046] The realization of the objectives, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0047] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0048] It should be noted that all directional indications in the embodiments of the present application (such as up, down, left, right, front, back, etc.) are only used to explain the relative position relationship, movement status, etc. between the various components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.

[0049] In addition, the descriptions of "first", "second", etc. in this application are for descriptive purposes only and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of such features. In addition, "and / or" in the full text includes three solutions. Taking A and / or B as an example, it includes technical solution A, technical solution B, and technical solution that satisfies both A and B. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in this field to implement them. When the combination of technical solutions is mutually contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by this application.

[0050] See also Figure 1-Figure 2 This design provides a method and system for dynamic random coloring of all primitives. In order to understand this design more clearly, we first introduce the dynamic random coloring system of all primitives.

[0051] A full-element dynamic random coloring system includes: a parameter initialization module, a layer screening module, an element screening module, a random seed generation module, an element coloring module, and an environment restoration module.

[0052] The parameter initialization module is responsible for initializing various parameters required for program operation, including the run counter, CAD document object, command echo settings, graphic regeneration mode, start time, CAD software version, whether it is ZWCAD, and document save status; the initialization parameters specifically include initializing the run counter to 0, obtaining the current CAD document object, recording the current command echo settings and graphic regeneration mode, recording the program start time, obtaining the CAD software version, such as determining whether it is ZWCAD, and checking whether the current CAD document has been saved.

[0053] The layer filtering module includes the getExcludedLayers function, which is used to obtain the excluded layer list and generate a layer filter based on the excluded layer list;

[0054] The element screening module uses the element type filter to filter out the element set that meets the conditions, and further excludes the elements in the exclusion layer to obtain a list of valid element names and the number of valid elements;

[0055] The random seed generation module generates random seeds based on factors such as user running time, running counter, CAD document file size, number of valid primitives and document save status, and updates the running counter; specifically,

[0056] User timer value: Gets the value of the user timer with an accuracy of 0.1 second. This value changes over time, introducing changes in the time dimension as a random factor.

[0057] Run counter value: Used to record the number of times the program has been run. This value increments each time the program is run, allowing the random factor to vary between runs.

[0058] File size: First try to get the full path of the document. If it can be obtained, get the file size. If the full path cannot be obtained, the file size is set to 0. The file size factor associates the random factor with the document.

[0059] Entity quantity factor: It participates in the calculation of the random factor as a fixed value, adding the characteristic of entity quantity to the random factor.

[0060] Coordinate characteristic factor: reflects the characteristic information related to the coordinates and will also be included in the calculation of the random factor.

[0061] The user timer value, run counter value, file size, entity number factor, and coordinate characteristic factor are summed to create a unique random factor. This integration of multiple factors ensures the uniqueness of the random factor under different operating environments and conditions. A linear congruential algorithm is used to multiply the composite random factor by a constant and then modulo it to generate a random seed. This algorithm generates a sequence with a certain degree of randomness while maintaining computational speed. The global counter is incremented by 1 to record the number of program runs, helping to track the program's running status and providing a different run counter value for the next run.

[0062] The primitive coloring module dynamically and randomly colors valid primitives and sets the primitive colors in different ways according to the CAD software version and type. The primitive coloring module specifically includes the following parts.

[0063] Initialization part: includes opening the undo group to support undoing all shading operations at once, turning off command echo and automatic regeneration to improve execution speed, and outputting a startup prompt to indicate that the shading engine has started.

[0064] Selection set check part: Checks whether the selection set exists and whether the number of entities is greater than 0. If the conditions are met, the entity processing flow will be entered; otherwise, a prompt will be output that no valid object was found.

[0065] Entity processing part: a. Loop processing, looping through each entity in the selection set; b. Random seed update, updating the random seed for each entity to ensure that the coloring randomness of each entity is independent; c. Color index generation, generating a color index between 1 and 255 based on the random seed; d. Version compatibility processing, selecting different coloring methods according to the CAD version; for 2010 and above versions, try to use the VLA method first; if it fails, use the traditional entmod method; for other versions, directly use the traditional entmod method, and call two underlying functions according to different versions to modify the characteristics. The VLA method and the entmod method are both used to modify some attributes of the graphics element.

[0066] Result output part: calculate and output the processing time; time calculation, after the entity processing is completed, calculate the time consumed by the shading processing, accurate to 0.01 seconds; prompt information output, output the processing completion information and time consumption in the command line.

[0067] Ending part: End the undo group, restore system parameters, restore variables to initial values, and restore command echo and automatic regeneration functions.

[0068] After completing the shading of all primitives, the environment restoration module calculates the total time taken by subtracting the start time from the current time and converting it to seconds. It then ends the undo mark and restores the command echo and graphics regeneration modes, prompting the user to enter commands again to rerun the program.

[0069] The parameter initialization module provides basic parameters for subsequent modules. The layer screening module and the primitive screening module are responsible for screening out the primitives that need to be colored. The random seed generation module provides random seeds for primitive coloring. The primitive coloring module dynamically and randomly colors the primitives. The environment recovery module calculates the time consumption and restores the program running environment after the coloring is completed.

[0070] This design also provides a method for dynamic random coloring of all primitives, which includes the following steps: step 1, initialization parameters; step 2, obtaining a list of excluded layers; step 3, generating layer filters and primitive type filters; step 4, screening primitives; step 5, generating random seeds, step 6, dynamic random coloring; step 7, calculating time consumption and restoring the environment. Each step will be explained in detail below.

[0071] Step 1: Initialize parameters. Specifically, we initialize the run counter to 0, obtain the current CAD document object, record the current command echo settings and graphics regeneration mode, record the program start time, obtain the CAD software version (e.g., determine if it is ZWCAD), and check whether the current CAD document has been saved. First, open CAD and load the full-element dynamic random shading program in the CAD command line. The CAD drawing already has some line drawings.

[0072] Step 2: In order to avoid operating on some layers that do not need to be colored, you need to obtain a list of excluded layers, including the following steps:

[0073] Define the function getExcludedLayers, which accepts the CAD document object doc as a parameter;

[0074] Inside the function, get the document's layer collection through the getExcludedLayers function;

[0075] Iterate over the layer collection and for each layer, check its frozen, locked, and open status; if the layer is frozen, locked, or closed, add its name to the list of excluded layers;

[0076] Returns a list of excluded layers.

[0077] In step 3, a layer filter is generated based on the exclusion layer list. If the exclusion layer list is not empty, the exclusion layer names are connected with commas and preceded by a symbol (such as a ~ symbol). If the exclusion layer list is empty, the layer filter is set to empty, indicating that all layers are selected.

[0078] At the same time, define the primitive type filter. The primitive type filter is a list that contains logical operators and primitive type information, which is used to exclude some primitive types that do not need to be shaded. Primitive types that do not need to be shaded include VPORT (view window), LAYER (layer), DIMENSION (dimension), etc.

[0079] Step 4: Filter out the qualified element set according to the element type filter. If the filtering is successful, obtain the length of the element set, which represents the total number of filtered objects. Then, further process the filtered elements, exclude the elements in the exclusion layer, obtain a list of valid element names, and calculate the number of valid elements.

[0080] Step 5: Generate a random seed, which includes the following factors: user running time, running counter, CAD document file size, number of valid primitives, coordinate eigenvalues, and document save status. Then, a random seed is generated through a linear congruential algorithm, and finally the global running counter is incremented by 1.

[0081] Step 6. Before dynamic random coloring, enable the undo flag, turn off command echo and graphics regeneration mode. If the valid primitive name list is not empty and the number of valid primitives is greater than 0, then dynamically random color each valid primitive. The specific steps are as follows:

[0082] Traverse the list of valid primitive names;

[0083] For each primitive, generate a new random seed based on the current random seed and calculate the color index, which ranges from 1 to 255.

[0084] Depending on the version and type of CAD software, choose different methods to set the color of the graphics element.

[0085] Step seven, after step six, it is necessary to calculate the time taken and restore the environment; calculate the total time taken by the program, then end the undo mark, restore the command echo and graphics regeneration mode, prompt the user to re-run the program again, and repeat the above process, which will not be described again.

[0086] This design has the following beneficial effects:

[0087] (1) Improve coloring efficiency

[0088] The present invention dynamically and randomly colors all primitives in an automated manner, avoiding the tedious process of manually setting the colors of primitives one by one, greatly improving coloring efficiency. It can significantly shorten the coloring time, especially for complex CAD drawings containing a large number of primitives.

[0089] (2) Enhanced flexibility

[0090] Random Coloring mode assigns random colors to each element, allowing for dynamic adjustments based on different design requirements and scenarios, enhancing the flexibility of element coloring. Run the program multiple times as needed to achieve different coloring effects to meet your individual design needs.

[0091] (3) Strong compatibility

[0092] The present invention takes into account the differences between different CAD software versions and types. By judging the CAD software version and whether it is ZWCAD, different methods are selected to set the primitive color, which has strong compatibility.

[0093] (4) Improved error handling

[0094] During the program running process, an error handling function error is defined, which can handle exceptions in a timely manner, restore the normal running environment of the program, and output error information to facilitate user debugging and maintenance.

[0095] The above description is only a preferred embodiment of the present application and does not limit the patent scope of the present application. All equivalent structural transformations made by using the contents of the present application description and drawings under the inventive concept of the present application, or direct / indirect application in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A method for dynamic random coloring of all primitives, characterized in that: The following steps are involved: Step 1: Initialize parameters; Step 2: Get the excluded layer list; Step 3: Generate layer filters and primitive type filters; Step 4: Filter the graphics elements; Step 5: Generate a random seed; Step 6: Dynamic random coloring.

2. The method for dynamic random coloring of all primitives according to claim 1, characterized in that: The initialization parameters specifically include initializing the running counter to 0, obtaining the current CAD document object, recording the current command echo settings and graphics regeneration mode, recording the program start time, obtaining the CAD software version, and checking whether the current CAD document has been saved.

3. The method for dynamic random coloring of all primitives according to claim 1, characterized in that: Getting the exclusion layer list includes the following steps: Define the function getExcludedLayers, which accepts the CAD document object doc as a parameter; Get the document's layer collection through the getExcludedLayers function; Iterate over the layer collection and for each layer, check its frozen, locked, and open status; if the layer is frozen, locked, or closed, add its name to the list of excluded layers; Returns a list of excluded layers.

4. The method for dynamic random coloring of all primitives according to claim 1, characterized in that: In step 3, a layer filter is generated based on the exclusion layer list. If the exclusion layer list is not empty, the exclusion layer names are connected with commas and preceded by a symbol; If the Exclude Layers list is empty, set the layer filter to empty, meaning all layers are selected; At the same time, define the primitive type filter, which is a list containing logical operators and primitive type information, and is used to exclude some primitive types that do not need to be colored.

5. The method for dynamic random coloring of all primitives according to claim 1, characterized in that: In step 4, the element set that meets the conditions is filtered out according to the element type filter. If the filtering is successful, the length of the element set is obtained, which represents the total number of filtered objects. Then, the filtered elements are further processed to exclude the elements in the exclusion layer, obtain a list of valid element names, and calculate the number of valid elements.

6. The method for dynamic random coloring of all primitives according to claim 1, characterized in that: The generation of the random seed in step 5 includes the following factors: user running time, running counter, CAD document file size, number of valid primitives, coordinate eigenvalues and document save status. The random seed is then generated through the linear congruential algorithm, and finally the global running counter is incremented.

7. The method for dynamic random coloring of all primitives according to claim 1, characterized in that: Before dynamic random coloring, enable the undo flag, turn off command echo and graphics regeneration mode, and if the valid primitive name list is not empty and the number of valid primitives is greater than 0, perform dynamic random coloring on each valid primitive. The specific steps are as follows: Traverse the list of valid primitive names; For each primitive, generate a new random seed based on the current random seed and calculate the color index, which ranges from 1 to 255. Depending on the version and type of CAD software, choose different methods to set the color of the graphics element.

8. The method for dynamic random coloring of all primitives according to claim 1, characterized in that: After step six, it is necessary to calculate the time consumption and restore the environment; calculate the total time consumption of the program, then end the undo mark, restore the command echo and graphics regeneration mode, and prompt the user to re-run the program again.

9. A full-element dynamic random coloring system, characterized in that: include: The parameter initialization module is responsible for initializing various parameters required for program operation, including the running counter, CAD document object, command echo settings, graphics regeneration mode, start time, CAD software version, whether it is ZWCAD, and document save status; The layer filtering module includes the getExcludedLayers function, which is used to obtain the excluded layer list and generate a layer filter based on the excluded layer list; The element screening module uses the element type filter to filter out the element set that meets the conditions, and further excludes the elements in the exclusion layer to obtain a list of valid element names and the number of valid elements; The random seed generation module generates random seeds based on factors such as user running time, running counter, CAD document file size, number of valid primitives and document save status, and updates the running counter; The primitive coloring module dynamically and randomly colors valid primitives and sets the primitive colors in different ways according to the CAD software version and type; The environment recovery module calculates the total time consumed by the program, ends the undo mark, restores the command echo and graphics regeneration mode, and prompts the user to run the program again.

10. The full-element dynamic random coloring system according to claim 9, characterized in that: The primitive shading module consists of the following parts: Initialization part: including opening undo groups, closing command echo and automatic regeneration, and outputting startup prompts; Selection set check part: Check whether the selection set exists and whether the number of entities is greater than 0. If the conditions are met, enter the entity processing process; Otherwise, it will output a prompt that no valid object is found; Entity processing part: a. Loop processing, looping through each entity in the selection set; b. Random seed update, updating the random seed for each entity; c. Color index generation, generating a color index between 1 and 255 based on the random seed; d. Version compatibility processing, select different coloring methods according to the CAD version; Result output part: calculate and output processing time; Ending part: End the undo group and restore system parameters.