V8i MDL Always Getting 0 in level id

Hello,
I'm sort of new to Microstations and have been tasked with upgrading MicrostationsJ(v 7.0) mdl code to work in v8i select series 4. I've hit an issue with a function that simply gets the level for an element. I've read that levels in Microstations 7 to 8 changed quite a bit, so I know I would have to rewrite the code for this funciton.

The existing function in v7 used the old method of obtaining the level by traversing an array of short integers and the level could be 1 to 63.

So here is my plan to rewrite the funcction to get the level in v8i

1. Use the mdlElement_getProperties function to get the level id of an element. Note that I realize that this is an internal id and does not equate to the level id in v7.

2. Use funcciton mdlLevel_getName to get the level name from the internal level id. The level name is significant to us, since it seems to equate to the old v7 level, example Level 71, Level 42 ect..

My problem is that in step 1, I always get back a 0 for the internal level id.
So when the code below runs I always see the following for each element: this is for thousands of elements always 0. I never see the line good level if the levelid is not 0.

element is graphic
level id: 0

I've commented out the call to mdlLevel_getName, since it seems pointless to call it for now if the levelid is always 0, and don't mind that I am returning 1 form the funciton, this is just for testing for now.

couple of more things:
I will post full code for my program in a reply to this post. this is a test program that I run from the command windows. The program does a file scan of each hard-coded cell then reads each element in the cell.
I know these elements are good because I had code in this program (that I removed for readability) that successfully got other information off the element after the call to getItemLevel.

The dgn that I am using is from v7, so when I opened it in v8i the first time, it converted the file. There is only 1 default model. And if I go into the dgn in v8i, I can see the levels exist that I am tring to get the level name for.

I kow that the way that I am scanning the file is outdated and I will be looking to changing that after I get past my current issue with the levelid.

So here is my question?
What am I doing wrong? Am I on the right track for retreiving the level name for an element or is there another way to do this? If I am on the right track then why am I always gettting a 0 in the levelid?

Help for my issue would be greatly appreciated. I've searched these forms and the reference material without success.

Public int getItemLevel(MSElement *elP)
{

MSWChar levelName [50];
UInt32  levelid;

                 //elements are graphic
                 if(elP->ehdr.isGraphics)
                 {
                  fprintf(fres,"\n element is graphic");  

		  mdlElement_getProperties ( &levelid , NULL , NULL , NULL, NULL , NULL, NULL, NULL, elP );
		  fprintf(fres,"\n level id: %d", levelid);
                  if (levelid != 0)
	   	  {
		    fprintf(fres,"\n good level");
		  } 

/*
                 if (SUCCESS == mdlLevel_getName( levelName, 50, MASTERFILE, levelid ))
                 {
                   fprintf(fres,"\nlevel name = %s",levelName);
                 }
*/	
                }




	return 1;
}

Parents
  • And here is the full code for my test program:

    /*
    	ShowLevels - test program
    */
    
    /*---------------------------------------------------------------------------
     Include Files
    -----------------------------------------------------------------------------*/
    #include <stdlib.h>		/* Standard "C" library			*/
    #include <stdio.h> 		/* Standard "C" I/O library     	*/
    #include <string.h> 		/* "C" lib to operate with "string" 	*/
    #include <ctype.h> 		/* "C" lib to operate with "symsol" 	*/
    #include <time.h>           	/* "C" lib to operate with "time"	*/
    
    #include <mdl.h>		/* Main include file for MDL   		*/
    #include <rscdefs.h>		/* Resource Manager Structure Definitions */
    #include <msrsrc.fdf>		/* Resource Manager function prototypes */
    #include <msdefs.h>		/* Defines for MicroStation data structures */
    #include <msrsrc.fdf>		/* Resource Manager function prototypes */
    #include <cexpr.h>		/* Defs for C Expression evaluation functions */
    #include <mscexpr.fdf>		/* C Expression evaluation function Prototypes */
    #include <mselems.h>           	/* Definitions for MicroStat. elements 	*/
    #include <mselmdsc.fdf>		/* MicroStation element function Prototypes */
    #include <dlogitem.h>		/* Dialog Box Item definitions 		*/
    #include <msdialog.fdf>		/* Dialog Box Function Prototypes 	*/
    #include <dbdefs.h>		/* Database definitions		 	*/
    #include <dberrs.h>		/* Database error return codes		*/
    #include <dbserver.h>		/* Database Server Definitions		*/
    #include <rdbmslib.fdf>		/* Database Function Definitions	*/
    #include <msoutput.fdf>		/* Output function Prototypes           */
    #include <msinputq.h>		/* Input queue definitions for MicroStation/MDL */
    #include <msinput.fdf>		/* Input queue Prototypes for MicroStation/MDL */
    #include <scanner.h>		/* Definitions for design files "scanner"	*/
    #include <msscan.fdf>		/* Function Prototypes for "scanner" */
    #include <mscnv.fdf>		/* Prototypes for Convert functions     */
    #include <tcb.h>		/* Definitions for "terminal control block" */
    #include <errno.h>		/* Standard Library error codes		*/
    #include <mssystem.fdf>		/* System function Prototypes           */
    #include <msoutput.fdf>		/* Output function Prototypes           */
    #include <msview.fdf>		/* View function Prototypes             */
    #include <msfile.fdf>		/* File function Prototypes             */
    
    #include <leveltable.fdf>
    
    #include "ShowLevels.h"
    
    /*--------------------------------------------------------------------
      Local Defines 
    ----------------------------------------------------------------------*/
    #define MAX_SIGNALS	1000
    #define MAX_ELEMS	1000
    #define NUM_CELLNAMES	43
    #define LEN_SQL 	256
    
    
    /*---------------------------------------------------------------------
      Global Data 
    ----------------------------------------------------------------------*/
    DialogBox  *GL_dbP;
    //char    GL_text[16], GL_signalName[8], GL_lever[8];
    char    GL_text[50], GL_signalName[25], GL_lever[25];
    int     GL_numLink; 	/* number Signals to be  linked */
    int     GL_numRes; 	/* number Signals currently linked */
    int     GL_numErr;
    FILE	*fres;
    
    
    /*---------------------------------------------------------------------
      Function Prototypes 
    ----------------------------------------------------------------------*/
    Public  void    findDFitems	(void);
    
    Public  int   	getItemLevel	(MSElement *);
    
    char    GL_cellNames[NUM_CELLNAMES][8] =
            {
            "SIG1L","SIG2L","SIG3L","SIG4L","SIG5L","SIG6L",
            "SIG1R","SIG2R","SIG3R","SIG4R","SIG5R","SIG6R",
            "SIG1A","SIG2A","SIG3A","SIG4A","SIG5A","SIG6A",
            "SIG1B","SIG2B","SIG3B","SIG4B","SIG5B","SIG6B",
            "SIG1C","SIG2C","SIG3C","SIG4C","SIG5C","SIG6C",
            "SIG1D","SIG2D","SIG3D","SIG4D","SIG5D","SIG6D",
            "SIG6AR","SIG1BR","SIG5BR",
    	"SIG1CR","SIG4CR","SIG5CR","SIG6DR"
            };
    
    int	GL_itemLevels[3]= {12,30,48};
    
    struct
    {
      int  mslink;
      char name[16];
      char lever[16];
    } GL_signals[MAX_SIGNALS];
    
    FILE	*fres;
    
    int main(int argc, char *argv[])
    {
            char str[128], *alertDir;
     int    status,n,m;
    
            alertDir = getenv("ALERT_DIR");
            strcpy(str,alertDir);
            strcat(str,"maint\\link\\testlog.txt");
            if ( (fres=fopen(str,"w")) == NULL ) 
            {
               printf("Can not open file %s",str);
               mdlSystem_exit(0,1);
            }
    
     	fprintf(fres,"ShowLevels started");
    
     	findDFitems();
    
    //        newSearch(); 
    
     	fprintf(fres,"\n\nfindDFitems complete");
    
    
    
     	fprintf(fres,"\n\nShowLevels ended");
         fclose(fres);
    	mdlSystem_exit(0, 1);
    	return 0;
    }
    
    /*-------------------------------------------------------------------------
      name          findDFitems
      A function to find all Signals in the active design
      file using cell names as search criterion
    --------------------------------------------------------------------------*/
    Public void     findDFitems()
    {
     ULong          elemAddr[MAX_ELEMS], eofPos, filePos, newFilePos, readFilePos;
     int            scanWords, status, status1, i, j, n, m, numAddr, numItems, 
    		exist=0, linkCount, level, mslink;
     ExtScanlist    scanList;
     MSElementDescr *edP, *newEdP;
     MSElement      *elP;
     short          cellNameR50[2];
     char           cellNameAsc[16], str[128], word2[16], word3[16], division[8];
     DatabaseLink   *links[10];
     double		x, y;
     int ttt = 0;
    
    
    fprintf(fres,"\n\nfindDFitems Beginning");
    
     for ( j = 0; j < NUM_CELLNAMES; j++ )
     {
    	strcpy(cellNameAsc,GL_cellNames[j]);
    	mdlScan_initScanlist (&scanList);
    	mdlScan_noRangeCheck (&scanList);
    	memset(scanList.typmask,0x00,sizeof(scanList.typmask));
    	memset(cellNameR50,0,sizeof(cellNameR50));
    
            scanList.scantype       = ELEMTYPE | PICKCELL;
    	scanList.extendedType   = FILEPOS;
    	scanList.typmask[0]     = TMSK0_CELL_HEADER;
    
    	mdlCnv_fromAsciiToR50(strlen(cellNameAsc),cellNameAsc,cellNameR50);
    
    	/* Initialize the scanlist for use w/ the masterfile (file 0) */
    	eofPos = mdlElement_getFilePos (FILEPOS_EOF,NULL);
    
    	mdlScan_initialize (MASTERFILE, &scanList);
    
    	filePos = 0L; /* start search from top of file */
    	do 
    	{
    	   scanWords = sizeof(elemAddr)/sizeof(short);
    	   status = mdlScan_file (elemAddr,&scanWords,sizeof(elemAddr),
    		    &filePos);
    
    	   numAddr = scanWords/sizeof(short);
    
    	   for ( i=0; i<numAddr; i++ )
    	   {
    		if (elemAddr[i] >= eofPos) break;
    		mdlElmdscr_read (&edP,elemAddr[i],0,FALSE,&readFilePos);
    
    		/* 1. Check if this Signal already has Link 
    		*/ 
                    elP = &edP->el;
    
    		/* 2. Get Signal Level and find the Division */
    		level = getItemLevel(elP);
    
    		mdlElmdscr_freeAll( &edP ); 
    	   }
     
    	} while (status == BUFF_FULL);
     }
    }
    
    /*-------------------------------------------------------------------------
      getItemLevel		
    --------------------------------------------------------------------------*/
    Public int getItemLevel(MSElement *elP)
    {
    
    MSWChar levelName [50];
    UInt32  levelid;
    
                     //elements are graphic
                     if(elP->ehdr.isGraphics)
                     {
                      fprintf(fres,"\n element is graphic");  
    
    		  mdlElement_getProperties ( &levelid , NULL , NULL , NULL, NULL , NULL, NULL, NULL, elP );
    		  fprintf(fres,"\n level id: %d", levelid);
                      if (levelid != 0)
    	   	  {
    		    fprintf(fres,"\n good level");
    		  } 
    
    /*
                     if (SUCCESS == mdlLevel_getName( levelName, 50, MASTERFILE, levelid ))
                    {
                      fprintf(fres,"\nlevel name = %s",levelName);
                    }
    */	
    
                    }
    
    
    
    
    	return 1;
    }
    

Reply
  • And here is the full code for my test program:

    /*
    	ShowLevels - test program
    */
    
    /*---------------------------------------------------------------------------
     Include Files
    -----------------------------------------------------------------------------*/
    #include <stdlib.h>		/* Standard "C" library			*/
    #include <stdio.h> 		/* Standard "C" I/O library     	*/
    #include <string.h> 		/* "C" lib to operate with "string" 	*/
    #include <ctype.h> 		/* "C" lib to operate with "symsol" 	*/
    #include <time.h>           	/* "C" lib to operate with "time"	*/
    
    #include <mdl.h>		/* Main include file for MDL   		*/
    #include <rscdefs.h>		/* Resource Manager Structure Definitions */
    #include <msrsrc.fdf>		/* Resource Manager function prototypes */
    #include <msdefs.h>		/* Defines for MicroStation data structures */
    #include <msrsrc.fdf>		/* Resource Manager function prototypes */
    #include <cexpr.h>		/* Defs for C Expression evaluation functions */
    #include <mscexpr.fdf>		/* C Expression evaluation function Prototypes */
    #include <mselems.h>           	/* Definitions for MicroStat. elements 	*/
    #include <mselmdsc.fdf>		/* MicroStation element function Prototypes */
    #include <dlogitem.h>		/* Dialog Box Item definitions 		*/
    #include <msdialog.fdf>		/* Dialog Box Function Prototypes 	*/
    #include <dbdefs.h>		/* Database definitions		 	*/
    #include <dberrs.h>		/* Database error return codes		*/
    #include <dbserver.h>		/* Database Server Definitions		*/
    #include <rdbmslib.fdf>		/* Database Function Definitions	*/
    #include <msoutput.fdf>		/* Output function Prototypes           */
    #include <msinputq.h>		/* Input queue definitions for MicroStation/MDL */
    #include <msinput.fdf>		/* Input queue Prototypes for MicroStation/MDL */
    #include <scanner.h>		/* Definitions for design files "scanner"	*/
    #include <msscan.fdf>		/* Function Prototypes for "scanner" */
    #include <mscnv.fdf>		/* Prototypes for Convert functions     */
    #include <tcb.h>		/* Definitions for "terminal control block" */
    #include <errno.h>		/* Standard Library error codes		*/
    #include <mssystem.fdf>		/* System function Prototypes           */
    #include <msoutput.fdf>		/* Output function Prototypes           */
    #include <msview.fdf>		/* View function Prototypes             */
    #include <msfile.fdf>		/* File function Prototypes             */
    
    #include <leveltable.fdf>
    
    #include "ShowLevels.h"
    
    /*--------------------------------------------------------------------
      Local Defines 
    ----------------------------------------------------------------------*/
    #define MAX_SIGNALS	1000
    #define MAX_ELEMS	1000
    #define NUM_CELLNAMES	43
    #define LEN_SQL 	256
    
    
    /*---------------------------------------------------------------------
      Global Data 
    ----------------------------------------------------------------------*/
    DialogBox  *GL_dbP;
    //char    GL_text[16], GL_signalName[8], GL_lever[8];
    char    GL_text[50], GL_signalName[25], GL_lever[25];
    int     GL_numLink; 	/* number Signals to be  linked */
    int     GL_numRes; 	/* number Signals currently linked */
    int     GL_numErr;
    FILE	*fres;
    
    
    /*---------------------------------------------------------------------
      Function Prototypes 
    ----------------------------------------------------------------------*/
    Public  void    findDFitems	(void);
    
    Public  int   	getItemLevel	(MSElement *);
    
    char    GL_cellNames[NUM_CELLNAMES][8] =
            {
            "SIG1L","SIG2L","SIG3L","SIG4L","SIG5L","SIG6L",
            "SIG1R","SIG2R","SIG3R","SIG4R","SIG5R","SIG6R",
            "SIG1A","SIG2A","SIG3A","SIG4A","SIG5A","SIG6A",
            "SIG1B","SIG2B","SIG3B","SIG4B","SIG5B","SIG6B",
            "SIG1C","SIG2C","SIG3C","SIG4C","SIG5C","SIG6C",
            "SIG1D","SIG2D","SIG3D","SIG4D","SIG5D","SIG6D",
            "SIG6AR","SIG1BR","SIG5BR",
    	"SIG1CR","SIG4CR","SIG5CR","SIG6DR"
            };
    
    int	GL_itemLevels[3]= {12,30,48};
    
    struct
    {
      int  mslink;
      char name[16];
      char lever[16];
    } GL_signals[MAX_SIGNALS];
    
    FILE	*fres;
    
    int main(int argc, char *argv[])
    {
            char str[128], *alertDir;
     int    status,n,m;
    
            alertDir = getenv("ALERT_DIR");
            strcpy(str,alertDir);
            strcat(str,"maint\\link\\testlog.txt");
            if ( (fres=fopen(str,"w")) == NULL ) 
            {
               printf("Can not open file %s",str);
               mdlSystem_exit(0,1);
            }
    
     	fprintf(fres,"ShowLevels started");
    
     	findDFitems();
    
    //        newSearch(); 
    
     	fprintf(fres,"\n\nfindDFitems complete");
    
    
    
     	fprintf(fres,"\n\nShowLevels ended");
         fclose(fres);
    	mdlSystem_exit(0, 1);
    	return 0;
    }
    
    /*-------------------------------------------------------------------------
      name          findDFitems
      A function to find all Signals in the active design
      file using cell names as search criterion
    --------------------------------------------------------------------------*/
    Public void     findDFitems()
    {
     ULong          elemAddr[MAX_ELEMS], eofPos, filePos, newFilePos, readFilePos;
     int            scanWords, status, status1, i, j, n, m, numAddr, numItems, 
    		exist=0, linkCount, level, mslink;
     ExtScanlist    scanList;
     MSElementDescr *edP, *newEdP;
     MSElement      *elP;
     short          cellNameR50[2];
     char           cellNameAsc[16], str[128], word2[16], word3[16], division[8];
     DatabaseLink   *links[10];
     double		x, y;
     int ttt = 0;
    
    
    fprintf(fres,"\n\nfindDFitems Beginning");
    
     for ( j = 0; j < NUM_CELLNAMES; j++ )
     {
    	strcpy(cellNameAsc,GL_cellNames[j]);
    	mdlScan_initScanlist (&scanList);
    	mdlScan_noRangeCheck (&scanList);
    	memset(scanList.typmask,0x00,sizeof(scanList.typmask));
    	memset(cellNameR50,0,sizeof(cellNameR50));
    
            scanList.scantype       = ELEMTYPE | PICKCELL;
    	scanList.extendedType   = FILEPOS;
    	scanList.typmask[0]     = TMSK0_CELL_HEADER;
    
    	mdlCnv_fromAsciiToR50(strlen(cellNameAsc),cellNameAsc,cellNameR50);
    
    	/* Initialize the scanlist for use w/ the masterfile (file 0) */
    	eofPos = mdlElement_getFilePos (FILEPOS_EOF,NULL);
    
    	mdlScan_initialize (MASTERFILE, &scanList);
    
    	filePos = 0L; /* start search from top of file */
    	do 
    	{
    	   scanWords = sizeof(elemAddr)/sizeof(short);
    	   status = mdlScan_file (elemAddr,&scanWords,sizeof(elemAddr),
    		    &filePos);
    
    	   numAddr = scanWords/sizeof(short);
    
    	   for ( i=0; i<numAddr; i++ )
    	   {
    		if (elemAddr[i] >= eofPos) break;
    		mdlElmdscr_read (&edP,elemAddr[i],0,FALSE,&readFilePos);
    
    		/* 1. Check if this Signal already has Link 
    		*/ 
                    elP = &edP->el;
    
    		/* 2. Get Signal Level and find the Division */
    		level = getItemLevel(elP);
    
    		mdlElmdscr_freeAll( &edP ); 
    	   }
     
    	} while (status == BUFF_FULL);
     }
    }
    
    /*-------------------------------------------------------------------------
      getItemLevel		
    --------------------------------------------------------------------------*/
    Public int getItemLevel(MSElement *elP)
    {
    
    MSWChar levelName [50];
    UInt32  levelid;
    
                     //elements are graphic
                     if(elP->ehdr.isGraphics)
                     {
                      fprintf(fres,"\n element is graphic");  
    
    		  mdlElement_getProperties ( &levelid , NULL , NULL , NULL, NULL , NULL, NULL, NULL, elP );
    		  fprintf(fres,"\n level id: %d", levelid);
                      if (levelid != 0)
    	   	  {
    		    fprintf(fres,"\n good level");
    		  } 
    
    /*
                     if (SUCCESS == mdlLevel_getName( levelName, 50, MASTERFILE, levelid ))
                    {
                      fprintf(fres,"\nlevel name = %s",levelName);
                    }
    */	
    
                    }
    
    
    
    
    	return 1;
    }
    

Children
No Data