Archicad Python API
About automating tasks in Archicad using the Python API.
SOLVED!

Adding objects with Python

atomczak
Beginner

Hi! I'm new to Archicad and wonder what is the best way to programmatically place elements in my model, based on some initial geometry. I came across 4 methods:
1) Creating a script in Param-O
2) Creating a script in Grasshopper with Gh Live Connection
3) Using Python API
4) Developing custom Add-On in C++
I tried the first three. Option 1) failed to do what I want. 2) is nice, but I want to avoid opening additional apps. As far as I can see, the option 3) is great but doesn't allow me to create/add any elements, only read/write on existing objects - is that correct? Option 4) is my last resort but if possible I want to avoid writing bespoke C++.
Can anyone recommend the best way forward and hopefully prove me wrong that it is possible to add new objects from Python code 🙂 ?

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

The present Python API has no capability to add objects to a Archicad Plan. The work around is to create a C++ add On to accomplish your scheme, then using a Python script use the function "CommandHandler" to communicate with that Add on and pass parameters back and forth. In this, case that would not be very efficient since you could accomplish the same by just using a dialog within your add On.

Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27

View solution in original post

5 REPLIES 5
Barry Kelly
Moderator

I know you said you wanted to do this programmatically (I can't help you with any ideas there sorry), but I would ...

 

5). Copy & paste from another file.

6). Create a module of the elements that you can merge in when needed.

7). Add those elements to your template so they are there from the beginning.

 

Barry.

One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
atomczak
Beginner

Let me explain the task a bit better. Let's say I have a wall in Archicad and I want to use the script to place instances of 3D bricks inside that wall to show the possible brick distribution and count how many I need. I don't want to manually place 300+ objects for each wall. I know how to do it in Grasshopper or Dynamo, but look for an alternative in Archicad.

That type of task is best suited to Grasshopper or Dynamo, But Dynamo is very limited. You could,of course, do it in the C++ API but any change would require extensive re-programming. Grasshopper is best to explore alternative configurations. To ease the configuration of Grasshopper you night look at using Python scripts within Grasshopper. Grasshopper uses Iron Python not Python 3 which Archicad uses -- They are similar. Don't know much about it but I expect it may not be much better than the native graphic configuration.

Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27

Thanks Gerry. I know Grasshopper well, but because I would need to run this command often I was looking for a solution that doesn't require opening any additional apps, so Grasshopper is my plan B. C++ is my plan C ;).
Do you know the answer to the question about the possibility to place new objects in the model from the Python code using API?  

Solution

The present Python API has no capability to add objects to a Archicad Plan. The work around is to create a C++ add On to accomplish your scheme, then using a Python script use the function "CommandHandler" to communicate with that Add on and pass parameters back and forth. In this, case that would not be very efficient since you could accomplish the same by just using a dialog within your add On.

Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27