2017-12-19 08:00 PM - last edited on 2022-12-06 01:47 PM by Daniel Kassai
short nMaterials = 0; ACAPI_Attribute_GetNum (API_MaterialID, &nMaterials); for ( short i = 1; i <= nMaterials; i++ ) { BNZeroMemory( &attrib, sizeof ( API_Attribute ) ); attrib.header.typeID = API_MaterialID; attrib.header.index = i; GSErrCode err2 = ACAPI_Attribute_Get( &attrib ); ... }The materials which aren't caught begin with "GDLM", for example: GDLM33_builtInMatAppleTop. They are only found when iterating through the meshes like this:
... BNZeroMemory ( &component, sizeof ( component ) ); component.header.typeID = API_BodyID; component.header.index = ibody; err = ACAPI_3D_GetComponent (&component); API_Component3D material; BNZeroMemory ( &material, sizeof ( material ) ); material.header.typeID = API_UmatID; material.header.index = (GS::Int32)component.body.iumat; GS::UniString uniStringName; material.umat.mater.head.uniStringNamePtr = &uniStringName; GSErrCode err = ACAPI_3D_GetComponent ( &material ); if ( err == NoError ) { ... // }
2017-12-21 03:47 PM
IanTr wrote:I think the origin of the problem is the dynamic nature of these materials. They're defined by scripts, so are subject to sudden change from one view to another.
I'm trying to get a list of all materials used in the project. The following code catches most materials, however there seems to be some type of material which isn't caught [...]
Is there a way for me to get all the materials including GDLM materials without looping through all the meshes?
2018-01-05 02:11 PM
Ralph wrote:Ralph is right, you can get the materials defined in GDL scripts that way, and right again that not all indexes are valid.IanTr wrote:I think the origin of the problem is the dynamic nature of these materials. They're defined by scripts, so are subject to sudden change from one view to another.
I'm trying to get a list of all materials used in the project. The following code catches most materials, however there seems to be some type of material which isn't caught [...]
Is there a way for me to get all the materials including GDLM materials without looping through all the meshes?
There is a way you may be able to us the ModelerAPI to avoid iterating through the entire model, but I haven't tried it myself. If you have an instance of aModelobject, you can find the highest material index by calling its GetMaterialNummethod. You could iterator through every value from 1 to this value calling the GetMaterialmethod, but I doubt you could assume that every index would return a valid (current) material. Worth a try though – someone from GS might be able to confirm.