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

Creating an window on wall using C++ code

roni
Booster

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;
    }
}

 

 


 

3 REPLIES 3
roni
Booster

HI Team,
Getting this error in debug console

err GS::GSErrCode -2130313112
This link shows the error as 
The passed parameters are inconsistent.

I am thinking some of the mandatory parameters was missing or not provided correctly, but the error message to general.
Any comments?

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

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: bschwb.com

Topic moved to proper forum.

Get Archicad Tips at https://twitter.com/laszlonagy
AMD Ryzen 1700X CPU, 48 GB RAM, Nvidia GTX 1060 6GB, 500 GB NVMe SSD
2x28" (2560x1440), WIN10 PRO ENG, Ac20-Ac27
Loving Archicad since 1995

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!