Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Retrieve and update the surface color override

allen-work
Participant

Hello, could you please help to advise what API I could use to retrieve and update the surface colour override for an element?

 

SCR-20231110-kftg.png

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Viktor Kovacs
Graphisoft
Graphisoft

This is an element-specific parameter so the way to change the override is dependent on the element type. Let's say you have a guid for an element (for example by enumerating selected elements) and the index of the new Surface (called Material on the API). This code will do the trick for Walls and GDL objects. The other elements work in a very similar way.

API_Element element = {};
element.header.guid = elementGuid;
ACAPI_Element_Get (&element);

API_AttributeIndex newMaterialIndex = ACAPI_CreateAttributeIndex (15);

API_Element mask = {};
ACAPI_ELEMENT_MASK_CLEAR (mask);
switch (element.header.type.typeID) {
    case API_WallID:
        element.wall.refMat = newMaterialIndex;
        element.wall.oppMat = newMaterialIndex;
        element.wall.sidMat = newMaterialIndex;
        ACAPI_ELEMENT_MASK_SET (mask, API_WallType, refMat);
        ACAPI_ELEMENT_MASK_SET (mask, API_WallType, oppMat);
        ACAPI_ELEMENT_MASK_SET (mask, API_WallType, sidMat);
        break;
    case API_ObjectID:
        element.object.mat = newMaterialIndex;
        element.object.useObjMaterials = false;
        ACAPI_ELEMENT_MASK_SET (mask, API_ObjectType, mat);
        ACAPI_ELEMENT_MASK_SET (mask, API_ObjectType, useObjMaterials);
        break;
}

ACAPI_Element_Change (&element, &mask, nullptr, 0, true);

 

View solution in original post

2 REPLIES 2
Solution
Viktor Kovacs
Graphisoft
Graphisoft

This is an element-specific parameter so the way to change the override is dependent on the element type. Let's say you have a guid for an element (for example by enumerating selected elements) and the index of the new Surface (called Material on the API). This code will do the trick for Walls and GDL objects. The other elements work in a very similar way.

API_Element element = {};
element.header.guid = elementGuid;
ACAPI_Element_Get (&element);

API_AttributeIndex newMaterialIndex = ACAPI_CreateAttributeIndex (15);

API_Element mask = {};
ACAPI_ELEMENT_MASK_CLEAR (mask);
switch (element.header.type.typeID) {
    case API_WallID:
        element.wall.refMat = newMaterialIndex;
        element.wall.oppMat = newMaterialIndex;
        element.wall.sidMat = newMaterialIndex;
        ACAPI_ELEMENT_MASK_SET (mask, API_WallType, refMat);
        ACAPI_ELEMENT_MASK_SET (mask, API_WallType, oppMat);
        ACAPI_ELEMENT_MASK_SET (mask, API_WallType, sidMat);
        break;
    case API_ObjectID:
        element.object.mat = newMaterialIndex;
        element.object.useObjMaterials = false;
        ACAPI_ELEMENT_MASK_SET (mask, API_ObjectType, mat);
        ACAPI_ELEMENT_MASK_SET (mask, API_ObjectType, useObjMaterials);
        break;
}

ACAPI_Element_Change (&element, &mask, nullptr, 0, true);

 

Viktor, you have provided an accurate solution, thank you so much!