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

Slab poly fom List of Coords

Anonymous
Not applicable
I'm trying to encapsulate Creating Slab out of given List of Coords. Unfortunately, I got stuck. Mostly I got Err that passed polygon is wrong. I triple checked with related docs, examples and tried different options but it doesn't work. I have also tried it out of fuction.. the same result. Please Help.
My last attempt:
		
		//Quick list
		GS::Array<API_Coord> myLis;
		API_Coord myPt;	myPt.x = 0.0;	myPt.y = 0.0; myLis.Push(myPt);
		myPt;	myPt.x = 0.0;	myPt.y = 1.0; myLis.Push(myPt);
		myPt;	myPt.x = 1.0;	myPt.y = 1.0; myLis.Push(myPt);
		myPt;	myPt.x = 0.0;	myPt.y = 1.0; myLis.Push(myPt);
		SlabDo(myLis);


static void SlabDo(GS::Array<API_Coord>& ptList) {
	
		API_Element		elem;
		API_ElementMemo	mem;
		BNZeroMemory(&elem, sizeof(API_Element));
		BNZeroMemory(&mem, sizeof(API_ElementMemo));
				
		elem.header.typeID = API_SlabID;
		ACAPI_Element_GetDefaults(&elem, nullptr); // &mem?
		int ptListSize = ptList.GetSize();
		
		elem.slab.poly.nCoords = ptListSize + 1;

		elem.slab.poly.nSubPolys = 1;
		elem.slab.poly.nArcs = 0;

		mem.coords = (API_Coord**)BMAllocateHandle((elem.detail.poly.nCoords + 1) * sizeof(API_Coord), ALLOCATE_CLEAR, 0);     //Works but gives Wrong Poligon Error when doing Slab
		mem.pends = (Int32**)BMAllocateHandle((elem.detail.poly.nSubPolys + 1) * sizeof(Int32), ALLOCATE_CLEAR, 0);
		mem.parcs = reinterpret_cast<API_PolyArc**> (BMAllocateHandle(elem.slab.poly.nArcs * sizeof(API_PolyArc), ALLOCATE_CLEAR, 0));  // Gives eerro - not enougth memory

		if (mem.coords == nullptr || mem.pends == nullptr || mem.parcs == nullptr) {
			ACAPI_WriteReport("Not enough memory to create slab polygon data", true);
			ACAPI_DisposeElemMemoHdls(&mem);
			return;
		}

		Int32 iCoord = 1;
		for (int ii=0; ii < ptListSize; ii++) {
			
			ACAPI_WriteReport(GS::ValueToString(ii), true);
			(*mem.coords)[iCoord].x = ptList[ii].x;
			ACAPI_WriteReport(GS::ValueToString(ptList[ii].x), true);

			(*mem.coords)[iCoord].y = ptList[ii].y;

			ACAPI_WriteReport(GS::ValueToString(ptList[ii].y), true);

			++iCoord;
		}

		(*mem.coords)[iCoord] = (*mem.coords)[1];
		(*mem.pends)[0] = 0;
		(*mem.pends)[1] = iCoord;
		
		const GSErrCode err = ACAPI_Element_Create(&elem, &mem);
		if (err != NoError) {
			ACAPI_WriteReport(GS::ValueToString(err), true);
		}
		ACAPI_DisposeElemMemoHdls(&mem);
	}
2 REPLIES 2
Anonymous
Not applicable
ok I got to the point where I have APIERR_IRREGULARPOLY error. Should I try ACPI_Goodies(API_RegularizePolyID) or there is still something wrong with poly it self ?
Anonymous
Not applicable
Ok. Moved back a bit and it's working. I got nCords and number of iterations wrong.