Microstation Development Language (MDL) – Place LineString

Back to MDL blog again.. Today we will do a simple program which will explain you a number of things in MDL programming in a simplified manner.

We will place a line string through a MDL program. Remember that this code is only applicable to the older version (Microstation/J – version 7).

In this program, I am showing how to
1. Show a prompt to the user
2. How to initiate a function on a data click
3. How to initiate a function on the right-click (Reset)
3. How to show a rubber band effect
4. How to generate a linestring in the end

The code is simple and self-explanatory but I will still add some description for you to understand.

In the program a prompt will ask use to give a point, when user gives a point in the view, an array of points will be populated and a counter of the number of vertices will be maintained. When user gives a right-click, the linestring placement will complete and a linestring will be generated. The user will be also see the rubber band dynamic display of the linestring as he gives point.


//include files
#include <mdl.h>
#include <tcb.h>
#include <mselems.h>
#include <userfnc.h>

//variable to create the linestring
MSElementUnion oElm;

//maximum 101 vertices – This is an array of coordinates
Dpoint3d lsPoints[MAX_VERTICES];

//number of vertices for the dynamic display of the linestring
int ntmpcount = 0;

//number of vertices to create a final linestring
int nvertexCount = 0;

//function definitions – if not added then it will not compile
void LS_NextPoint(Dpoint3d *point,int numView);
void LS_Complete(Dpoint3d *point,int numView);

//Dynamic display function, it is passed a cursor coordinate as the //cursor moves in the map
//dgnBuf is used for the dynamic display
//If this function is not defined then user will be able to give a point //in the map as usual but will not see how his linestring is appearing //in the map at the runtime.

int LineStringDynamics(Dpoint3d *ptP,int view)
{
ntmpcount = nvertexCount;
lsPoints[ntmpcount].x = ptP->x;
lsPoints[ntmpcount].y = ptP->y;

mdlLineString_create(dgnBuf, NULL, lsPoints, (ntmpcount+1));

return (SUCCESS);
}

//This is function receives a point on a data click, point array is //populated and vertex counter is incremented. The function calls itself // on a dataclick, it also sets a dynamic display function and complete //function on a right-click
void LS_NextPoint(Dpoint3d *point,int numView)
{

lsPoints[nvertexCount].x=point->x;
lsPoints[nvertexCount].y=point->y;

nvertexCount = nvertexCount+1;
mdlOutput_prompt(“Give the next point”);

mdlState_setFunction (STATE_DATAPOINT,LS_NextPoint);
mdlState_dynamicUpdate (LineStringDynamics, FALSE);
mdlState_setFunction (STATE_RESET,LS_Complete);
}

//When user gives a right-click the complete function is called, line //string is created, added to the file displayed normally, dialog box //shows a message to the user about the completion of the command and a //default command call is made. The Exit function call is made in the //end
void LS_Complete(Dpoint3d *point,int numView)
{
if(nvertexCount<2)
{
mdlOutput_prompt(“Give next point”);
mdlState_setFunction (STATE_DATAPOINT,LS_NextPoint);
}
else
{

mdlLineString_create(&oElm, NULL, lsPoints, nvertexCount);
mdlElement_add (&oElm);
mdlElement_display (&oElm, NORMALDRAW);
mdlOutput_prompt(“”);
mdlDialog_openInfoBox(“Placement is complete”);
mdlState_startDefaultCommand ();
mdlSystem_exit(NULL,1);
}
}

//program entry point – the function prompts user to give a first point
//A function call on a data click is set

int main(int argc, char *argv[])
{
mdlOutput_prompt(“Give the first point”);
mdlState_setFunction (STATE_DATAPOINT,LS_NextPoint);
return 0;
}


As you see the code above can be saved as a whole (with comments) in a file placeline.mc and compile as explained in the blog – Hello World MDL

Open a dgn file and execute the command as

mdl l \placeline

See the dynamic display below:

rubberband

The linestring placement is complete.

lscomplete

I will add more blogs on MDL, any comments or questions are welcome! Thank you!

Microstation Development Language (MDL) – Hello World

Let me start with very small a Hello World app using MDL programming. This will give an idea where to start, how to compile and produce a .ma file and run the .ma file. I will try to resist the temptation to add many theoretical details at first. Just want to give that eureka moment for a beginner MDL programmer. With further modules I will try to explain more in detail slowly. You can contact me in case you have any queries, you can put the comments or email me.

I am going to develop the HelloWorld mdl app on Microstation v7 in Windows enviroment. So make sure it is installed fully on your PC.

You are expected to have basic knowledge of C or C++, code debugging and compile error resolutions etc. You will also have to refer MDL Help from the Microstation menu, time to time.

There are a number of source file types involved (.mc, .h, .r etc.). You can write those using Notepad, Notepad++, Visual Studio or any other text editor.  In this example we will code HelloWorld.mc file.

After compiling process, it will produce HelloWorld.ma which when executed; Microstation will interpret and show a dialog box.

First, open the console window

1

This will open a command prompt as:

2

Create a HelloWorld.mc.

3

Write the following in HelloWorld.mc and save the file.

#include <mdl.h>
#include <dlogitem.h>

int main()
{
mdlDialog_openInfoBox(“Hello World!!”);
return 0;
}

The first two file are the preprocessing directives. The main function has a call to mdlDialog_openInfoBox function which will open a modal dialog box.

If you open Windows Explore, you will find under the MicroStation directory, there is folder as mdl\include. Note the whole path.

4

In the command prompt, type the following.

set MDL_COMP=-i<path to mdl include folder>

In my case, it is

set MDL_COMP=-iF:\Bentley\Program\MicroStation\mdl\include

This will help compiler to find where the .h (header files with function definitions) files are. Otherwise, you will get the errors such as Can’t include mdl.h

Now, start the compiling process. Use the MCOMP utility first. This will produce .mo file in the same folder where .mc file is.

6

Use the MLINK utility and produce the .MA file.

7

We are there!!

Open Microstation and give the command as

mdl l c:\temp\HelloWorld

It will show a dialog box.

9

You can refer the next lesson  Place a Linestring using MDL where you will learn how a linestring can be placed using MDL, you will also learn about dynamic update in the same lesson.

Cheers!!! smley