cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Archicad C++ API
About Archicad add-on development using the C++ API.

How to assign a texture to an API_MaterialType

mats1
Contributor

I have a program to create a custom API_Attribute with a specific color. Now i want to assign a texture to it. I have found a list of images using LibraryManager::FindLibParts but when i assign the texture to the API_MaterialType in API_Attribute it is like it is not saved.

API_Attribute material;
BNZeroMemory(&material, sizeof(API_Attribute));

 

auto libParts = libraryManager->FindLibParts(
    [](const ACAPI::Library::LibPart &libPart) {
      return ACAPI::Library::v1::SelectImageLibParts(libPart);
    });

auto libPart = libParts[0];

IO::Location fLoc;
BNZeroMemory(&fLoc, sizeof(IO::Location));
auto tmp = libPart.GetLocation().Unwrap();
memcpy((void *)&fLoc, (void *)&tmp, sizeof(IO::Location));

 

then i am assigning it to my API_Attribute like this:

material.material.texture.fileLoc = &fLoc;
memcpy(material.material.texture.texName, libPart.GetName()->ToCStr(),
        256);
material.material.texture.status = 4096;
material.material.texture.xSize = 250;
material.material.texture.ySize = 250;


Please help me, thanks in advance!

3 REPLIES 3
Krille-Alster
Participant

Very good question Mats.

mats1
Contributor

I even tried this but it didn't work.

material.material.texture.fileLoc = new IO::Location(
    "/Applications/Graphisoft/Archicad 28/Archicad "
    "bibliotekspaket/Surface Catalog.libpack/Surface Catalog.lcf/Surface "
    "Catalog/[Timg] Textures/Concrete/Concrete - 02 -opt.jpg");
unsigned char binaryData[] = {66, 101, 116, 111, 110, 103, 32,  45,
                              32, 48,  50,  32,  45,  111, 112, 116};
for (int i = 0; i < 16; i++) {
  material.material.texture.texName[i] = binaryData[i];
}

material.material.texture.ySize = 250;
material.material.texture.xSize = 250;
material.material.texture.withoutExtension = false;
Krille-Alster
Participant

hanginthere.jpg

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!