The Global ARCHICAD Community

Stay informed. Get help. Share your knowledge.

Discussions about using GRAPHISOFT's tools (API DevKit) for independent software developers

Moderators: Barry Kelly, Karl Ottenstein, LaszloNagy, ejrolon, gkmethy, Tibor Lorántfy, MOREH Tamas, Akos Somorjai, Ed Brown, Mihály Palenik

#286178
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:
Code: Select all //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); }
By kzaremba
#286236
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 ?