Choose your top Archicad wishes!

Read more
Archicad Python API
About automating tasks in Archicad using the Python API.

C++ API Examples in Python Scripts

poco2013
Mentor

Been working with the latest API with the intent to make available some of the features of the API examples to Python scripts. My idea is that Python is much easier to work with and doesn’t require a recompilation anytime a change is made. Very easy to experiment with. I also don’t want to reinvent the wheel since most of the functions of interest are already contained within the examples. Unfortunately, they are not in a form which can be immediately used, requiring one to recreate and compile the AddOn in a form more specific to one’s needs. It is much, much easier to experiment with a Python script. However, the present Python API has almost no access to the functions demoed in the C++ API examples. And, Graphisoft has indicated that they have no intention of upgrading the Python API in the near future.

 

This why I would like to create parallel AddOn examples which would make those functions available. Actually, this is relatively straight forward, by just making the Graphisoft menu items available to a Python script and passing over the results.

 

However, there is a problem. Graphisoft’s examples almost exclusively write their data/results to the session report via a variadic template (WriteReport). Completely worthless!! The data (output) is packed in a variadic argument and I am unable to unpack it or know how.  

 

I tried using stdargs.h but just get a error on va_start of “va_start intrinsic only allowed in varags”. I also asked Graphisoft’s beta tech support to provide a solution but was just ignored. Understandable, since the beta site now has over 250 submittals. They are swamped.

 

Can anyone provide a means to unpack and use a variadic argument within a template which would provide access to all the results.

template<typename... Args>

void         WriteReport (const char* format, Args&&... args)

{

       ACAPI_WriteReport (format, false, std::forward<Args> (args)...);

}

Of course, I could just bypass the WriteReport function(s), but that would be a huge amount of work – not practical.

 

Can anyone help. Help me, help you?

Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
13 REPLIES 13

Using DevKit 27 Attribute_Test - VS 2019

Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27

For Attribute_Test we'll need the following template specializations:

	// Template specializations here!
	// Anything that doesn't support GS::ValueToUniString will need to be explicitly implemented similar to this:
	template<>
	void addToArray<char*> (char* cStr) {
		container.Push (GS::UniString (cStr));
	}

	template<>
	void addToArray<const char*> (const char* cStr) {
		container.Push (GS::UniString (cStr));
	}

	template<>
	void addToArray<const void*> (const void* printfStr) {
		container.Push (GS::UniString ((const char*)printfStr));
	}

	template<>
	void addToArray<const GS::uchar_t*> (const GS::uchar_t* printfStr) {
		container.Push (GS::UniString (printfStr));
	}

 
Unfortunately I probably won't have time the coming weeks to look into the other issue on how to setup the global container correctly.

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

Now i am getting the message that "addToArray is not a Template" Looks like a template to me.

 

I want to thank you for your help, I got a lot of new ideas now on how to approach this problem. i will continue my investigation.

 

Thanks again, i would not spend anymore of your time on this, I have a lot of new ideas now. Thanks again

Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27

You're welcome!

Just a last thought for the latest error: The code new code needs to go into the class at the same place where I've put previous template specializations. Maybe that's the issue for "addToArray is not a Template"

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