2023-09-27 10:46 AM - last edited on 2024-09-17 12:47 PM by Doreena Deng
Hi Team,
I was trying to create a wall and window using and Add-on. I was able to create a wall but when I added the code for window nothing got rendered.
I have added the code below
archiCAD 25, IDE XCode
static GSErrCode CreateWallElement (double begX, double begY, double endX, double endY, API_Guid& placedWallGuid)
{
GSErrCode err = NoError;
API_Element wallElement = {};
SetAPIElementType (wallElement, API_WallID);
err = ACAPI_Element_GetDefaults (&wallElement, nullptr);
if (err != NoError) {
return err;
}
wallElement.wall.begC = { begX, begY };
wallElement.wall.endC = { endX, endY };
wallElement.wall.referenceLineLocation = APIWallRefLine_Center;
err = ACAPI_Element_Create (&wallElement, nullptr);
if (err != NoError) {
return err;
}
placedWallGuid = wallElement.header.guid;
return NoError;
}
static GSErrCode CreateWindowElement (double x, double y, API_Guid& placedWindowGuid, API_Guid& placedWallGuidLeft) {
GSErrCode err = NoError;
API_Element windowElement = {};
SetAPIElementType (windowElement, API_WindowID);
err = ACAPI_Element_GetDefaults (&windowElement, nullptr);
if (err != NoError) {
return err;
}
windowElement.window.startPoint.x = x;
windowElement.window.startPoint.y = y;
windowElement.window.openingBase.width = 0.3;
windowElement.window.openingBase.height = 0.3;
windowElement.window.jambDepth = 0.1;
windowElement.window.owner = placedWallGuidLeft;
err = ACAPI_Element_Create (&windowElement, nullptr);
if (err != NoError) {
return err;
}
placedWindowGuid = windowElement.header.guid;
return NoError;
}
main function() {
GS::Array<API_Guid> placedElementGuids;
API_Guid placedWallGuidLeft;
CreateWallElement (0, 0, 0, 10, placedWallGuidLeft);
placedElementGuids.Push (placedWallGuidLeft);
API_Guid placedWindowGuid;
err = CreateWindowElement(10, 10, placedWindowGuid, placedWallGuidLeft);
placedElementGuids.Push(placedWindowGuid);
err = ElementGroup_Create (placedElementGuids);
if (err != NoError) {
return APIERR_CANCEL;
}
}
2023-09-27 01:36 PM - edited 2023-09-27 01:36 PM
HI Team,
Getting this error in debug console
2023-10-13 06:57 AM
Hi Roni!
You are missing the ElementMemo data structure. It's necessary for a lot of elements and especially for elements based on library parts. For such elements, it includes the values for the GDL-Object parameters. Here are some additional & adapted lines you'd need:
API_ElementMemo windowMemo{};
// Disposes the handles at the end of the lifetime of 'memoDisposer'.
// So in this case when exiting the function.
GS::OnExit memoDisposer ([&windowMemo] {ACAPI_DisposeElemMemoHdls (&windowMemo); });
// ...
// Get memo from defaults here
err = ACAPI_Element_GetDefaults (&windowElement, &windowMemo);
if (err != NoError) { return err; }
// ...
// and use when creating the window here
err = ACAPI_Element_Create (&windowElement, &windowMemo);
Also next time please post this in the Archicad C++ API Subforum. I think all of us programmers missed it here ^^
Hope that helps!
Bernd
2023-10-15 07:38 PM - edited 2023-10-15 07:38 PM
Topic moved to proper forum.