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

how to get the zone element that contains another zone element?

Anonymous
Not applicable
Hi.
I want to query the zone element that contains the selected zone element.
Is there any API can solve it?

How to get the outer zone that contains the inner zone? The inner zone is known.
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Ralph Wessel
Mentor
There isn't documentation for this, so I can't say for sure. But looking through the headers, this method in the CustomPolygon2D class looks promising:
// Returns the relative position of the Polygon and the Polygon parameter
RelativePosition GetPosition (const CustomPolygon2D& poly, Boundary boundaries, DetailedRelativePosition* detailed = nullptr) const;
Ralph Wessel BArch

View solution in original post

8 REPLIES 8
Anonymous
Not applicable
Hi.
Is there any API that can get different spatial relationship between elements?
Thanks.
Hello DevJeer,

Between one Zone and other elements we just have to create a schedule to show the relation between them
But if there are 2 Zones at the same place, an element into them can not know with which be linked (and only one of them).
So I think if the are two zones in a same area... They are probably not able to communicate together 😕

It is like a "mother zone" and linked "daughter element".
Christophe - FRANCE
Archicad Designer and Teacher
Archicad 15 to 27 FRA FULL

OS 11.6 Big Sur - MacBook Pro 2017 - 16Go RAM
"Quality is never an accident ; it's always the result of an intelligent effort" John Ruskin
Anonymous
Not applicable
Christophe wrote:
Hello DevJeer,

Between one Zone and other elements we just have to create a schedule to show the relation between them
But if there are 2 Zones at the same place, an element into them can not know with which be linked (and only one of them).
So I think if the are two zones in a same area... They are probably not able to communicate together 😕

It is like a "mother zone" and linked "daughter element".
Thanks.
Are there other methods that can get the spatial relationship of two polygon?
Ralph Wessel
Mentor
I don't know of an API function that will automatically retrieve the relationship between zones. But you could do the following:
1) Get the selected zone
2) Get the polygon of the selected zone
3) Iterate through the model database to search for zone elements
4) For each zone found, test if its polygon encloses the selected zone polygon
Ralph Wessel BArch
Anonymous
Not applicable
Ralph wrote:
I don't know of an API function that will automatically retrieve the relationship between zones. But you could do the following:
1) Get the selected zone
2) Get the polygon of the selected zone
3) Iterate through the model database to search for zone elements
4) For each zone found, test if its polygon encloses the selected zone polygon
Thanks.
'4) For each zone found, test if its polygon encloses the selected zone polygon'
Is there any api method that can do this?
Ralph Wessel
Mentor
I'm sure there is. We started our element and polygon classes a long time ago, so I haven't delved into the ARCHICAD API for that. If we're testing whether a zone encloses another polygon, we just do something like this:
bool isParent(const ZoneElement& testZone, const Polygon& childPolygon)
{
	return ((testZone.getPolygon() != nullptr) &&			//Check the test zone has a valid polygon
		testZone.getPolygon()->encloses(childPolygon));		//…and the test zone polygon encloses the child polygon
}
I know the API has built up a comprehensive geometry library over the years - maybe one of the GS guys could point you to the right function?
Ralph Wessel BArch
Anonymous
Not applicable
Ralph wrote:
I'm sure there is. We started our element and polygon classes a long time ago, so I haven't delved into the ARCHICAD API for that. If we're testing whether a zone encloses another polygon, we just do something like this:
bool isParent(const ZoneElement& testZone, const Polygon& childPolygon)
{
	return ((testZone.getPolygon() != nullptr) &&			//Check the test zone has a valid polygon
		testZone.getPolygon()->encloses(childPolygon));		//…and the test zone polygon encloses the child polygon
}
I know the API has built up a comprehensive geometry library over the years - maybe one of the GS guys could point you to the right function?
Thanks.
Whether it is possible to solve this problem by Geometry API?
Solution
Ralph Wessel
Mentor
There isn't documentation for this, so I can't say for sure. But looking through the headers, this method in the CustomPolygon2D class looks promising:
// Returns the relative position of the Polygon and the Polygon parameter
RelativePosition GetPosition (const CustomPolygon2D& poly, Boundary boundaries, DetailedRelativePosition* detailed = nullptr) const;
Ralph Wessel BArch