Here is a small example:
The MDL portions are partial. So I assume you know MDL quit well. The mdl file must be in a directory covered by the ms_mdl system variable. The dls file is complete however without the header comments. The mke file is incomplete showing only the macro commands for compiling the dls file into your final mdl resource. The mjava file is a complete, locate command.
You can return longs from mdl as long as the java file expects an int; You can return pointers to element descriptiors to java you then must use:
Element javaelement =
Element.fromDescriptor(mdlfunctionwhichreturnsdescriptor(arg1, arg2));
If you want, I can zip and send a complete example. I cannot now because I must do it from scratch.
this is a public function in a file called deleteque.mc:
Public void delQ_tagElement(ULong *tagId, ULong filePos) { MSElementUnion elU; int oLocked = 1; int taginc; if(mdlParams_getActive(&taginc, ACTIVEPARAM_TAGINCREMENT) == SUCCESS) { if(taginc != 1) { taginc=1; mdlParams_setActive(&taginc, ACTIVEPARAM_TAGINCREMENT); } } else mdlParams_setActive(&taginc, ACTIVEPARAM_TAGINCREMENT);
if(mdlAssoc_tagElement(tagId, filePos, 0) != SUCCESS)
*tagId = 0;
}
Here is how we export the public function:
This file is deleteque.dls
%Version 0x551
%InterfaceType Mdllib
%ModuleName exlib
%Functions
delQ_tagElement // decalare each function as so one line at a time
%EndFunctions
%Variables
%EndVariables
%End
This is how the dls file is compiled into the mdl resource:
This is inside of deleteque.mke.
#---------------------------------------------------------------------- # compile c source #---------------------------------------------------------------------- $(o)$(appName).mo : $(baseDir)$(appName).mc $(baseDir)$(appName).h $(baseDir)TRmselems.h
$(mdlLibs)$(appName).dlo : $(baseDir)$(appName).dls
#------------------------------------------------------------------------ # The following section generates the MDL Program module using # mlink. This module should contain ALL CODE resources and/or # libraries used by the application. #------------------------------------------------------------------------
$(o)$(appName).mp : $(Objs) $(mdlLibs)$(appName).dlo $(msg)
-e$(mdlLibs)$(appName).dlo
-a$@
$(linkOpts)
$(Objs)
<
$(MLinkCmd) @$(o)$(appName).cmd
~time
#------------------------------------------------------------------------ # The following section generates the MDL Intermediate module using # rlib. This module contains the MDL CODE module and any # non-translatable resource modules. #------------------------------------------------------------------------
$(o)$(appName).mi : $(Rscs)
$(msg)
> $(o)temp.cmd
-o$@
$(Rscs)
<
$(RLibCmd) @$(o)temp.cmd
~time
maRscs = $(o)$(appName).mi
$(outputDir)$(appName).msl : $(o)$(appName).mi
// the finished file a an msl file not an ma file
$(msg)
> $(o)make.opt
-o$@
$(maRscs)
<
$(RLibCmd) @$(o)make.opt
~time
#------------------------------------------------------------------------ # End of build. NOTE: This line is helpful by terminating the # last rule with a blank line. This is necessary
Lastly the mjava file would look like this:
This is testDelQTagCmd.mjava.
package com.staten.cad.microstation;
/**
* The command to display the tririga attachment information about an
* intelligent element
*/
import com.bentley.dgn.DgnKernel;
import com.bentley.dgn.DPoint;
import com.bentley.dgn.Element;
import com.bentley.dgn.LocateCommand;
import com.bentley.dgn.View;
#include "TRtfinfo.h"
public class testDelQTagCmd extends LocateCommand
{
/**
* These are native functions for the TRdeleteQmdl.msl link library file
* that is used to manipulate and search through complex elements
*/
jmdl_import ( mdl="deleteque", name=delQ_tagElement ) //This jmdl import imports the native function for use by java static native void delQ_tagElement(unsigned int *tagId_, unsigned int filePos); //This declares the native functions signature
public void start (String oStrUnparsed)
{
DgnKernel.showCommand ("Test Delete Que");
DgnKernel.showPrompt ("Select a Cad Object");
this.setLocateAll;
}
public boolean locateFilter (Element oElement) {
return true;
}
/**
* Accept is called when an element is located and meets the criteria of the locateFilter.
*/
public void accept(Element oElement, DPoint oPoint, View oView) { unsigned int tagId=0; unsigned int filepos = 0;
filepos = oElement.getFilePos
System.out.println("FilePos is :" + filepos);
delQ_tagElement(&tagid, filepos); // In mstation, java has pointers if(tagid > 0) System.out.println("You were successful in tagging the element"); restart ; }
public void locateFailed {
DgnKernel.showStatus ("No element Found");
}
public static void main(String args)
{
testDelQCmd testDQCmd = new testDelQCmd;
testDQCmd.setKeyin ("test DeleteQ");
DgnKernel.registerCommand (testDQCmd);
}
}
import com.bentley.dgn.*;
public class DeleteQue
{
public DeleteQue //Constructor
{
}
public void tagElement(MSElement el)
{
unsigned int tagid = 0;
unsigned int filepos = 0; // remember a java long is 64 bit and a java int is 32 bits where a c long is 32 bits, // so a ULong in mdl is an unsigned int in java
filepos = el.getFilePos;
}
}