You are currently reviewing an older revision of this page.
For those of you who have spent some time on comp.cad.microstation, I'm sure you've seen reference to keyins that contain mdl load calculat and/or calc something-or-other and have wondered what that the heck that's all about. This article is a brief overview of MicroStation's Calculator / Preprocessor and will help explain use use of the calc keyin.
I'd like to thank Mr. Bernhard Leicher for his inspiration, assistance and contributions for this article! Bernhard spent ten years at Intergraph Germany in Munich supporting MicroStation users in the areas of graphics handling, programming, and EdG. About three years ago he moved on to Degussa in Trostberg and where he supports both IT and MicroStation. Additional thanks goes to none other than Bentley's Phil Chouinard for his awesome editing and clarification of a few points. Then of course, there's also Josh Schifter (Bentley), Geoff Houck, Chuck Gummo, Jim Weisgram, Wolfgang Hauser and many others for their contributions regarding this topic. For those of you who have spent some time on comp.cad.microstation, I'm sure you've seen reference to keyins that contain ,mdl load calculat and/or calc something-or-other and have wondered what that the heck that's all about. What follows is a brief overview and the information presented in this article is of a fairly advanced nature. So, if you don't have any experience with the C programming language, please exercise caution before trying out any of this stuff out. Thank you! The keyin mdl load calculat loads MicroStation's Calculator / Preprocessor utility called calculat.ma which is located in the ...\Program\MicroStation\mdlapps\ folder. Simply put, this utility evaluates mathematical expressions. If a valid expression using the “C” syntax is found in a keyin, the calculator / preprocessor passes the resulting answer into MicroStation's brain for processing. Now, even though you may not be familiar with “C”, you can still use calculat.ma in a variety of ways! Note that in each case, you'll first need to load the MDL with mdl load calculat. As a calculator: When used as a calculator, it can evaluate mathematical expressions and display the results in the status bar. Common mathematical functions such as: cos, sin, and tan are supported along with a variety of others which you can find in MicroStation's documentation. To use this utility as a nifty little calculator, ensure that you've loaded the MDL application and then simply keyin calc followed by your equation: Calc 2+3 Calc (11+14)/3 Calc 3*sin(90)
As a Preprocessor: When acting as a preprocessor, calculat.ma looks for a MicroStation keyin that contains text enclosed by squiggly brackets: { }. (And "Yes", there is a difference between using the squiggly brackets "{}" compard to normal round brackets "( )". For more information, please refer to MicroStation/J v7.1's documentation: Reference Guide > Miscellaneous Reference > Utilities > MDL Applications > Calculator/Preprocessor.) If the keyin contains these delimiters, and if the equation between the deliminators is a valid expression, it calculates the result. At this point, it passes the resulting answer to the MicroStation keyin for processing. For example, it you keyin AS={2*1.27} the Active Scale will be set to 2.540 and AA={tan(3)} will set the Active Angle to the value of 0.0524 !
Directly Access MicroStation's TCB: The neatest thing about calculat.ma is that you can use it to access MicroStation's TCB directly! MicroStation's Terminal Control Block, or TCB, is commonly used in MDL and is programmatically defined in ...\Program\MicroStation\mdl\include\tcb.h Note that it requires MDE Programming Tools to be installed. The TCB data structure essentially defines and contains all of the current information about the design file being edited. This would include items such as the active angle, active scale, dimension settings, and so forth. It should be noted that MicroStation's TCB is mostly associated with the design header and additional TCB structure information can be found in the tcb.h file. On a side note, the User Preferences are separate from the TCB and the public information can be found in: ...\MicroStation\mdl\include\userpref.h. You can apply similar capabilities to the user preferences as you can to TCB. You can open the tcb.h file with any text editor and ‘guess' based on the name of the structure member and any comments behind it. For example, the image below shows a very small snippet of the tcb.h file..it's actually quite a large document. But anyway, you can clearly see the line that reads typedef struct tcbTag and the definitions below it. From that, it's quite obvious that xactscle stores the active angle in the x-axis!! Easy huh?
Another way of obtaining TCB information is to record a macro of your actions. For example, recording the action of selecting Element > Dimensions > Placement > Alignment > Drawing will result in the following bit of code: MbeSetAppVariable "DIMSET", "tcb->ad1.mode.parallel", 1&. You can then use calculat.ma to evaluate the current condition of the TCB by keying in calc tcb->ad1.mode.parallel and MicroStation will display it's current value in the status bar.
Knowing a bit about the TCB structure will allow you to either retrieve or even set a variable via a keyin! Note that your keyin will now have to include this thing “ -> ” which is just a C pointer to the variable. Here's an example: the keyin calc tcb->textSlant will retrieve the numerical value of the text slant and display it on the right side of your status bar. While the keyin calc tcb->textSlant=15 will set the text slant to 15 degrees. Pretty cool stuff! Evaluate built-in C and MDL Functions: An added bonus when using calculat.ma is that you can also invoke any C or MDL function! For example, if you keyin calc printf (“hello”), the word hello will passed to the MicroStation text window! Another example would be to keyin calc mdlSystem_elapsedTime() to display the elapsed time since MicroStation was started! As you can probably tell, you'll need to have a fair bit of C and MDL programming knowledge to utilize this part of calculat.ma.
Although there's certainly more to say and explain, I encourage you to fiddle around with calculat.ma to see where you might be able to utilize it. Please remember that this is a very powerful utility and you should use caution! Additional information can be found in MicroStation/J's v7.1 on-line Help: Help > Reference Guide > Miscellaneous Reference > Utilities > MDL Applications > Calculator/Preprocessor. Well, that's about it…I'll finish up by leaving you some keyins to try. Most of these have been posted at some point in time to "comp.cad.microstation" so I'd like to thank the following for sharing these nifty keyins with us: Barry Bentley, Phil Chouinard, Chuck Gummo, Wolfgang Hauser, Geoff Houck Bernhard Leicher, Josh Schifter, Doug Watt, and Jim Weisgram Oh...and remember that you'll have to load calculat.ma first. Have fun!
The following was posted and contributed by none other than Chuck Gummo! These instructions will allow you to measure a value and place the resulting distance as text. Step 1: Preset your text size and attributes. Load calculat.ma Step 2: Set the number of decimal places for the text. For example use the keyin %.4f for 4 decimal places; %.3f for 3 decimal places and so on. Step 3: Keyin a measurement tool such as Measure Area [option] or Measure Length Step 4A: Keyin the following for area text placement: place text;tcb->smobuf[0] Step 4B: Keyin the following for linear text placement: place text;tcb->smobuf[1] Example 1 - Single line of text: place text;Area= {tcb->smobuf[0]}, Perimeter= {tcb->smobuf[1]} Example 2 - Two lines of text: place text;Area: {tcb->smobuf[0]}\010Perimeter: {tcb->smobuf[1]} Example 3 - Two lines of text: place text;Area = {tcb->smobuf[0]}\010Perimeter = {tcb->smobuf[1]} Notes: A. Steps 1-2-3 can be combined into one keyin. Steps 4 or 5 (if included in keyin string) will result in placing text value of any previously measured area/length command. Therefore, Steps 4 or 5 need to be separate to place current value of tcb->smobuf. B. \010 is code for line return. C. Values in tcb->smobuf[0] and tcb-smobuf[1] with "Measure Area" commands should not be divided by "UOR/MU" factor. See examples above. D. For "Length Measurements", the value in tcb->smobuf[0] should be divided by "UOR/MU" for master unit conversion (Feet, meters, yards, etc.). E. This method will work with lines, arcs and curves. F. If a linestring is selected, the text label will be total length. G. If applied to Shapes, the resultant text will be the perimeter. H. Selecting Circles and Elipses will give you the circumference. I. If multiple elements are pre-selected with the Element Selection tool, the label will be the total length of all elements. J. Whatever results the "Measure Length" tool calculates and displays you can label with the "Place Text" command. This includes any of the placement methods such as "above", "below" etc. K. You can customize the labeling of lengths by modifying the keyin. For example: place text above;Length={tcb->smobuf[0]} place text above;{tcb->smobuf[0]} FT In version 7 (MS/J): PLACE TEXT;{tcb->smobuf[0]/tcb->subpermast/tcb->uorpersub} PLACE TEXT;LENGTH={tcb->smobuf[0]/tcb->subpermast/tcb->uorpersub} In Version 8: PLACE TEXT;{tcb->smobuf[0]/mdlModelRef_getUorPerMaster mdlModelRef_getActive()) PLACE TEXT;LENGTH={tcb->smobuf[0]/mdlModelRef_getUorPerMaster (mdlModelRef_getActive()) Thanks Chuck!