cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Developer forum

Receive external data via HTTP GET in a loop

BrunoValads
Contributor

I'm trying to make an automation that allows the user to send data to a server in the web via HTTP POST, and automatically receive data form this server when its available via HTTP GET.

The POST part is solved already, by simply calling it from the menu option clicked by the user, it's a manual action.

The GET part is the problem here, I need it to be constantly requesting the server, i.e in a loop doing GET every second or less, but in a way that Archicad is not frozen by it.

Another idea would be the server sending a command directly to Archicad somehow, making the server acting like the user manually doing the command.

I'm not sure if this is the best approach actually, I'm open to any suggestion.

 

There are a few related things I saw in the forums, like:

6 REPLIES 6

poco2013
Advisor

I believe that, assuming that your polled web site is outside your local network, you would probably need a static address, which is expensive and difficult to get . Lacking that , you might just create a browser in Python to communicate and receive from your remote address.

I believe , the C++ API can do the same ( don't really know how) but would either 'lock up Archicad' or affect performance.

 

The external python script could handle any communication with the remote site and Archicad and would mostly be idle, then ,upon any action, forward any data or commands to a C++AddOn in Archicad via the ExecuteCommand function.There are many instr. videos on YouTube as to how to create a browser in Python.

Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 26

kovacsv
Booster

I would try this approach:

  1. Make the addon preloaded, so Archicad won't unload it automatically when it's not used.
  2. Start a separate thread that constantly polls your web server (e.g. every 5 seconds or so).
  3. When you get the response from the web server, run the command you need.

The tricky part is step 3. It's not safe to do an operation at any time, since it's possible that Archicad works hard on something else, and your call would mess up things. This is why ACAPI_Command_CallFromEventLoop was invented. It makes sure that your command will be executed when Archicad has nothing important to do. It also runs on the main thread, so you don't have to worry much about multithreading issues.

The external server is a webservice our partner maintains, this add-on should speak directly to it.

 


@poco2013 wrote:

The external python script could handle any communication with the remote site and Archicad and would mostly be idle, then ,upon any action, forward any data or commands to a C++AddOn in Archicad via the ExecuteCommand function.There are many instr. videos on YouTube as to how to create a browser in Python.


By "ExecuteCommand" you mean ExecuteAddOnCommand, right? And can this python script be running externally too?

This approach makes sense in my mind, just the technicalities that are bugging me.

 


@kovacsv wrote:

1. Make the addon preloaded, so Archicad won't unload it automatically when it's not used.


By "preloaded" you mean using ACAPI_KeepInMemory?

 


@kovacsv wrote:
2. Start a separate thread that constantly polls your web server (e.g. every 5 seconds or so).

How exactly I do that? GS::Thread is not documented.

Not sure about "ACAPI_KeepInMemory" -- probably yes. But you do need "return APIAddon_Preload;" in CheckEnvuronment to keep the AddOn from being unloaded. I would definitely run the script externally, Internally run Python scripts in Archicad can be trouble because of focus issues. I run all my scripts externally now. Most from  Stream Deck buttons. I would use the Python script to do the polling and just notify or pass the data to the Archicad AddOn via ExecuteAddOnCommand() function.

Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 26


@BrunoValads wrote:

This approach makes sense in my mind, just the technicalities that are bugging me.

 


@kovacsv wrote:

1. Make the addon preloaded, so Archicad won't unload it automatically when it's not used.


By "preloaded" you mean using ACAPI_KeepInMemory?

 


@kovacsv wrote:
2. Start a separate thread that constantly polls your web server (e.g. every 5 seconds or so).

How exactly I do that? GS::Thread is not documented.


You can return APIAddon_Preload in CheckEnvironment. GS::Thread is not documented, but std::thread is: https://en.cppreference.com/w/cpp/thread/thread. If I understand your use case correctly, you don't need python at all.

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!