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

referencing by name, not index number

TomWaltz
Participant
I am digging through the settings for defaults of different element types, and I found that many attributes are referenced by number, not name.

So if I want to set the font to "Arial" or the layer to "Text - Notes," I have to reference them by their index number (??!??!), not their actual name.

Is there any way around this that I'm not seeing?

Thanks!
Tom Waltz
3 REPLIES 3
Akos Somorjai
Graphisoft
Graphisoft
Tom,

The element structures store only the indices of the attributes they refer to. The reasons behind that are synchronization and memory saving.

So, if you know the name of the attribute you'd like to set for an element, then for example in the layer case:
API_Attribute attr;
BNZeroMemory (&attr, sizeof (API_Attribute));
attr.header.typeID = API_LayerID;
CHCopyC ("Text - Notes", attr.header.name);

// now see if this layer exists
if (ACAPI_Attribute_Search (&attr) == NoError) {
    // bingo! put the index in the element's header
    element.header.layer = attr.header.index;
} else {
    // exercise for the reader
    // e.g. create a new, or
    // search for another suitable layer 
}
HTH,

Akos
TomWaltz
Participant
Akos,

that seemed to be the funciton I was looking for,

When I compiled, though, the compiler gave me an error that ACAPI_Attribute_Search () requires a header, not an attribute.

Should that line then read:
ACAPI_Attribute_Search (&attr.header)
Tom Waltz
Andras Babos
Graphisoft Alumni
Graphisoft Alumni
TomWaltz,

Yes, you're right. That was a typo on Akos' part.