How to list all cells in two cell libraries

Hi, There,

I am developing an app with a dialogue box with two list boxes. I need to list all cells in two different cell libraries. I tried to following code assuming lib1 is attached to the master file, the file name lib2 is known:

mdlCell_getLibraryObject(&modelRefLib1, tcb->celfilenm, FALSE);
mdlWorkDgn_openFile (&modelRefLib2, NULL, NULL, lib2FileName, NULL, TRUE);

In the list box hook function, when each list box was created, the string list was loaded in the same way using the following functon:

Public int CellMgr_loadStringList
(
StringList *strListP, //<=>
DgnFileObjP srcLib //==> modelRefLib1/modelRefLib2 was passed in
)
{
char cellName[MAX_CELLNAME_LENGTH];
char cellDscr[MAX_CELLNAME_LENGTH];
MSWChar mdlName[MAX_CELLNAME_LENGTH];
int offset;
DgnIndexIteratorP dgnIdxIterP;
DgnIndexItemP dgnIdxItemP;

// Create a model iterator: each cell is a model in a cell lib
dgnIdxIterP = mdlModelIterator_create (srcLib);

mdlModelIterator_setAcceptCellsOnly (dgnIdxIterP, TRUE);

/* Advances the iterator object through each model */
dgnIdxItemP = mdlModelIterator_getNext (dgnIdxIterP);

while (dgnIdxItemP)
{ // Get model name, i.e. the cell name.
mdlModelItem_getName (dgnIdxItemP, mdlName, MAX_CELLNAME_LENGTH);

mdlCnv_convertUnicodeToMultibyte (mdlName, -1, cellName, MAX_CELLNAME_LENGTH);
strpspc (cellName);

// Get model description, i.e. the description name.
mdlModelItem_getDescription(dgnIdxItemP, mdlName, MAX_CELLDSCR_LENGTH);

mdlCnv_convertUnicodeToMultibyte (mdlName, -1, cellDscr, MAX_CELLDSCR_LENGTH);

/* --- if we have the correct section type add to string list --- */
mdlStringList_insertMember (&offset, strListP, -1, NUM_COLUMNS);

/* --- place blank in column 1 --- */
mdlStringList_setMember (strListP, offset, " ", NULL);

/* --- place cell name in column 2 --- */
mdlStringList_setMember (strListP, offset, cellName, NULL);

/* --- place cell description in column 3 --- */
mdlStringList_setMember (strListP, offset, cellDscr, NULL);

dgnIdxItemP = mdlModelIterator_getNext (dgnIdxIterP);
} // end of while(dgnIdxItemP)

/* --- sort the stringlist by cell name --- */
mdlStringList_sortByColumn (strListP, -1, TRUE, NULL, NUM_COLUMNS, 1);

mdlOutput_prompt (" ");

return SUCCESS;
} // end of loadStringList()
For lib1, the above code worked perfectly, loading all cells into the list. However, for lib2, the while loop did not run at all. So the lib2 list was not loaded at all. For the testing purpose, the lib1 is a copy of lib2, so these two lists should look the same.
Please advise what is the problem above code.  Any suggestions will be greatly appreciated.
Ken
  • Unknown said:
    mdlCell_getLibraryObject(&modelRefLib1, tcb->celfilenm, FALSE);
    mdlWorkDgn_openFile (&modelRefLib2, NULL, NULL, lib2FileName, NULL, TRUE);
    
    

    mdlCell_getLibraryObject gets a DgnFileObjP, whereas mdlWorkDgn_openFile gets a DgnModelRefP. Your function CellMgr_loadStringList wants a DgnFileObjP.

    Why not use mdlCell_getLibraryObject for both? There's nothing in the documentation to say that it has to be the currently-attached cell library.

    Prefer ListModel to StringList

    While it's not illegal to use StringLists, compared to the ListModel they are crude. ListModels can store and display several different data types, including number, text (both multibyte and Unicode) and even graphics. There are some ListModel examples on our web site.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Hi, Jon,

    Thanks for your reply.

    After checking the existence of my lib2 file, I did try to use mdlCell_getLibraryObject to create the DgnFileObjP. However, this function call always return an ERROR. So, this lead me to believe that it only worked with  he currently-attached cell library.

    Regards,

    Ken

  • Hi, Jon,

    I tried it again by changing the last argument of the function from FALSE to TRUE and it worked! i.e.

    mdlCell_getLibraryObject(&dgnFileObj2, lib2Name, TRUE);

    It does not making any sense according to the MDL manual since I passed the lib2Name with full path.

    Any how, it is MDL which does not making sense all the time.

    Thanks again for your help.

    You are a TRUE MVP.

    Ken

  • Unknown said:
    I tried it again by changing the last argument of the function from FALSE to TRUE and it worked!

    It is MDL which does not making sense all the time

    The V8i documentation for the last argument has this:

    Unused; pass FALSE

    So I absolutely agree with your comment   8-)

     
    Regards, Jon Summers
    LA Solutions

  • The saga continue ...

    When I tried to add a new cell to the attached cell lib (my lib1) by calling mdlCell_addLibDescr (cellDP, 1, TRUE) it returned error with mdlErrno set to -110 (MDLERR_WRITEINHIBIT)

    However, the cell was created correctly in the attahced lib.

    Not sure what is going on!!!!

    Ken

  • One more wired thing ...

    When I found the newly created cell in the attached cell lib, I tried to delete it, I got a dialogue box informing me that the deletion failed duo to the lib  is protected. However, when I close the MicroStation cell lib dialogue box and open it again, the cell disappeared.

    What a frustrating day!

    Ken