BIM Coordinator Program (INT) April 22, 2024
Find the next step in your career as a Graphisoft Certified BIM Coordinator!
Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Instances/BaseElems

Anonymous
Not applicable
Hello. I want to ask if there is any way to check if an element/body is an instance of another in Archicad 22's API. I have tried many things such as checking Guids of the various components, comparing indexes of polygons. But after much testing, it is extremely difficult to verify whether or not an element still remains an instance of element.

In Archicad 21, I used to be able to extract the ModelerAPI::BaseElem from the ModellerAPI::Element and check the hash value to compare between other base elements to determine whether they share the same geometry. Archicad 22 seems to have deprecated this class and I no longer have access to it.

I much appreciate any advice and apologise if I utilise terms not native to Archicad.
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Akos Somorjai
Graphisoft
Graphisoft
Arc wrote:
Thank you for the reply.

Is there an example I can refer to as reference with regards to using this function?
Here it is:
void ElementExporter::GetBaseElemId (const ModelerAPI::Element& element, ModelerAPI::BaseElemId* baseElemId)
{
	GS::NonInterruptibleProcessControl processControl;
	element.GetBaseElemId (baseElemId,
		processControl,
		ModelerAPI::Element::EdgeColorInBaseElemId::NotIncluded,
		ModelerAPI::Element::PolygonAndFaceTextureMappingInBaseElemId::NotIncluded,
		ModelerAPI::Element::BodyTextureMappingInBaseElemId::NotIncluded,
		ModelerAPI::Element::EliminationInfoInBaseElemId::NotIncluded);
}
Regards, Akos

View solution in original post

7 REPLIES 7
Akos Somorjai
Graphisoft
Graphisoft
Hi,

AC 22 introduced the ModelerAPI::BaseElemId to solve that kind of issue. This can be used to compare instances of elements, it has operator== defined. It can also serve as a hashable key.

Call elem.GetBaseElemId() to access it.

Regards, Akos
Anonymous
Not applicable
Thank you for the reply.

I tried to use it but I encountered a problem where I cannot seem to obtain the BaseElemId without at the same time requiring to extract a lot of other types of Ids as well.

ModelerAPI::Element element;
ModelerAPI::BaseElemId baseId;
element.GetBaseElemId(&baseId);

ModelerAPI::Element element;
ModelerAPI::BaseElemId baseId = element.GetBaseElemId();
Neither of the above seem to be able to just give me the BaseElemId. The first one requires me to also add a bunch of parameters that I don't know how to initialise and does not seem to accept nullpointers. The second one cannot work because it is a void function and thus does not return anything. Is there an example I can refer to as reference with regards to using this function?
Solution
Akos Somorjai
Graphisoft
Graphisoft
Arc wrote:
Thank you for the reply.

Is there an example I can refer to as reference with regards to using this function?
Here it is:
void ElementExporter::GetBaseElemId (const ModelerAPI::Element& element, ModelerAPI::BaseElemId* baseElemId)
{
	GS::NonInterruptibleProcessControl processControl;
	element.GetBaseElemId (baseElemId,
		processControl,
		ModelerAPI::Element::EdgeColorInBaseElemId::NotIncluded,
		ModelerAPI::Element::PolygonAndFaceTextureMappingInBaseElemId::NotIncluded,
		ModelerAPI::Element::BodyTextureMappingInBaseElemId::NotIncluded,
		ModelerAPI::Element::EliminationInfoInBaseElemId::NotIncluded);
}
Regards, Akos
Anonymous
Not applicable
It works now! Many thanks!
drjustice
Newcomer
Hi, I'm looking into a similar issue and would need clarification.

Let's say I have 2 chairs placed & orientated at different locations of the model. If I just extract the geometries of the Elements via their mesh bodies, each chair will have vertices at different spots (eg: the object's tranformation appears to be baked into the vertices I obtain).

Are you saying that if I use BaseElemId, I will be able to get the same hash for two objects that are placed at different locations, and that to extract the vertices in local coordinate of the bodies, I will need to multiply the vertices by the inverse of ModelerAPI::Element.GetElemLocalToWorldTransformation() for one of them?
drjustice
Newcomer
Following up on my own thread: Yes, I confirm that to obtain the geometry in local coordinates, apply the inverse of the element's transform.
drjustice
Newcomer
.. or, to get the geometry's local coordinates, the easier way is to specify the reference coordinate system.

meshBody.GetVertex(vertexId, &positionW);

is the same as

meshBody.GetVertex(vertexId, &positionW, ModelerAPI::CoordinateSystem::World);

but you can also use:

meshBody.GetVertex(vertexId, &positionL, ModelerAPI::CoordinateSystem::ElemLocal);
Learn and get certified!

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!