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

Creating a Slab from scratch

Anonymous
Not applicable
Hello!

I am new to this forum, so please forgive me if this topic has been covered before... I am developing a plugin for ArchiCAD, and I am having a problem creating a slab "from scratch" (rather than modify an existing slab element).

I've read the documentation on the ACAPI_Element_Create() routine, API_SlabType, and API_Polygon (several times). And I *believe* I'm creating and filling the element and memo fields correctly...

...but no matter what I do I get a APIERR_BADPOLY error out of the create call.


Is there some sample code that demonstrates *creating* a slab element?


I appreciate any suggestions, references, or samples.

Thanks again.

-larry


p.s. Everything else I've used in the API has worked fine (i.e. creating walls, reading data, manipulating elements, etc. etc.)

p.p.s. I would include my code...but at this point it's a bit of a mess with all of the experiments I've tried to get it to work... 🙂
3 REPLIES 3
Karl Ottenstein
Moderator
lciscon wrote:
Is there some sample code that demonstrates *creating* a slab element?
I haven't done it, so don't have any code to share ... The Element Manager example project's Element_Basics.cpp file has a lot of sample calls to ACAPI_Element_Create (but no slab). The only reference to API_SlabType in the example source files is in this same example's Element_Modify.cpp file.

Hopefully someone else can help ... or you can weed out your code so that you can post it... Ralph and Oleg will be waking up soon. 😉

Karl
One of the forum moderators
AC 28 USA and earlier   •   macOS Sequoia 15.2, MacBook Pro M2 Max 12CPU/30GPU cores, 32GB
Akos Somorjai
Graphisoft
Graphisoft
You can also take a look at the code which creates a library part out of the selection while it works. Or any other code which picks up the API_Element and the API_Element_Memo of an existing slab element.

APIERR_BADPOLY is returned usually if you haven't filled the coords, parcs, and pends fields of API_ElementMemo correctly.

Also, you might take a look at the description of AP_Polygon.

HTH,

Akos
Ralph Wessel
Mentor
lciscon wrote:
...I am having a problem creating a slab "from scratch" (rather than modify an existing slab element).
...but no matter what I do I get a APIERR_BADPOLY error out of the create call.
It's difficult to say at what point your code is failing without more information. Perhaps you could describe your slab creation in pseudo-code?

You need to do something along the following lines:
Initialise an API_Polygon structure (nSubPolys, nCoords, nArcs)
Allocate handles for the relevant fields of an API_ElementMemo structure (vertexIDs, coords, parcs, pends)
For each polygon (perimeter, then holes) {
	For each vertex in the current polygon {
		Fill in the vertex coordinate (coords)
		Fill in the vertex ID (vertexIDs - optional)
		If the vertex is the end of an arc
			Fill in the arc end details (parcs)
	}
	Fill in the polygon end details (pends)
}
Make sure you allocate handles for the memo structures, not pointers. Contact me privately if you're still getting bogged down and I'll take a quick look at your source.
Ralph Wessel BArch
Software Engineer Speckle Systems