License Delivery maintenance is expected to occur on Saturday, November 30, between 8 AM and 11 AM CET. This may cause a short 3-hours outage in which license-related tasks: license key upload, download, update, SSA validation, access to the license pool and Graphisoft ID authentication may not function properly. We apologize for any inconvenience.
Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Creating an Add-on for No. groups / SEO's

JGoode
Expert
Hello,

How difficult would it be to create an add-on that could calculate how many groups / SEO's there are in a project?

Thanks
ArchiCAD 23

Windows 10
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
static USize	GetNumberOfGroups () {
	GS::HashSet<API_Guid> groups;

	GSErrCode		err = NoError;
	GS::Array<API_Guid>	allElements;
	ACAPI_Element_GetElemList (API_ZombieElemID, &allElements);

	for (const API_Guid& guid : allElements) {
		API_Elem_Head head = {};
		head.guid = guid;
		err = ACAPI_Element_GetHeader (&head, APIElemMask_FromFloorplan);
		if (err != NoError)
			continue;
		if (head.groupGuid != APINULLGuid)
			groups.Add (head.groupGuid);
	}

	return groups.GetSize ();
}


static USize	GetNumberOfSolidLinks () {
	USize numberOfSolidLinks = 0;

	GSErrCode		err = NoError;
	GS::Array<API_Guid>	allElements;
	ACAPI_Element_GetElemList (API_ZombieElemID, &allElements);

	for (const API_Guid& guid : allElements) {
		API_Guid**	guid_Operators = nullptr;
		Int32		nLinks;
		err = ACAPI_Element_SolidLink_GetOperators (guid, &guid_Operators, &nLinks);
		BMhFree (reinterpret_cast<GSHandle> (guid_Operators));
		if (err != NoError)
			continue;
		numberOfSolidLinks += nLinks;
	}

	return numberOfSolidLinks;
}
I'm not sure this does exactly what you want, but if you need any further help, feel free to ask!

View solution in original post

15 REPLIES 15
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

It's very easy to get the number of the groups:
1. Get all elements using ACAPI_Element_GetElemList
2. Get the header for each retrieved element using ACAPI_Element_GetHeader
3. The groupGuid member in the API_Elem_Head structure identifies the group of the element.
So for example if you add these guids into a GS::HashSet, then the size of the HashSet will be the number of the groups.

Regards,
Tibor
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
static USize	GetNumberOfGroups () {
	GS::HashSet<API_Guid> groups;

	GSErrCode		err = NoError;
	GS::Array<API_Guid>	allElements;
	ACAPI_Element_GetElemList (API_ZombieElemID, &allElements);

	for (const API_Guid& guid : allElements) {
		API_Elem_Head head = {};
		head.guid = guid;
		err = ACAPI_Element_GetHeader (&head, APIElemMask_FromFloorplan);
		if (err != NoError)
			continue;
		if (head.groupGuid != APINULLGuid)
			groups.Add (head.groupGuid);
	}

	return groups.GetSize ();
}


static USize	GetNumberOfSolidLinks () {
	USize numberOfSolidLinks = 0;

	GSErrCode		err = NoError;
	GS::Array<API_Guid>	allElements;
	ACAPI_Element_GetElemList (API_ZombieElemID, &allElements);

	for (const API_Guid& guid : allElements) {
		API_Guid**	guid_Operators = nullptr;
		Int32		nLinks;
		err = ACAPI_Element_SolidLink_GetOperators (guid, &guid_Operators, &nLinks);
		BMhFree (reinterpret_cast<GSHandle> (guid_Operators));
		if (err != NoError)
			continue;
		numberOfSolidLinks += nLinks;
	}

	return numberOfSolidLinks;
}
I'm not sure this does exactly what you want, but if you need any further help, feel free to ask!
JGoode
Expert
Thanks for this, I haven't used the DevKit before, is there anything else I should know before implementing this?

Thanks
ArchiCAD 23

Windows 10
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
To be able to create a new AddOn, you will have to be able to generate new identifier (MDID). So first you have to register at archicadapi.graphisoft.com.
After the registration, which is free (the extra paid services are optional), you will be able to download the API DevKit and read the API documentation and our blog. You can find many usefull informations to getting started with development.
I recommend these articles:
http://archicadapi.graphisoft.com/getting_started_with_api_development_kit
http://archicadapi.graphisoft.com/life-of-an-archicad-add-on
http://archicadapi.graphisoft.com/hello-world-part-2-dialog-with-text-svg-icon-and-button

Feel free to ask any questions related to API on this forum or via email (archicadapi@graphisoft.com)!
JGoode
Expert
I have registered, do I need to install anything besides the API DevKit to be able to create this add-on?
Thanks
ArchiCAD 23

Windows 10
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
You need a proper build environment:
On Windows platform Visual Studio 2015 (2017 can be used also, see http://archicadapi.graphisoft.com/working-in-visual-studio-2017) and Microsoft Visual C++ 2015 Update 3 installed. Only the 64-bit architecture is supported.
On macOS platform Xcode 7+ (Xcode 8+ recommended).

After you successfully installed the build environment, then I recommend you to test your environment by opening any example project from the API DevKit (can be found inside the Examples subfolder) and try to build them.
JGoode
Expert
Okay, thanks!

Do I need to do anything to the piece of code that you sent previously for it to work?
I am an absolute beginner so I'm not too sure. All I need is that one simple add-on but I haven't been able to find any add-ons that include those features!
ArchiCAD 23

Windows 10
JGoode
Expert
I've spent most of yesterday evening trying to figure it out in terms of the process of creating an add-on and I can't find much information other than people saying if you don't know how then don't try which is obviously not very useful! Even a vague step by step would be useful as I'd be able to research it myself but I can't even seem to find that! The addon would be incredibly useful but it's not looking very promising
ArchiCAD 23

Windows 10
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
JGoode wrote:
I've spent most of yesterday evening trying to figure it out in terms of the process of creating an add-on and I can't find much information other than people saying if you don't know how then don't try which is obviously not very useful! Even a vague step by step would be useful as I'd be able to research it myself but I can't even seem to find that! The addon would be incredibly useful but it's not looking very promising
As I said, we have many useful blog posts on our site. For example the following post is a step-by-step guide to create an Add-On:
http://archicadapi.graphisoft.com/hello-world-part-2-dialog-with-text-svg-icon-and-button
I hope soon you will be able to write comment to our blog posts, but until then please ask your questions here. Which steps are not detailed enough for you in this blog post? I can update it if I know what is not clear enough.