Hi Folks,
Is there any body used mdlMaterial_functions in mdl programming. Iam trying to use the material functions to assign or attach materails to the the building faces. I found source code examples nowhere. Could you please any one share yours knowledge or any source codes ?.
Thanks in Advance
Nataraju
Nataraju: Is there any body used mdlMaterial_functions in MDL programming?
You're right — there aren't any substantial examples.
Getting and assigning materials is largely a matter of getting and chasing pointers. I'm not an expert in materials, so maybe someone else can chime in. Here's something to get you started:
MaterialNode *pNode = NULL; DgnModelRefP modelRef = ACTIVEMODEL; //Initialise materials for your MDL mdlMaterial_initialize (); mdlMaterial_getTable (&pNode, modelRef); if (NULL != pNode) { MaterialNode *pCurrent = pNode; while (pCurrent) { //Do something with pCurrent pCurrent = pCurrent->next; } // To Clean up the material Node when done use : mdlMaterial_deleteNode (&pNode, pNode, modelRef); } //Free materials for your MDL mdlMaterial_cleanup ();
Regards, Jon Summers LA Solutions
Now, when there are new types of materials, I'm not sure, whether these functions will work.
I found this on old forum (discussion.bentley.com):
KIBODY* sphereP; MSElementDescr* edP; ULong elmFilePos; // create a new element mdlKISolid_beginCurrTrans(MASTERFILE); mdlKISolid_makeSphere(&sphereP, radius); mdlKISolid_bodyToElement(&edP, sphereP, TRUE, -1, 0, MASTERFILE); mdlKISolid_freeBody(sphereP); mdlKISolid_endCurrTrans(); // Write it to the design file elmFilePos = mdlElmdscr_add(edP); // create a material attachment linkage { MaterialLinkageData data; LinkageHeader linkHdr; memset(&linkHdr, 0, sizeof(linkHdr)); linkHdr.primaryID = LINKAGEID_Material; linkHdr.user = 1; strcpy(data.name, "Blue"); data.nameSize = strlen(data.name); printf("appendUsingDescr\n"); if (mdlLinkage_extractUsingDescr (&data, edP, LINKAGEID_Material, 0, NULL, NULL, NULL, FALSE)) mdlLinkage_deleteUsingDescr (&edP, LINKAGEID_Material, 0, NULL, NULL, NULL, FALSE); if (mdlLinkage_appendUsingDescr(&edP, &linkHdr, &data, LINKAGEID_Material, NULL, FALSE) == SUCCESS) printf("success\n"); else printf("no success\n"); printf("end\n"); }
KIBODY* sphereP; MSElementDescr* edP; ULong elmFilePos;
// create a new element mdlKISolid_beginCurrTrans(MASTERFILE); mdlKISolid_makeSphere(&sphereP, radius); mdlKISolid_bodyToElement(&edP, sphereP, TRUE, -1, 0, MASTERFILE); mdlKISolid_freeBody(sphereP); mdlKISolid_endCurrTrans();
// Write it to the design file elmFilePos = mdlElmdscr_add(edP);
// create a material attachment linkage { MaterialLinkageData data; LinkageHeader linkHdr; memset(&linkHdr, 0, sizeof(linkHdr)); linkHdr.primaryID = LINKAGEID_Material; linkHdr.user = 1; strcpy(data.name, "Blue"); data.nameSize = strlen(data.name); printf("appendUsingDescr\n"); if (mdlLinkage_extractUsingDescr (&data, edP, LINKAGEID_Material, 0, NULL, NULL, NULL, FALSE)) mdlLinkage_deleteUsingDescr (&edP, LINKAGEID_Material, 0, NULL, NULL, NULL, FALSE); if (mdlLinkage_appendUsingDescr(&edP, &linkHdr, &data, LINKAGEID_Material, NULL, FALSE) == SUCCESS) printf("success\n"); else printf("no success\n"); printf("end\n"); }
I was able to attach a material to an element descriptor using the code posted by Dan Paul, with the following changes:
Saxon Druce
Saxon: After setting ... Pass zero ... No need to call mdlLinkage_extractUsingDescr() or mdlLinkage_deleteUsingDescr(). Call mdlElmdscr_rewrite() ... A call to mdlMaterial_cleanup() ...
The material library is tortuous, so congrats. on navigating a path through the maze.
Put matched calls from the MDL API into a C++ struct or class constructor/destructor. That way, you can't forget the second of the matched pair:
// Class definition/implementation in MaterialAPI.h #include <material.fdf> struct CMaterialAPI { CMaterialAPI () { mdlMaterial_initialize (); }; ~CMaterialAPI () { mdlMaterial_cleanup (); }; }; // Usage in myApp.cpp #include "MaterialAPI.h" { CMaterialAPI material_raii; // Calls mdlMaterial_initialize ... your code that uses mdlMaterial_xxx } // Destructor called when CMaterialAPI goes out of scope: calls mdlMaterial_cleanup