Hello everybody,
Is there any MDL function which return directley the level name where an object is created ?
Actually, I use the two mdl function in order to get the level name as follows:
wnomNiveau[DKM_MAX_LEVEL_NAME_LENGTH] type MSWChar
idNiveau type UInt32 elmDscrP type MSElementDescr*
mdlElement_getProperties ( &niveau , NULL , NULL , NULL, NULL , NULL, NULL, NULL, &mselmDscrP->el ); mdlLevel_getName( wnomNiveau, DKM_MAX_LEVEL_NAME_LENGTH, MASTERFILE, idNiveau );
that's work fine, but, I'd like to know if is there an MDL function which allows the recuperation of the level name directly from the mselmDscrP->el variable without use of the variable idNiveau.
Thanks.
Unknown said: Is there any MDL function which return directley the level name where an object is created ?
Actually you can get levelID using mdlElmdscr_getProperties(). But it does not give correct results on nested cells.
Unknown said: mdlElement_getProperties ( &niveau , NULL , NULL , NULL, NULL , NULL, NULL, NULL, &mselmDscrP->el ); mdlLevel_getName( wnomNiveau, DKM_MAX_LEVEL_NAME_LENGTH, MASTERFILE, idNiveau );
Your method seems correct but it fails for cell headers or solids because they start with a header element and it returns 0 as levelID. You may check this on MicroStation element information dialog by navigating cells or solids.
Instead, I am getting level ID of first graphics element inside an element descriptor.
// Element function to get level of first graphics element after the headerint akElmfunc_getLevel( MSElementUnion *elP, /* <=> element to be modified */ UInt32 *levelID, /* => user parameter ( level of elmdscr ) */ DgnModelRefP fileNum, /* => file # for current elem */ MSElementDescr *elmDscrP, /* => element descr for elem */ MSElementDescr **newDscrPP /* <= if replacing entire descr */){
if(elP->ehdr.isGraphics) { // Get level of the first graphics element mdlElement_getProperties (levelID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, elP); return (MODIFY_STATUS_ABORT); // Level got, abort process } return (MODIFY_STATUS_NOCHANGE);}
// Get level ID of an element descriptor
int akElmdscr_getLevel( MSElementDescr **edP, ULong *levelid)
{ int status;
*levelid = 0;
#if defined (MSVERSION) && (MSVERSION >= 0x8b0) status = mdlModify_elementDescr2(edP,ACTIVEMODEL,MODIFY_REQUEST_NOHEADERS, akElmfunc_getLevel,levelid,0); #else status = mdlModify_elementDescr(edP,ACTIVEMODEL,MODIFY_REQUEST_NOHEADERS, akElmfunc_getLevel,levelid,0); #endif
return status;
}
Alternatively, you may use mdlElmdscr_operation() instead of mdlModify_elementDescr(), but I prefered mdlModify_elementDescr() because it has option to filter some unneeded elements like headers.
Hope this helps.
Kind regards,
Sedat AlisAEC Technology Inc.
Answer Verified By: cdiTech
Unknown said:Can you update mdlElmdscr_getProperties() function to return Level ID of first graphics element?
I assume that you're discussing a complex element descriptor, such as a cell.
If that function were to return a property of the first element, how would you ever discover the properties of other elements in the descriptor chain? It's easy enough to write your own function that examines the properties of the first graphic element in a complex descriptor...
MSElementDescr* FirstGraphicComponent (MSElementDescr const* pComplex) { // Get complex element from somewhere MSElementDescr* pComponent = pComplex->h.firstElem; while (pComponent) { if (pComponent->el.ehdr.IsGraphics) return pComponent; pComponent = pComponent->h.next; } return NULL; }
Regards, Jon Summers LA Solutions
Unknown said: I assume that you're discussing a complex element descriptor, such as a cell.
You are right, complex elements must return correct level ID too.
Unknown said: If that function were to return a property of the first element, how would you ever discover the properties of other elements in the descriptor chain? It's easy enough to write your own function that examines the properties of the first graphic element in a complex descriptor... MSElementDescr* FirstGraphicComponent (MSElementDescr const* pComplex) { // Get complex element from somewhere MSElementDescr* pComponent = pComplex->h.firstElem; while (pComponent) { if (pComponent->el.ehdr.IsGraphics) return pComponent; pComponent = pComponent->h.next; } return NULL; }
A good alternative, thanks.
Actually I mentioned to fix the problem on an existing function mdlElmdscr_getProperties().
Michael Stark said: Ahmet, there is no problem with the existing function, as the cell-header has no level assigned, it MUST NOT return any of the underlying elements level-Id. As soon as you have underlying elements on different levels it will always return the false one. And even if all underlying elements are on the same level, there's no reason to return a level for the cell-header when no one is assigned.
Ahmet, there is no problem with the existing function, as the cell-header has no level assigned, it MUST NOT return any of the underlying elements level-Id. As soon as you have underlying elements on different levels it will always return the false one. And even if all underlying elements are on the same level, there's no reason to return a level for the cell-header when no one is assigned.
Michael thank you. Actually if you think all component elements of an element descriptor can be on different levels, it is not meaningful for mdlElemdscr_getProperties to return the level of the first element. We assume that all elements inside the element descriptor is in the same level otherwise it can't return a single level ID.
Unknown said:We assume that all elements inside the element descriptor is in the same level otherwise it can't return a single level ID.
Thought so, and in your case this assumption might work and last for long time. Nevertheless the API was made (and had to work) for general purposes, so Jon's solution is the one you have to choose.
I permanently create cells with at least 2 different levels, 3D/2D/Text is strictly distinct at our application, and even those components might consist of different levels inside (i.e. a chair has different 3D levels for the wooden and textile parts). So your assumption should not result in changes in the API, even not as an optional switch/flag. We are programmers, we need to understand the underlying structures and their restricitions. Such discussion are good to show even differences in the viewpoint of different developers. Together we will almost find a solution, and (hopefully) understand why this or that decision was made by the APi developers.
Unknown said:We assume that all elements inside the element descriptor is in the same level otherwise it can't return a single level ID
What about a cell? A cell would be rather dull if its components could sit on only one level!
Thanks Michael and Jon. As a result of this conversation, let's say mdlElmdscr_getProperties must return a list of levels. :)
Unknown said:let's say mdlElmdscr_getProperties must return a list of levels