Method for processing CNC machining program variable based on EXCEL table VBA macro command
By processing CNC plus engineering variables based on the VBA macro command of the EXCEL table, the problems of large engineering volume and high error probability caused by manual variable addition and logical calculation are solved, and automated processing is realized, improving efficiency and accuracy.
Patent Information
- Application Number
- CN202411714720.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-03-07
AI Technical Summary
In the prior art, the problems of large engineering volume and high error probability caused by manual variable addition and logical calculation in CNC-plus engineering design.
The CNC plus engineering variables are processed using the method based on the VBA macro command of the EXCEL table. The conventional CNC plus engineering formula is analyzed and designed through the CNC processing software. After the format is sorted, the EXCEL table is imported. The preset VBA macro command is used to calculate and process it, and the variables are added and the CNC plus engineering formula of the adjusted format is exported.
The CNC plus engineering method is realized, which reduces the engineering volume of manual variable addition and logical calculation, improves processing efficiency and accuracy, and reduces the risk of errors.
Smart Images

Figure CN119575877A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of numerical control machining, and in particular to a method for processing CNC machining formula variables based on EXCEL table VBA macro commands. Background Art
[0002] CNC (Computer Numerical Control) is a technology that uses computers to control machine tools for machining parts. CNC machines, also known as numerically controlled (NC) machines, can be programmed to precisely control tool movement, allowing the tool to cut along a predetermined path and speed, thereby producing a variety of complex parts and products. CNC technology is widely used in the manufacturing industry, including automotive, aerospace, molds, electronics, and other fields. The advantages of CNC machining include high precision, high efficiency, and high flexibility.
[0003] A CNC program refers to a set of instructions for computer numerical control (CNC) programming, a programming language that uses G-code and M-code to control machine tool motion and perform other tasks. CNC programming also includes macro instructions, which allow users to create more complex programs using variables and expressions. In a macro program, variables are specified using a variable symbol followed by the variable number, while expressions must be enclosed in parentheses. Prior art requires engineers to manually enter a large amount of information, such as tool number, tool length, tool name, machining time, and machining depth, when creating CNC setup sheets for CNC machining center operators. This amount of information is particularly significant when programming complex workpieces. This leads to low programming efficiency, requiring significant time to organize data within the software program. Manually entering all the required setup sheets requires further verification and confirmation. Due to the large amount of information and the complexity of the information, human error is inevitable, which can lead to subsequent machining quality issues and even damage to the CNC machining center machine.
[0004] Based on this, Chinese patent CN112800733A discloses a method for automatically importing CNC setting sheet information based on CAMworks, including the following steps: 1: compile an XSL file through the XML document generated by CAMworks software, and input the required HTML table data; 2: develop a CNC setting sheet template file in Excel file format; 3: define the mapping relationship between the new setting sheet and the required data between the XML file in S1; 4: use a combination of various Excel file functions to process the data in S3; this technical solution realizes an automated process from software generation of process data files to one-click loading and subsequent processing of data, greatly reducing the links of human participation, being simple and easy to use, and using the program settings of Excel functions to realize intelligent error reporting of key data, ensuring accurate and efficient results.
[0005] However, the aforementioned method for automatically importing CNC setup sheet information based on CAMworks still has the technical problem of being unable to automatically calculate and add variables to the CNC program. Specifically, current CNC machining formulas are all written by machining software. For example, mainstream programming software used for CNC machining includes UG, Mastercam, etc., and existing machining software programming all refers to a pre-imported 3D contour that has been designed using a computer program to perform the program writing steps. However, in the actual CNC production process, especially in the process flow of CNC high-gloss products, due to the actual production size of the product, contour deformation factors, and normal tolerance fluctuations in the mass production process, there will be differences between the actual size of each processed product and the aforementioned preset 3D contour. In this case, a probe or stylus is needed to measure the corresponding position of the workpiece. The value measured by the probe needs to be compensated to the variables of the CNC machining formula accordingly, so that the CNC machining can be better carried out according to the actual contour of the product during the actual CNC machining. Furthermore, to ensure smooth connection between compensation values at each point, the program needs to be divided into many small segments, for example, each segment is approximately 0.05mm. At the same time, corresponding variable logic calculations and additions need to be performed for each segment. Furthermore, due to the dense number of program points, programs typically have thousands to tens of thousands of segments. Manually adding variables and performing logic calculations for each segment would result in a massive engineering effort and technical challenges. Currently, it is difficult to manually calculate and add variables for programs with tens of thousands of segments. Summary of the Invention
[0006] Based on this, it is necessary to provide a method for processing CNC machining formula variables based on EXCEL table VBA macro commands to address the technical problem of large engineering workload caused by manual variable addition and logical calculation in CNC machining formula design.
[0007] A method for processing CNC machining formula variables based on EXCEL table VBA macro commands, comprising the following steps:
[0008] S1: Use CNC machining software to analyze and design the 3D model of the workpiece to be CNC machined and output the conventional CNC machining formula;
[0009] S2: Format the conventional CNC machining program;
[0010] S3: Open the preset EXCEL table and import the formatted conventional CNC machining formula into the EXCEL table;
[0011] S4: Starting a VBA macro command preset in the EXCEL table to calculate and process the imported conventional CNC machining formula, so that variables are added to the CNC machining formula;
[0012] S5: Export the calculated CNC machining formula from the EXCEL table, and adjust the format of the exported CNC machining formula again.
[0013] Furthermore, in step S4, the specific steps of calculating and processing the imported conventional CNC machining formula by using the VBA macro command preset in the EXCEL table include:
[0014] S41: The preset VBA macro command first searches and fills each row of the imported CNC machining program so that the X, Y, Z and B positions of each row of the CNC machining program have values;
[0015] S42: performing calculations on the probe points within the preset interval, determining an axis with a larger variable between two adjacent probe points, calculating a difference between the measured values of adjacent probe points in the current section, and selecting the axis with the larger variable;
[0016] S43: performing a start-end point calculation on the selected axis to obtain the total running distance of the current segment, that is, the total moving length between the two probe point segments;
[0017] S44: Calculate the distance between the position point corresponding to each line of the program and the starting point one by one to obtain the length of the current position point relative to the starting point of this section;
[0018] S45: Calculate the variable compensation value according to the formula: variable compensation value = length of the current position point relative to the starting point of this segment / total movement length between two probe points * difference between the measurement values of adjacent probe points in the current segment to obtain the variable compensation value;
[0019] S46: adding the variable compensation value to the corresponding position of the imported CNC machining program;
[0020] S47: Repeat steps S42 to S46 until all preset rows of the imported CNC machining program have completed the addition of variable compensation values.
[0021] Furthermore, in step S42, a method for determining which axis has a larger movement distance between adjacent detection points, the X-axis or the Y-axis, and calculating and selecting the axis with the larger distance as the axis of the total length base includes the following steps:
[0022] S421: Automatically select a starting point or direction for processing;
[0023] S422: Preparation before judgment, including: judging the current detection point, recording the row of the previous detection point, the length in the X direction, the length in the Y direction, and accumulating detection points, etc.;
[0024] S423: Calculate and record: X-direction movement distance = X-end point - X-start point, Y-direction movement distance = Y-end point - Y-start point;
[0025] S424: If the movement distance in the X direction is greater than or equal to the movement distance in the Y direction, execute step S425; otherwise, execute step S426;
[0026] S425: Determine and select the direction of the X probe point, and record the starting point of the X probe point;
[0027] S426: Determine and select the direction of the Y probe point, and record the starting point of the Y probe point.
[0028] Furthermore, in step S45, the method of calculating the variable compensation value and adding the variable compensation value to the original CNC machining formula is as follows:
[0029] S451: Import the values of the original CNC machining formula respectively; including the values of the original CNC machining formula, the number of the current segment probe point, the difference between the measurement values of adjacent probe points in the current segment, the length of the current position point relative to the starting point of the current segment, and the total movement length between the two probe point segments;
[0030] S452: Add the value of the original CNC machining formula to the calculated variable compensation value, i.e., the program replacement value = the original CNC machining formula value + the current probe point number + the difference between the measured values of adjacent probe points in the current segment * (the length of the current position point relative to the starting point of this segment / the total movement length between the two probe points);
[0031] S453: Replace the program value with the value corresponding to the original CNC machining program
[0032] In summary, the present invention discloses a method for processing CNC machining formula variables based on an Excel spreadsheet VBA macro command. The method first uses CNC machining software to analyze and design a 3D model of a workpiece to be CNC machined and outputs a conventional CNC machining formula. The conventional CNC machining formula is then formatted. A preset Excel spreadsheet is then opened, and the formatted conventional CNC machining formula is imported into the Excel spreadsheet. A preset VBA macro command in the Excel spreadsheet is activated to calculate and process the imported conventional CNC machining formula, thereby adding variables to the CNC machining formula. Finally, the calculated CNC machining formula is exported from the Excel spreadsheet and the exported CNC machining formula is formatted again. Thus, the CNC machining formula can be corrected and compensated based on measured values. Therefore, the present invention solves the technical problem of the large amount of work involved in CNC machining formula design due to manual variable addition and logical calculations. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 A flow chart of a method for processing CNC machining formula variables based on EXCEL spreadsheet VBA macro commands applicable to the present invention;
[0034] Figure 2 The figure is a schematic diagram of a CNC machining trajectory that can be applied to the method of processing CNC machining formula variables based on EXCEL table VBA macro commands of the present invention. DETAILED DESCRIPTION
[0035] To make the above-mentioned objects, features, and advantages of the present invention more readily apparent, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings. The following description sets forth numerous specific details to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways than those described herein, and those skilled in the art may make similar modifications without departing from the scope of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0036] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise", "axial", "radial", "circumferential" and the like to indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as limiting the present invention.
[0037] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of the technical features being referred to. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In the description of the present invention, "plurality" means at least two, such as two, three, etc., unless otherwise specifically defined.
[0038] In the present invention, unless otherwise specified or limited, the terms "installed," "connected," "connect," "fixed," etc. should be understood in a broad sense. For example, they can refer to fixed connection, detachable connection, or integration; mechanical connection, electrical connection; direct connection, or indirect connection through an intermediate medium; internal communication between two components, or interaction between two components, unless otherwise specified. Those skilled in the art will understand the specific meanings of the above terms in the present invention based on specific circumstances.
[0039] In the present invention, unless otherwise expressly specified or limited, when a first feature is "above" or "below" a second feature, it may mean that the first and second features are in direct contact, or that the first and second features are in indirect contact through an intermediary. Furthermore, when a first feature is "above," "above," or "above" a second feature, it may mean that the first feature is directly above or diagonally above the second feature, or simply means that the first feature is at a higher level than the second feature. When a first feature is "below," "below," or "below" a second feature, it may mean that the first feature is directly below or diagonally below the second feature, or simply means that the first feature is at a lower level than the second feature.
[0040] It should be noted that when an element is referred to as being "fixed to" or "disposed on" another element, it may be directly on the other element or there may be an intermediate element. When an element is considered to be "connected to" another element, it may be directly connected to the other element or there may be an intermediate element. The terms "vertical," "horizontal," "upper," "lower," "left," "right," and similar expressions used herein are for illustrative purposes only and do not represent the only implementation methods.
[0041] For details, please refer to Figure 1 The present invention provides a method for processing CNC machining formula variables based on EXCEL table VBA macro commands, which includes the following steps:
[0042] S1: Use CNC machining software to analyze and design the 3D model of the workpiece to be CNC machined and output the conventional CNC machining formula;
[0043] S2: Format the conventional CNC machining program;
[0044] S3: Open the preset EXCEL table and import the formatted conventional CNC machining formula into the EXCEL table;
[0045] S4: Starting a VBA macro command preset in the EXCEL table to calculate and process the imported conventional CNC machining formula, so that variables are added to the CNC machining formula;
[0046] S5: Export the calculated CNC machining formula from the EXCEL table, and adjust the format of the exported CNC machining formula again.
[0047] Specifically, at present, for the automatic CNC machining of workpieces, especially the CNC process of surface highlight machining of workpieces, the CNC machining programs corresponding to the workpieces are all designed and written by software. At present, the mainstream CNC programming software includes UG, Mastercamd, etc.
[0048] Existing CNC machining software is programmed using the 3D model of the workpiece being machined as a benchmark for CNC programming. Specifically, when designing a workpiece, 3D modeling software can be used to design its contour, shape, and structure to obtain a designed 3D model. However, the actual contour, shape, and structure parameters of the workpiece produced based on the designed 3D model differ from those of the corresponding designed 3D model. This is because, during the actual production process, the workpiece's actual dimensions and contours can differ from the standard dimensions in the corresponding designed 3D model due to structural deformation and normal tolerance fluctuations during mass production. For example, the cavity of an injection mold obtained using the designed 3D model of a workpiece can deform during the molding process due to objective factors such as shrinkage of the plastic material, resulting in deformation of the plastic workpiece. Consequently, the resulting plastic workpiece will inevitably have differences in contour, dimensions, and other parameters from its corresponding designed 3D model. For example, in the forming processes of metal workpieces such as stamping, stretching or die-casting, due to factors such as material deformation, the metal workpiece made by the mold made according to the designed 3D model of the metal workpiece will inevitably have differences in parameters such as contour and size between it and its corresponding designed 3D model.
[0049] For this reason, before CNC machining begins, a probe is used to measure the actual dimensions, contours, and other parameters of the workpiece being machined. The actual values of the workpiece's parameters are then compared with those of the corresponding designed 3D model to determine the difference between the two. Consequently, probes are frequently used in the CNC machining of high-gloss products, especially high-gloss plastics.
[0050] Furthermore, after using a probe to measure and compare the parameter differences of the workpiece to be machined, these differences need to be compensated within the CNC machining formula within the CNC machining process. This allows the CNC machining formula to perform machining based on the 3D model parameters obtained through actual measurement and calibration of the compensation variables. However, in the prior art, adding compensation to CNC machining formulas relies on manual work by engineers or equipment operators, relying on manual calculations and variable addition line by line. This is barely sufficient when CNC machining has a relatively small number of steps. However, in scenarios where machining steps, such as CNC highlighting of workpiece surfaces, increase dramatically, the number of CNC machining steps per workpiece can easily reach tens of thousands, making manual work difficult. Furthermore, this manual addition method also presents a high probability of error. Therefore, the present invention proposes a method for processing CNC machining formula variables based on Excel spreadsheet VBA macros. This method can perform batch calculations and processing on CNC machining formulas, thereby addressing the technical issues of the large workload and high probability of error caused by manual variable addition and logical calculations.
[0051] Specifically, in a specific embodiment, a conventional CNC machining formula obtained by using CNC machining software based on the designed 3D model of the workpiece is as follows:
[0052] G01 X10.Y10.F500.;
[0053] After calculating and processing the above CNC machining formula using the method of processing CNC machining formula variables based on EXCEL table VBA macro commands of the present invention, the obtained CNC machining formula is as follows:
[0054] G01 X10[10.+#501]Y10[10.+#601]F500.;
[0055] In the above formula, #501 is the difference between the actual value measured by the probe and the design value of the 3D model used during programming. Similarly, #601 is the difference between the actual value measured by the probe and the design value of the 3D model used during programming. By adding these differences, or variables, to the CNC machining formula, the measured values of the workpiece can be used to perform CNC machining, ensuring that the resulting workpiece meets the requirements.
[0056] Furthermore, in the aforementioned step S4, the specific steps of calculating and processing the imported conventional CNC machining formula by using the VBA macro command preset in the EXCEL table are as follows:
[0057] S41: The preset VBA macro command first searches and fills each row of the imported CNC machining program so that the X, Y, Z and B positions of each row of the CNC machining program have values;
[0058] S42: performing calculations on the probe points within the preset interval, determining an axis with a larger variable between two adjacent probe points, calculating a difference between the measured values of adjacent probe points in the current section, and selecting the axis with the larger variable;
[0059] S43: performing a start-end point calculation on the selected axis to obtain the total running distance of the current segment, that is, the total moving length between the two probe point segments;
[0060] S44: Calculate the distance between the position point corresponding to each line of the program and the starting point one by one to obtain the length of the current position point relative to the starting point of this section;
[0061] S45: Calculate the variable compensation value according to the formula: variable compensation value = length of the current position point relative to the starting point of this segment / total movement length between two probe points * difference between the measurement values of adjacent probe points in the current segment to obtain the variable compensation value;
[0062] S46: adding the variable compensation value to the corresponding position of the imported CNC machining program;
[0063] S47: Repeat steps S42 to S46 until all preset rows of the imported CNC machining program have completed the addition of variable compensation values.
[0064] Specifically, in the aforementioned step S42, a method for determining which axis has a larger movement distance between adjacent detection points in the X-axis or Y-axis direction, and calculating and selecting the axis with the larger distance as the axis of the total length base is:
[0065] S421: Automatically select a starting point or direction for processing;
[0066] S422: Preparation before judgment, including: judging the current detection point, recording the row of the previous detection point, the length in the X direction, the length in the Y direction, and accumulating detection points, etc.;
[0067] S423: Calculate and record: X-direction movement distance = X-end point - X-start point, Y-direction movement distance = Y-end point - Y-start point;
[0068] S424: If the movement distance in the X direction is greater than or equal to the movement distance in the Y direction, execute step S425; otherwise, execute step S426;
[0069] S425: Determine and select the direction of the X probe point, and record the starting point of the X probe point;
[0070] S426: Determine and select the direction of the Y probe point, and record the starting point of the Y probe point.
[0071] The specific implementation methods are as follows:
[0072] Automatically select direction / starting point output
[0073] CMX2=0'Judge the current detection point
[0074] CMX3=0'Record the line of the last detection point
[0075] CMX4=0'X direction length
[0076] CMX5=0'Y direction length
[0077] For CMX1=3To CMX60
[0078] If Worksheets("Single Track").Range("W"&CMXl).Value=""Then GoTo N7
[0079] CMX2=CMX2+1
[0080] If CMX2>1Then'Start from the second probe point
[0081] CMX4=Abs(Worksheets((" Single Track").Range("K"&CMX1).Value-Worksheets(" Single Track").Range("K"&CMX3).Value)*l00'X end point-X start point=X direction movement distance CMX5=Abs(Worksheets(" Single Track").Range("M"&CMX1).Value-Worksheets(" Single Track").Range("M"&CMX3).Value)*l00Y end point-Y start point=Y direction movement distance
[0082] If CMX4>=CMX5Then'CMX4 is the X-axis movement distance, CMX5 is the Y-axis movement distance, when the X-axis is larger, the line is pulled down, and when the Y-axis is larger, the line after ELSE is executed
[0083] Worksheets("Single Track").Range("AE"&CMX3).Value="X"X probe point direction determination, when the X axis is large, select the X axis
[0084] Worksheets(" Single Track").Range("AF"&CMX3).Value = Worksheets(" Single Track").Range("K"&CMX3).Value'X probe point starting point record
[0085] Worksheets("Single Track").Range("AE"&CMXl).Vaue="X"X probe point direction determination, fill in the last probe point in the current direction
[0086] Worksheets(" Single Track").Range("AF"&CMXl).Value=Worksheets(" Single Track").Range("K"&CMXl).Value'X probe point starting point current direction to fill in the last probe point
[0087] Else
[0088] Worksheets("Single Track").Range(("AE"&CMX3).Value="Y"'Y probe point direction determination, when the Y axis movement distance is large, select the Y axis
[0089] Worksheets(("Single Track").Range("AF"&CMX3).Value=Worksheets("Single Track").Range("M"&CMX3).Value'Y-axis starting point record
[0090] Worksheets("Single Track").Range("AE"&CMXI).Value="Y"'Y probe point direction determines the current direction and fills in the last probe point
[0091] Worksheets(" Single Track").Range("AF"&CMX1).Value=Worksheets(" Single Track").Range("M"&CMX1).Value'Y probe point starting point current direction to fill in the last probe point
[0092] End If
[0093] End If
[0094] CMX3 CMX1
[0095] N7:
[0096] Next
[0097] Furthermore, in the aforementioned step S43, the specific implementation of performing the start-end point calculation on the selected axis to obtain the total running distance of the current segment is as follows:
[0098] CMX2 = 0 column X or Y
[0099] CMX3=0'Confirm the starting point
[0100] CMX4=3'previous line number
[0101] For CMX1=CMX57 To CMX59
[0102] If Worksheets(("Single Track").Range("AE"&CMXl).Value="Then GoTo N8
[0103] CMX3=CMX3+1
[0104] If Worksheets("Single Track").Ranget("AE"&CMX4).Value="X"Then' The previous program segment has recorded the starting point and whether X or Y is selected as the base. Here, the above settings are determined;
[0105] CMX2=0
[0106] Else
[0107] CMX2=2
[0108] End If
[0109] If CMX3>=2Then
[0110] Worksheets(("Single Track").Range("AG"&CMX4).Value=Abs(Worksheets(("Single Track").Cells(CMXl,Il+CMX2)-Worksheets("Single Track").Range("AF"&
[0111] CMX4).Vue)*100' length calculation, the length position calculation of the axis movement between two adjacent detection points;
[0112] End If
[0113] CMX4 CMX1
[0114] N8:
[0115] Next
[0116] Furthermore, in the aforementioned step S44, the distances of the position points corresponding to each line of the equation relative to the starting point are calculated one by one to obtain the length of the current position point relative to the starting point of the current segment. The specific implementation method is:
[0117] CMX2=0' X or Y column
[0118] CMX3=0' starting point
[0119] CMX4=0' length
[0120] CMX5=0'Probe variable
[0121] CMX6=0'Current length
[0122] For CMX1=CMX57 To CMX59
[0123] If Worksheets("Single Track").Range("AF"&CMX1).Value◇"Then
[0124] CMX3 = Worksheets ("Single Track").Range ("AF" & CMXl).Value'Starting point
[0125] CMX5=Worksheets("Single Track").Range("W"'&CMXl).Value'Explore Point
[0126] CMX6 = Vorksheets("Single Track").Range("AG"&CMX1).Value'length
[0127] If Worksheets("Single Track").Range("AE"&CMXl).Value="X"Then
[0128] CMX2=0
[0129] Else
[0130] CMX2=2
[0131] End If
[0132] End If
[0133] Worksheets("Single Track").Range("AH"&CMX1).Value=Abs(Worksheets("Single Track").Cells(CMX1,11+CMX2)-CMX3)*l00'What is the length of the current point relative to the starting point of the current segment?
[0134] Worksheets("Single Track").Range("W"&CMX1).Value=CMX5'Probe point variable
[0135] Vorksheets("Single Track").Range("AG"&CMX1).Value=CMX6'Length
[0136] Next
[0137] Furthermore, in the aforementioned step S45, the variable compensation value is calculated according to the formula: variable compensation value = the length of the current position point relative to the starting point of the current segment / the total movement length between the two probe points * the difference between the measurement values of adjacent probe points in the current segment. The method for obtaining the variable compensation value is as follows:
[0138] S451: Import the values of the original CNC machining formula respectively; including the values of the original CNC machining formula, the number of the current segment probe point, the difference between the measurement values of adjacent probe points in the current segment, the length of the current position point relative to the starting point of the current segment, and the total movement length between the two probe point segments;
[0139] S452: Add the value of the original CNC machining formula to the calculated variable compensation value, i.e., the program replacement value = the original CNC machining formula value + the current probe point number + the difference between the measured values of adjacent probe points in the current segment * (the length of the current position point relative to the starting point of this segment / the total movement length between the two probe points);
[0140] S453: Replace the numerical value corresponding to the original CNC machining formula with the program replacement value.
[0141] Furthermore, the specific implementation is as follows:
[0142] Y value variable calculation, final result calculation:
[0143] For CMX1=3To CMX60
[0144] CMX11 = Worksheets ("Single Track"). Range ("M" & CMX1). Value 'Y value of the original CNC machining formula
[0145] CMXl2=730+Worksheets("single track").Range("W"&CMXl).Value'current segment probe point number
[0146] CMX15=830+Worksheets("Single Track").Range("W"&CMXI).Value'The difference between the measured values of adjacent detection points in the current segment
[0147] CMX13=Round(Worksheets("Single Track").Range("AH"&CMXI).Value,I)'The position or length of the current point relative to the starting point of this segment
[0148] CMXl4=Round(Worksheets("Single Track").Range("AG"&CMXl).Value,1)'Total movement length between the current two probe points;
[0149] If Worksheets("Single Track").Range("AG"&CMXl).Value◇""Then
[0150] Worksheets("Single Track
[0151] ").Range("Y"&CMX1).Value="["&CMX11&"+"&"#"&CMX12&"+#"&CMX15&"*["&CMX13&" / "&CMX14&"]]"' Program Z value calculation: CMXI1 is the original CNC program Z value, + the existing variable calculation value;
[0152] Else
[0153] Worksheets("Single Track
[0154] ").Range("Y"&CMXl).Vaue="["&CMX11&"+"&"#"&CMXl2&"]"'Z value calculation
[0155] End If
[0156] Next
[0157] For further information, see Figure 2 In a specific embodiment, two measuring probes are designed, one at the starting point and one at the end point. In this processing trajectory, only the Z value is compensated. If it is defined that the length of this processing trajectory is 100mm; if the measurement value register variable at the starting point is: #1, and the measurement value register variable at the end point is #2; then, the measurement difference between the two can be calculated as: #3=#2-#1. At the same time, the actual measurement measured by the measuring probe: #1=0 (that is, the same as the design value); #2=0.1 (that is, the actual measurement value at this point is 0.1mm higher than the theoretical value); then #3=0.1-0.0=0.1
[0158] Therefore, if the machining trajectory is written into the CNC machining program according to the design value, the details are as follows:
[0159] X1.Y0.Z0
[0160] X2.Y0.Z0
[0161] X3.Y0.Z0
[0162] X4.Y0.Z0
[0163] X5.Y0.Z0
[0164] Based on the aforementioned CNC machining formula, after processing according to the method of processing CNC machining formula variables based on EXCEL spreadsheet VBA macro commands of the present invention, the CNC machining formula for adding variable compensation values is as follows:
[0165] X1.Y0.Z[0+1 / 100*#3]
[0166] X2.Y0.Z[0+2 / 100*#3]
[0167] X3.Y0.Z[0+3 / 100*#3]
[0168] X4.Y0.Z[0+4 / 100*#31]
[0169] X5.Y0.Z[0+5 / 100*#3]
[0170] In summary, the present invention discloses a method for processing CNC machining formula variables based on an Excel spreadsheet VBA macro command. The method first uses CNC machining software to analyze and design a 3D model of a workpiece to be CNC machined and outputs a conventional CNC machining formula. The conventional CNC machining formula is then formatted. A preset Excel spreadsheet is then opened, and the formatted conventional CNC machining formula is imported into the Excel spreadsheet. A preset VBA macro command in the Excel spreadsheet is activated to calculate and process the imported conventional CNC machining formula, thereby adding variables to the CNC machining formula. Finally, the calculated CNC machining formula is exported from the Excel spreadsheet and the exported CNC machining formula is formatted again. Thus, the CNC machining formula can be corrected and compensated based on measured values. Therefore, the present invention solves the technical problem of the large amount of work involved in CNC machining formula design due to manual variable addition and logical calculations.
[0171] Specifically, in CNC and high-gloss production and processing, some product surfaces have deformations, and in this case, a probe or stylus is needed to measure the corresponding position of the workpiece. The values measured by the probe need to be compensated to the program variables to better ensure that the processing is carried out according to the actual contour of the product. If the compensation values between points are to be completely smoothly connected, the program needs to be made into many small segments, for example, in units of about 0.05MM. At the same time, corresponding variable logic calculations and additions need to be performed for each segment. However, due to the dense program points, the program generally has thousands to tens of thousands of segments. Manual variable addition and logic calculations are required for each segment, which is a very large project. Currently, there is no purely manual method to complete the variable calculation and addition for programs with tens of thousands of segments.
[0172] The proposed method for processing CNC machining formula variables using Excel spreadsheet VBA macros allows for on-site adjustments based on actual needs, eliminating the time-consuming and error-prone manual additions. Furthermore, it requires only standard office software and a computer; VBA calculation methods and logic can be adjusted and modified to meet specific needs, offering high variability and scalability.
[0173] The aforementioned method is applicable to circular, annular, curved, oblique, and single-path machining. By programming the corresponding calculation logic in VBA, 100% accuracy is achieved, compared to the previous manual step-by-step variable addition process. Furthermore, this method can be applied to all products with irregular surface contours, such as CNC high-gloss chamfering, machining special-shaped workpieces, and thin-walled products, to improve machining quality.
[0174] The technical features of the above-mentioned embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above-mentioned embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0175] The above-described embodiments merely illustrate several implementations of the present invention, and while their descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent. It should be noted that a person skilled in the art would be able to make numerous variations and improvements without departing from the spirit of the present invention, all of which fall within the scope of protection of the present invention. Therefore, the scope of protection of the patent for this invention shall be determined by the appended claims.
Claims
1. A method for processing CNC machining formula variables based on EXCEL table VBA macro commands, characterized in that: It includes the following steps: S1: Use CNC machining software to analyze and design the 3D model of the workpiece to be CNC machined and output the conventional CNC machining formula; S2: Format the conventional CNC machining formula; S3: Open the preset EXCEL table, and import the formatted conventional CNC machining formula into the EXCEL table; S4: starting the VBA macro command preset in the EXCEL table to calculate and process the imported conventional CNC machining formula, so that variables are added to the CNC machining formula; S5: Export the calculated CNC machining formula from the EXCEL table, and adjust the format of the exported CNC machining formula again.
2. The method for processing CNC machining formula variables based on EXCEL table VBA macro commands according to claim 1, characterized in that: In step S4, the specific steps of calculating and processing the imported conventional CNC machining formula by using the VBA macro command preset in the EXCEL table include: S41: The preset VBA macro command first searches and fills each line of the imported CNC machining program, so that the positions of X, Y, Z and B of each line of the CNC machining program have values; S42: performing disassembly calculation on the detection points within the preset interval, determining the axis with the larger variable between two adjacent detection points, calculating the difference between the measurement values of adjacent detection points in the current section, and selecting the axis with the larger variable; S43: performing a start-end point calculation on the selected axis to obtain a total running distance of the current segment, that is, a total moving length between two detection point segments; S44: Calculate the distances of the position points corresponding to each line of the equation relative to the starting point one by one to obtain the length of the current position point relative to the starting point of this section; S45: Calculate according to the formula: variable compensation value = length of the current position point relative to the starting point of this section / total movement length between two probe point sections * difference value between the measurement values of adjacent probe points in the current section to obtain the variable compensation value; S46: adding the variable compensation value to the corresponding position of the imported CNC machining formula; S47: Repeat steps S42 to S46 until the variable compensation values are added to all preset rows of the imported CNC machining formula.
3. The method for processing CNC machining formula variables based on EXCEL table VBA macro commands according to claim 2, characterized in that: In step S42, a method for determining which axis has a larger movement distance between adjacent detection points, the X-axis or the Y-axis, and calculating and selecting the axis with the larger distance as the axis of the total length base comprises the following steps: S421: Automatically select a starting point or direction for processing; S422: Performing preparation before judgment, including: judging the current detection point, recording the row where the previous detection point is located, the length in the X direction, the length in the Y direction, and accumulating detection points, etc.; S423: Calculate and record: the movement distance in the X direction = the X end point - the X start point, the movement distance in the Y direction = the Y end point - the Y start point; S424: If the movement distance in the X direction is ≥ the movement distance in the Y direction, execute step S425; otherwise, execute step S426; S425: Determine and select the direction of the X probe point, and record the starting point of the X probe point; S426: Determine and select the direction of the Y probe point, and record the starting point of the Y probe point.
4. The method for processing CNC machining formula variables based on EXCEL table VBA macro commands according to claim 2, characterized in that: In step S45, the method of calculating the variable compensation value and adding the variable compensation value to the original CNC machining formula is as follows: S451: Import the values of the original CNC machining formula respectively; including the values of the original CNC machining formula, the number of the current segment probe point, the difference between the measurement values of adjacent probe points in the current segment, the length of the current position point relative to the starting point of this segment, and the total movement length between the two probe point segments; S452: Add the value of the original CNC machining formula to the calculated variable compensation value, that is, the program replacement value = the original CNC machining formula value + the current probe point number + the difference between the measured values of the adjacent probe points in the current segment * (the length of the current position point relative to the starting point of this segment / the total movement length between the two probe point segments); S453: Replace the numerical value corresponding to the original CNC machining formula with the program replacement value.
Citation Information
Patent Citations
Automatic importing method of CNC setting list information based on CAMworks
CN112800733A