Thread Content
This post was last edited by ssbpro on 2010-1-13 09:43 In the process of using Pro/E to design the pipeline system, in order to automatically extract the parameters of the pipeline, the real numbers used to drive the model need to be converted into strings and then output. For example, for DN20x2.8 steel pipes in GB 3091-2001 "Welded Steel Pipes for Low-Pressure Fluid Transport", the driving parameter for the model thickness is 2.8. http://images.cnblogs.com/cnblogs_com/ssbpro/GB3091.jpg http://images.cnblogs.com/cnblogs_com/ssbpro/proe.jpg Since ProE does not directly provide a function for converting real data to string data, we need to combine it through existing functions. according to http://www.5dcad.cn/bbs/images/default/logo.gif Method: B=itos(A)+"."+extract(itos((A-floor(A)+1) * 1000),2,3) (A is a real number parameter (n digits after the decimal point), B is a string parameter), you can extract the integer part and the decimal part of the real number separately and then connect them together. This requires using itos(), extract(), floor(), String_length(), pow(), respectively introduced below: 1. Basic functions: 1.1 itos() Convert an integer to a string Usage: Itos(integer) Integer, if it is a real number, it will be rounded. Example: S1=Itos(123) ==> s1="123" S2=itos(2.8) ==> s2="3" Note: If the user uses the itos function with a parameter value of zero (0), the return value will be an empty string. 1.2 extract() Extract string usage: extract(string, position, length) | | | The number of characters to be extracted from the original string position: greater than 0 but less than the length of the string. length: position+length-1 cannot be greater than the length of the string. For example: new=extraect("abcded",2,3)==>new="bcd". Its meaning is: extract 3 characters starting from the second character (b) of the "abcdef" string. 1.3 floor() does not exceed the maximum integer of its value, which can be used to specify the decimal places to be rounded off. Usage: floor(parameter_name or number, number_of_dec_places). | | The number of decimal places to retain in the parameter name or value (can be omitted) number_of_ded_places: Different values can have different results. i) It can be a numerical value or a parameter. If it is a real number, it will be rounded. ii) If number_of_dec_If place>8, no processing will be done, and the original value such as number will be used._of_dec_place-11 The largest integer smaller than -10.2 is -11. floor(10.2)-->10 The largest integer smaller than 10.2 is 10. floor(10.255,1)-->10.2 1.4 String_length() calculates the number of characters in a string Usage: String_length (parameter name or string) Example: strlen1=string_length("material") then strlen1=8 if material="steel",strlen2=string_length(material), then strlen2=5, the string should be enclosed in " ", note: Spaces are also counted as one character. 1.5 Pow() exponential function such as: A=pow(10,2) A=100 B=pow(100,0.5) B=10 2. The secret discovered accidentally. For the parameters entered in ProE, only 8 characters (excluding the decimal point.) can be displayed in the real number type parameters, as shown in the figure below (no matter how many decimal places are entered, the system will always default to 8 digits based on rounding. ; For the relational expression, directly take the first 8 digits). This has a slight impact on the decimal part. We can all use 8-digit values to meet the accuracy requirements. http://images.cnblogs.com/cnblogs_com/ssbpro/ProePara_8bit.jpg http://images.cnblogs.com/cnblogs_com/ssbpro/ProePara_8bit_input.jpg 3. Process of algorithm implementation: Assume that the parameter to be extracted is a=12.345678 (real number type, 8 characters in total) 3.1 Take the integer part and convert it to a string: Since the parameters of the driving model are all positive numbers, the influence of the negative sign in the negative number is not considered. So just use floor() to extract the integer part of the parameter (itos() cannot be used) if itos(floor(a))=="" integer part="0" else integer part=itos(floor(a)) endif 3.2 Get the decimal part: 3.2.1 Using String_length() calculates the length of the integer part, thereby calculating the number of digits in the decimal part: The number of digits in the integer part c=String_length(b) gets c=2; 3.2.2 Since the number of digits in the integer part c=2, the number of digits in the decimal part is: The number of digits in the decimal part is d= 8-c and we get d=6 ; (The overall length of real numbers is 8) 3.2.3 Multiply the decimal part by 10 to the power of d and convert it to a string: if a-floor(a) != 0 fractional part e = itos( (a-floor(a)) * pow(10,d) ) gets e=345678 else decimal part e = "0" endif Note: for 0.0 * * … If the values are not suitable, considering the actual conditions of parts processing, they will not be considered. 3.3 The string obtained by concatenating the integer part and the decimal part string= "integer part b"+"."+"decimal part e" results in string="12.345678", as shown in the figure below: http://images.cnblogs.com/cnblogs_com/ssbpro/ProE_R2S_Simple.jpg 4. Improvement of the algorithm. Since actual parameters rarely reach 8 significant figures, the above method may produce many zeros at the end, and these useless parts need to be deleted. ; For many decimal places, such as 0.001 (≤0.0 * ) and other high-precision dimensions, considering the actual situation during processing, will not be considered for the time being (I haven't figured it out after thinking for a long time, I hope experts can solve it). Since there is no loop statement in the proe function, and there is no if...elseif... statement for conditional judgment, it is necessary to use if...endif statements multiple times. I eliminate the trailing zeros from the back to the front. The single-step algorithm is as follows (disregarding ≤0.0 * In the case of numerical values, there can only be 7 significant digits after the decimal point, so the following statements only overlap 7 paragraphs). See the picture for the test results. if extract(e,d,1) == "0" & d > 0 e=extract(e,1,d-1) d=d-1 endif http://images.cnblogs.com/cnblogs_com/ssbpro/ProePara_8bit_output.jpg 5. Thoughts: Since ProE provides very few functions, the best way is to use high-level languages for secondary development (refer to: ProE secondary development work - customized relational function "real number to string"), because I don't know how to do it, so I used this stupid method. This should be a basic algorithm for converting real data to string data, and there should be a fixed algorithm. When we use high-level languages, programming environments such as VB and C# have already packaged this algorithm, and we did not notice this problem. When we did it ourselves, we found that there are many issues to consider. It is really good to say that "you will learn less when you use the book".