Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

referencing by name, not index number

TomWaltz
Newcomer
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
Newcomer
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.

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!