cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Archicad C++ API
About Archicad add-on development using the C++ API.

How to get object geometry openings

HalitYagar
Participant

Hi I am trying to get object geometries using ArchiCAD API and convert them to .obj files but I couldn't get the openings on the walls. I only got whole geometry of a wall even if it have windows or doors placed on it. What I am missing? Any help is appreciated.

for (Int32 ibody = info3D.fbody; ibody <= info3D.lbody; ibody++) {
	API_Component3D component = {};
	component.header.typeID = API_BodyID;
	component.header.index = ibody;
	err = ACAPI_ModelAccess_GetComponent(&component);
	if (err != NoError)
		continue;

	nVert = component.body.nVert;
	nEdge = component.body.nEdge;
	nPgon = component.body.nPgon;

	// Collect vertices
	std::vector<API_VertType> verts(nVert + 1);
	for (j = 1; j <= nVert; j++) {
		component.header.typeID = API_VertID;
		component.header.index = j;
		err = ACAPI_ModelAccess_GetComponent(&component);
		if (err == NoError) {
			verts[j] = component.vert;
			char buf[128];
			snprintf(buf, sizeof(buf), "v %f %f %f\n", component.vert.x, component.vert.y, component.vert.z);
			objContent += buf;
		}
	}

	// Collect edges
	std::vector<API_EdgeType> edges(nEdge + 1);
	for (j = 1; j <= nEdge; j++) {
		component.header.typeID = API_EdgeID;
		component.header.index = j;
		err = ACAPI_ModelAccess_GetComponent(&component);
		if (err == NoError) {
			edges[j] = component.edge;
		}
	}

	// Write faces
	for (j = 1; j <= nPgon; j++) {
		component.header.typeID = API_PgonID;
		component.header.index = j;
		err = ACAPI_ModelAccess_GetComponent(&component);
		if (err != NoError)
			continue;
		API_PgonType p = component.pgon;

		// Collect all contours (outer + holes)
		std::vector<std::vector<int>> contours;
		std::vector<int> currentContour;

		for (Int32 pedgIdx = p.fpedg; pedgIdx <= p.lpedg; ++pedgIdx) {
			component.header.typeID = API_PedgID;
			component.header.index = pedgIdx;
			err = ACAPI_ModelAccess_GetComponent(&component);
			if (err != NoError) break;
			API_PedgType pedg = component.pedg;

			if (pedg.pedg == 0) {
				// End of current contour, start a new one
				if (!currentContour.empty())
					contours.push_back(currentContour);
				currentContour.clear();
				continue;
			}

			Int32 edgeIdx = abs(pedg.pedg);
			if (edgeIdx < 1 || edgeIdx > nEdge) continue;
			const API_EdgeType& edge = edges[edgeIdx];

			int vIdx = (pedg.pedg > 0) ? edge.vert1 : edge.vert2;
			currentContour.push_back(vertexOffset + vIdx);
		}
		if (!currentContour.empty())
			contours.push_back(currentContour);

		// Only export the outer contour (first one) as a face
		if (!contours.empty() && contours[0].size() >= 3) {
			const std::vector<int>& faceIndices = contours[0];
			for (size_t k = 1; k + 1 < faceIndices.size(); ++k) {
				char buf[128];
				snprintf(buf, sizeof(buf), "f %d %d %d\n", faceIndices[0], faceIndices[k], faceIndices[k + 1]);
				objContent += buf;
			}
		}
	}
	vertexOffset += nVert;
}

 

4 REPLIES 4
LChen
Graphisoft

Hi, I'd suggest you to try pass the window/door guid and call the following command:

HTH.

 

elemHead.guid = window_guid;
err = ACAPI_ModelAccess_Get3DInfo(elemHead, &info3D);
if (err) return;

for (Int32 i = info3D.fbody; i <= info3D.lbody; i++) {
	API_Component3D component{};

	component.header.typeID = API_BodyID;
	component.header.index = i;
	err = ACAPI_ModelAccess_GetComponent(&component);
...

 

HalitYagar
Participant

Yes I am also putting window/door guids into that function and it gives me complete geometry of the object. However I cannot get the openings on the walls that have windows on it. I have a simple project with a wall and a windows on it. I can get the wall and windows using guids and Model_Access_API. But I cannot see the opening on the wall where the window should be. Is there a way to get that?

HalitYagar_5-1751756037153.pngHalitYagar_6-1751756046440.pngHalitYagar_7-1751756068506.png

 

 

 

 

LChen
Graphisoft

Hi, Maybe I'm not fully understand what you meant the opening. You cannot get the opening geometry only as it's represented by wall. I mean if you get the wall geometry, than you can a piece of wall with a hole (opening) geometry.

HTH. 

HalitYagar
Participant

 I expect the wall should have a hole in its geometry representation where the window placed. But maybe I am thinking wrong.

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!