String coding in MCOSMOS: the @ tool of parametric programming
Why our part programs work with text
A measurement program that only knows a single part is quickly written. It gets interesting with series, variants and repeat measurements: report names, feature names and nominal values should then be created at run time, not while programming. GEOPAK offers an inconspicuous lever for this: the @ character. Wherever the software expects text — in file names, feature names, the formula calculation, text output or dialogue defaults — it replaces @ keywords with the current value.
One peculiarity has to become second nature: the text analysis runs before the actual calculation. If the formula calculation contains Var1 = @StrLen(Text)+1, the text is substituted first (Var1 = 4+1) and only then calculated (Var1 = 5). Keep that order in mind and even nested expressions become clear at first glance.
The building blocks we work with
Variables and formulas
@(VarName)— insert the value of a numeric variable@[TxtVarName]— insert the content of a text variable@Formula(x)— calculates as the formula calculation does, directly in the text@ResVarExist("...")/@StrVarExist("...")— check whether a variable exists (1 or 0)
Splitting and rebuilding strings
@StrLen,@StrPos— length and search position@StrLeft,@StrRight,@SubStr— cut out parts@StrChg/@StrChgAll— replace the first or all occurrences@StrGetStr("42.1;18.03;7.5", ";", "2")— returns the second field of a separated list (here: 18.03);@StrGetNumdoes the same for numbers — the workhorse when nominal values come from a CSV file@StrCmp/@StrICmp— comparison with and without case sensitivity@FileExist("path")— 1 if the file exists
Program information and counters
@PartProgName,@Partname,@Revision,@Operator— for the report and for file names@RC(repeat counter),@LC(loop counter),@NoOfLC,@LoadedVars— the counters of loop programming@ElementName[CR, 5]— name of the fifth circle; works for all feature types (PT, LN, CR, PL, CY …)@Time,@Date,@TimeCode— time stamps; path keywords such as@PartPathor@CosmosTempPathsave you from hard-wired directories
Formatting: the numbers after the colon
Up to three parameters after each keyword control the format. For numbers: :total length:decimal places:z — a negative total length means left-aligned, z produces leading zeros. For text variables: :total length:number of characters:start position. That is how we cut columns out of fixed-format files: @[Line]:0:10:11 returns characters 11 to 20.
Five moves from programming practice
1. Make text variables visible. During development we keep a comment dialogue open — the current values of the text variables are visible there at any time, and errors in nested expressions stand out immediately. The "define text variables" command also shows the complete list of all codings.
2. Feature names count themselves up. Ci@Formula(CR.MaxNo+1):3:0:z produces Ci001, Ci002, Ci003 … — CR.MaxNo returns the highest circle number assigned, and the formatting ensures three digits with leading zeros. Nobody assigns names by hand any more.
3. Reports do not overwrite each other. @PartProgName supplies the default file name, @Date or @TimeCode make it unique — every repeat measurement gets its own output file.
4. The series is controlled through a CSV file. The program loads nominal values with "load text variables", @LoadedVars bounds the loop, @[Line@Formula(@LC-1):0] accesses the current line and @StrGetNum separates out the fields. New positions then means: adjust the file, leave the program unchanged.
5. Check first, then access. @FileExist before reading and @StrVarExist before using a variable save you from aborts in repeat operation — especially when the program later runs unattended.
Why this matters for your measurement programs
This technique turns a one-off part program into a reusable template: variables instead of fixed values, dialogues instead of manual work, external control files instead of copies of the program. In CMM programming for Mitutoyo MCOSMOS, string coding is therefore part of the standard — from automatically numbered features to series measurement that pulls its nominal values from a CSV file. How we build and commission measurement programs in general is described on the overview page.