I am trying to get all the appearances of a component using IGetRenderMaterial function. First, I get the number of render materials in the component using GetRenderMaterialsCount(). This function seems to be working fine, and gives the right number of render materials applied to my model. After that I try to use IGetRenderMaterials to get the different appearances, and that is where the problem arises. I can only access one material using the IGetRenderMaterial function. My program crashes when I try to access anything after the first appearance. Can anyone point me in the right direction?
SolidworksApi macroslong renderMaterialCount = 0;
if (SUCCEEDED(pComponent->GetRenderMaterialsCount(&renderMaterialCount)))
{
cout << "RenderMaterialCount = " << renderMaterialCount << "\n";
if(renderMaterialCount > 0)
{
IRenderMaterial *renderMaterials;
if (SUCCEEDED(pComponent->IGetRenderMaterials(renderMaterialCount, &renderMaterials)))
{
BSTR texName;
string texNameStr;
// Trying to access index 1 or later of renderMaterials crashes the program.
for (int rmc = 0; rmc < renderMaterialCount; rmc++)
{
if (SUCCEEDED(renderMaterials[rmc].get_TextureFilename(&texName)))
{
EcWSTRING2STRING(texName, texNameStr);
cout << "Texture filename: " << texNameStr << "\n";
}
else
{
cout << "Render material cannot be accessed. \n";
}
}
}
}
}