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.
SOLVED!

Exception during IFC property hook execution Archicad 29

Emkave
Enthusiast

Hello guys. I was coding the hookers for Archicad 29 and something went wrong. I was following the examples in IFC_Test, and I wrote the code:

Emkave_0-1757669104747.png

 

I have also executed this code that gave no errors:

IFCAPI::GetHookManager().RegisterPropertyHook(IFCHook::property_hook);


However, for some reason, after the ending of execution of property_hook(), I received this exception error:

 

Screenshot 2025-09-12 105725.png

 

I want also to point out that the ifc values were creating fine, without any errors. I was checking it a lot of times through the debugger.

 

Have someone dealt with this issue before? I would be glad if someone could point me to my mistake. Thank you in advance!

 

17 REPLIES 17

It's hard to say without running your exact example myself. But I've successfully compiled and run the IFCHOOK_Test example without crashes.

My first guess is, that you need to make your hook a static function because the function needs to stay available. Something like:

static void IFCHook::PropertyHook1(const ......) {
...
}

 

Let us know if this solves the issue.

Bernd

Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com

Having the following code:

template<typename TValue>
static void AddProperty(std::vector<IFCAPI::Property>& properties, const GS::UniString& setName, const GS::UniString& name, const GS::UniString& valueType, const TValue& value)
{
	auto apiValue = IFCAPI::GetPropertyBuilder().CreateValue(valueType, value);
	if (apiValue.IsOk()) {
		auto apiProperty = IFCAPI::GetPropertyBuilder().CreatePropertySingleValue(setName, name, *apiValue);
		if (apiProperty.IsOk())
			properties.emplace_back(*apiProperty);
	}
}


static void AddTextProperty(std::vector<IFCAPI::Property>& properties, const GS::UniString& setName, const GS::UniString& name, const GS::UniString& valueType, const GS::UniString& value)
{
	AddProperty(properties, setName, name, valueType, value);
}


void IFCHook::PropertyHook1(const IFCAPI::ObjectID& objectID, std::vector<IFCAPI::Property>& properties) noexcept {


	AddTextProperty(properties, "Sample Property Set", "Sample Property", "IfcLabel", "Hello from IFC Hook!");
	AddProperty(properties, "Sample Property Set", "Sample Integer Property", "IfcInteger", (Int64)12345);
}



void IFCHook::Enable() noexcept {
	auto res = IFCAPI::GetHookManager().RegisterPropertyHook(IFCHook::PropertyHook1);

	if (!res.IsOk()) {
		throw "Unable to register property hook.";
	}
}




 

...still causes a crash. I just place a chair, trying to check out its properties and it crashes. 

P.S. IFCHook::PropertyHook1 is already static as it is declared in such a way in IFCHook class.

Hm... weird! Can you show the call stack when the crash happens?

Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com

Screenshot 2025-09-26 181441.png

 

 This is where it jumps after finishing the execution of IFCHook::PropertyHook1()

And this is when it is 1 Step Over behind the crash

 

Emkave_0-1758904466841.png

 

My suspection is that possibly the value that I put into the vector gets disappeared from the std::vector. Hence I get the crash for reading the invalid address. 

Btw. When I copied the entire test code and tried to test it out, it would also crash Archicad for read access violation. 

 

Emkave_0-1759135914597.png
It happens in this loop, on 5th iteration:

static void PropertyHookCommon(const IFCAPI::ObjectID& objectID, std::vector<IFCAPI::Property>& properties, const GS::UniString namePostfix)
{
	API_Element apiElement{};
	GS::UniString infoString;
	if (GetAPIElement(objectID, apiElement, &infoString)) {
		// create scheme property after every infoString character
		for (auto index : GS::InRange((UIndex)0, infoString.GetLength())) {
			if (infoString[index].IsWhiteSpace())
				continue;

			GS::UniString character = infoString.GetSubstring(index, 1);

			GS::UniString propertySetName = "PSet_InfoString";
			GS::UniString propertyName = character;

			propertySetName.Append(namePostfix);
			propertyName.Append(namePostfix);

			AddTextProperty(properties, propertySetName, propertyName, "IfcLabel", character);
		}
	}
}

 

Solution

OK, I just saw a possible solution. Are you making a Debug build? Try compiling it as a Release build.

 

Somebody else seemed to have a very similar problem in AC29 TP and this was their solution. (https://community.graphisoft.com/t5/Graphisoft-Technology-Preview/Crashes-when-invoking-property-hoo...)

 

This relates to an issue I had a while back with Debug builds. Check this post to see how you can adapt your Debug build once you've confirmed that it was the issue by trying the Release build: https://community.graphisoft.com/t5/Archicad-C-API/Crash-for-GetOrganizationIds-in-DEBUG-builds-link...

 

 

Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com

Hello. Yes, it works now with Release build. Thank you a lot! Now I really wonder why my issue appeared in the first place... 

I will try fix the Debug now. Thank you and everybody else here a lot!