Original Post Date: August 2002 Updated: August 2010 MicroStation's Calculator / Preprocessor For those of you who've been frequenting the web as a resource for all things MicroStation, you may have run into keyins that contain mdl load calculat and/or calc something-or-other and wondered what that refers to. MicroStation is delivered with a Calculator / Preprocessor utility called calculat.ma that's loaded with the keyin mdl load calculat. This utility evaluates mathematical expressions in MicroStation keyins and, if a valid expression found, the calculator / preprocessor passes the resulting answer into MicroStation's brain for further processing. The syntax used for the keyin is "C" and 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 message center. In older versions of MicroStation, the results will display on right side of the status bar. The following mathematical functions are supported: cos, acos, sin, asin, atan, atan2, tan, cosh, tanh, sinh, exp, ldexp, log, log10, pow, and sqrt.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. For example: Calc 2+3 , Calc (11+14)/3 , and Calc 3*sin(90) As a Preprocessor:When acting as a preprocessor, calculat looks for a MicroStation keyin that contains text enclosed by delimiter characters which by default are set to squiggly brackets or braces: { } If the keyin contains these delimiters, and if the equation between the deliminators is a valid expression, it calculates and displays the result in the message center. At that point, it passes the resulting answer to the MicroStation keyin for processing. For example, AS={4*1.27} will set the active scale to 5.08 while AA={tan(3)} will set the active angle to 0.0524 Directly Access MicroStation's TCB:The neatest thing about calculat 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 the following file: .../microstation/mdl/include/tcb.h. Note: MicroStation V8i and MicroStation V8 XM Edition, require that you install the MicroStation SDK from SELECTservices Online). Previous versions MicroStation, require that the MDE Programming Tools are installed. These can also be found on SELECTservices Online.The TCB data structure 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.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 h files with any text editor and search for key words using the editor's Find function. For example, searching for active scale in TCB.H will indicate that xactscle stores the active angle setting for the x-axis, while yactscle stores the active scale for the y-axis. . Another way of obtaining TCB information is to record a macro of your actions. For example, the following information can be captured when changing the Start At option to Text in the Place Note tool: Knowing a bit about the TCB structure will allow you to either retrieve or even set a variable via a keyin. In this particular example, you could force the Place Note tool to always be set to the Text 'start at' option by using the following keyin: calc tcb->msToolSettings.placeText.noteToolReverse = 1 Just remember that you'll need to have the calculator/preprocessor loaded first. This can easily be done by preceding you keyin with the following: mdl load calculat. Also note that the keyin will include this thing -> which is just a C pointer to the variable. Evaluate built-in C and MDL Functions:The calculator/preprocessor can also invoke any C or MDL functions. 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. Pre-V8 examples using the Calculator/Preprocessors:The following list shows a variety of usages of the Calculator/Preprocessor. Note that these were last tested on V7 and due to design file changes, may not work in V8. Set the Selection Set highlight colour:calc tcb->selectionHiliteColor=XWhere X is the desired colour number. Set the fence placement colour:This is not the colour of the fence after it's placed, rather the colour when the fence is being placed.calc userPrefsP->alignmentColor=5Where the "5" is a colour from the attached colour table. Set the active fill to "None":calc tcb->ext_locks.fillMode=0;act col X;act fillcol Y Set the active fill to "Outlined":calc tcb->ext_locks.fillMode=1;act col X;act fillcol YWhere X=Outline Color, Y=Fill Color Set the active fill to "Opaque":calc tcb->ext_locks.fillMode=1;act col X;act fillcol XWhere X=Outline Color = Fill Color Change Sub-Units to 12 and Positinal-Units to 1000:calc tcb->subpermast=12;calc tcb->uorpersub=1000 Set the Master Unit label to two characters such as "FT":calc tcb->mastname[0]='F' ; calc tcb->mastname[1]='T' Set the Sub Unit label to two characters such as "IN":calc tcb->subname[0]='i' ; calc tcb->subname[1]='n' Set the Master Unit label to a single character such as "M":calc tcb->mastname[0]='m' ; calc tcb->mastname[1]='\0' Set the active text size as a factor of the active scale:tx=*{tcb->xactscle} Stop dimensions flipping when view is rotated:calc tcb->ad4.ext_dimflg.viewRotation=1 Set dimension terminators to "inside":calc tcb->ad4.ext_dimflg.arrowOut=2 Set dimension terminators to "outside":calc tcb->ad4.ext_dimflg.arrowOut=3 Add 15 degrees to the active angle:aa={tcb->actangle+15} Add the Axis Lock Increment Angle to the Active Angle:calc tcb->actangle=tcb->actangle+tcb->axlock_angleOr: aa={tcb->actangle+tcb->axlock_angle} Decrement the Axis Lock Increment Angle from the Active Angle:calc tcb->actangle=tcb->actangle-tcb->axlock_angleOr: aa={tcb->actangle-tcb->axlock_angle} Set the Active Angle to the measured angle when using “Measure Angle Between Lines” tool:calc tcb->actangle=tcb->smobuf[0];aa=$ Place text using the results of "Measure Area":place text;area={tcb->smobuf[0]} Change the custom line style scale: calc tcb->lineStyle.scale=x Turn ON the scale setting if it's turned OFF in the custom line style settings dialog:calc tcb->lineStyle.modifiers=1|tcb->lineStyle.modifiers Get the current path of the active design file:calc tcb->dgnfilenm Rotate clip masks when the view is rotated:calc userPrefsP->refFilePrefs.rotateClipping=1;ref clip rot on XWhere X is the logical name of the reference file. Force a save of the user preferences (V8 only)calc mdlUserPrefs_save(0) AskInga Article #80 Original Article Date:
Original Post Date: August 2002
Updated: August 2010
MicroStation's Calculator / Preprocessor
For those of you who've been frequenting the web as a resource for all things MicroStation, you may have run into keyins that contain mdl load calculat and/or calc something-or-other and wondered what that refers to.
MicroStation is delivered with a Calculator / Preprocessor utility called calculat.ma that's loaded with the keyin mdl load calculat.
This utility evaluates mathematical expressions in MicroStation keyins and, if a valid expression found, the calculator / preprocessor passes the resulting answer into MicroStation's brain for further processing. The syntax used for the keyin is "C" and 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 message center. In older versions of MicroStation, the results will display on right side of the status bar.
The following mathematical functions are supported: cos, acos, sin, asin, atan, atan2, tan, cosh, tanh, sinh, exp, ldexp, log, log10, pow, and sqrt.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. For example: Calc 2+3 , Calc (11+14)/3 , and Calc 3*sin(90)
As a Preprocessor:When acting as a preprocessor, calculat looks for a MicroStation keyin that contains text enclosed by delimiter characters which by default are set to squiggly brackets or braces: { }
If the keyin contains these delimiters, and if the equation between the deliminators is a valid expression, it calculates and displays the result in the message center. At that point, it passes the resulting answer to the MicroStation keyin for processing. For example, AS={4*1.27} will set the active scale to 5.08 while AA={tan(3)} will set the active angle to 0.0524
Directly Access MicroStation's TCB:The neatest thing about calculat 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 the following file: .../microstation/mdl/include/tcb.h.
Note: MicroStation V8i and MicroStation V8 XM Edition, require that you install the MicroStation SDK from SELECTservices Online). Previous versions MicroStation, require that the MDE Programming Tools are installed. These can also be found on SELECTservices Online.The TCB data structure 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.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 h files with any text editor and search for key words using the editor's Find function. For example, searching for active scale in TCB.H will indicate that xactscle stores the active angle setting for the x-axis, while yactscle stores the active scale for the y-axis.
.
Another way of obtaining TCB information is to record a macro of your actions. For example, the following information can be captured when changing the Start At option to Text in the Place Note tool:
Knowing a bit about the TCB structure will allow you to either retrieve or even set a variable via a keyin. In this particular example, you could force the Place Note tool to always be set to the Text 'start at' option by using the following keyin:
calc tcb->msToolSettings.placeText.noteToolReverse = 1
Just remember that you'll need to have the calculator/preprocessor loaded first. This can easily be done by preceding you keyin with the following: mdl load calculat. Also note that the keyin will include this thing -> which is just a C pointer to the variable.
Evaluate built-in C and MDL Functions:The calculator/preprocessor can also invoke any C or MDL functions. 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.
Pre-V8 examples using the Calculator/Preprocessors:The following list shows a variety of usages of the Calculator/Preprocessor. Note that these were last tested on V7 and due to design file changes, may not work in V8.
Set the Selection Set highlight colour:calc tcb->selectionHiliteColor=XWhere X is the desired colour number.
Set the fence placement colour:This is not the colour of the fence after it's placed, rather the colour when the fence is being placed.calc userPrefsP->alignmentColor=5Where the "5" is a colour from the attached colour table.
Set the active fill to "None":calc tcb->ext_locks.fillMode=0;act col X;act fillcol Y
Set the active fill to "Outlined":calc tcb->ext_locks.fillMode=1;act col X;act fillcol YWhere X=Outline Color, Y=Fill Color
Set the active fill to "Opaque":calc tcb->ext_locks.fillMode=1;act col X;act fillcol XWhere X=Outline Color = Fill Color
Change Sub-Units to 12 and Positinal-Units to 1000:calc tcb->subpermast=12;calc tcb->uorpersub=1000
Set the Master Unit label to two characters such as "FT":calc tcb->mastname[0]='F' ; calc tcb->mastname[1]='T'
Set the Sub Unit label to two characters such as "IN":calc tcb->subname[0]='i' ; calc tcb->subname[1]='n'
Set the Master Unit label to a single character such as "M":calc tcb->mastname[0]='m' ; calc tcb->mastname[1]='\0'
Set the active text size as a factor of the active scale:tx=*{tcb->xactscle}
Stop dimensions flipping when view is rotated:calc tcb->ad4.ext_dimflg.viewRotation=1
Set dimension terminators to "inside":calc tcb->ad4.ext_dimflg.arrowOut=2
Set dimension terminators to "outside":calc tcb->ad4.ext_dimflg.arrowOut=3
Add 15 degrees to the active angle:aa={tcb->actangle+15}
Add the Axis Lock Increment Angle to the Active Angle:calc tcb->actangle=tcb->actangle+tcb->axlock_angleOr: aa={tcb->actangle+tcb->axlock_angle}
Decrement the Axis Lock Increment Angle from the Active Angle:calc tcb->actangle=tcb->actangle-tcb->axlock_angleOr: aa={tcb->actangle-tcb->axlock_angle}
Set the Active Angle to the measured angle when using “Measure Angle Between Lines” tool:calc tcb->actangle=tcb->smobuf[0];aa=$
Place text using the results of "Measure Area":place text;area={tcb->smobuf[0]}
Change the custom line style scale: calc tcb->lineStyle.scale=x
Turn ON the scale setting if it's turned OFF in the custom line style settings dialog:calc tcb->lineStyle.modifiers=1|tcb->lineStyle.modifiers
Get the current path of the active design file:calc tcb->dgnfilenm
Rotate clip masks when the view is rotated:calc userPrefsP->refFilePrefs.rotateClipping=1;ref clip rot on XWhere X is the logical name of the reference file.
Force a save of the user preferences (V8 only)calc mdlUserPrefs_save(0)
AskInga Article #80