Choose your top Archicad wishes!

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

Custom GUID

Anonymous
Not applicable
I'm playing around with different Create functions. I have noticed that a new element has always new GUID. When I'm passing GUID in element it is getting new GUID anyway. In some cases, I would like to define my own GUID and create an element with it. Is this possible?
15 REPLIES 15
Anonymous
Not applicable
I have some troubles with overwriting data. I assumed that the easiest way would be to delete user data and set a new one. Here is my attempt. But as always the easiest way doesn't work at all. As pointed in docs I used nullptr to delete data. I assume that some treatment od memorychannel is necessary, but all my attempts just crashed AC. Please help.
	GS::ErrCode MyUserData::DelToAttrib(const API_Attribute& attrib) const {
		API_AttributeUserData userData = {};
		userData.dataHdl = nullptr;
	        API_Attr_Head attHead = {};
		attHead.index = attrib.header.index;
		attHead.typeID = attrib.header.typeID;
		GSErrCode err = ACAPI_Attribute_SetUserData(&attHead, &userData);
		BMKillHandle(&userData.dataHdl);
		return err;
		}
Anonymous
Not applicable
Any suggestions ?
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
kzaremba wrote:
Do you think there is a possibility to start GitRepository (or similar solution) to create the library of classes working with actual API (like the example above)? So if someone is interested in developing such an approach could collaborate and build upon some examples like this? This might be an even better way to share this knowledge than the forum where some topics are covered by the others.
Yes, it's possible, but could be very hard to maintain.
There should be an attached continous integration system which builds the code after anybody pushed some modification to make sure it builds successfully and it runs tests to make sure it still works correctly.
Without this system I think that repository can be a big mess after few years (or it would take too many effort for somebody to maintain).
Anonymous
Not applicable
Ok. I thought its easier since you have version control and branching. Anyway, I understand that there are no plans for reorganizing API?
I did some prototypes of polymorphic classes based on API and it seems much easier to build up commands and much less code to maintain.
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
kzaremba wrote:
I have some troubles with overwriting data. I assumed that the easiest way would be to delete user data and set a new one.
You don't have to delete the userdata, because if you call ACAPI_Attribute_SetUserData to the attribute for the second time then it will automatically overwrite the existing userdata.
kzaremba wrote:
I assume that some treatment od memorychannel is necessary, but all my attempts just crashed AC. Please help.

...
		userData.dataHdl = nullptr;
...
		BMKillHandle(&userData.dataHdl);
...
Your code is ok, except the BMKillHandle call, I think that line caused the crash, because the userData.dataHdl is nullptr there.
Anonymous
Not applicable
Aaaa... ok. Works now. Thank you!