We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

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

Experimental Python add-on is available for Archicad 23

Akos Somorjai
Graphisoft
Graphisoft
Hi folks,

See the blog post on the developer site: https://archicadapi.Graphisoft.com/experimental-python-add-on-for-archicad23

Good luck!

Akos
86 REPLIES 86
poco2013
Mentor
To describe a text paragraph, one must use the API structure of API_ParagraphType which would normally be wrapped as a APIObject() in Archicad's Python. The structure is:
typedef struct {
        Int32           from;
        Int32           range;
        API_JustID      just;
        Int32           filler_1;
        double          firstIndent;
        double          indent;
        double          rightIndent;
        double          spacing;
        API_TabType     *tab;
        API_RunType     *run;
        Int32           *eolPos;
        Int32           filler_2;
        double          width;
        double          height;
        double          filler_3[2];
    } API_ParagraphType;
Note: that the first variable, a Int, is named "from" which is a keyword in Python and not usable for reference.Therefore,it's not possible to create a wrapped paragraph python object.The actual code would parallel the example for "rich text" shown in the Element_Test example Add On. BUT its not now possible to create a paragraph object because of this conflict. Any workarounds? (Other than breaking the document up into separate draw segment, which would be a PITA) It might be simpler if Graphisoft would implement HTML or the other inline web format such as "markdown"?
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
mr_Mikhail
Booster
poco2013 wrote:
To describe a text paragraph, one must use the API structure of API_ParagraphType which would normally be wrapped as a APIObject() in Archicad's Python. The structure is:

Note: that the first variable, a Int, is named "from" which is a keyword in Python and not usable for reference.Therefore,it's not possible to create a wrapped paragraph python object.The actual code would parallel the example for "rich text" shown in the Element_Test example Add On. BUT its not now possible to create a paragraph object because of this conflict. Any workarounds? (Other than breaking the document up into separate draw segment, which would be a PITA) It might be simpler if Graphisoft would implement HTML or the other inline web format such as "markdown"?
If I understand correctly you are trying to create plain text, the only thing I know can be seen in "DoElementTest.py"
def DrawText(x, y, text):
    element = APIObject()
    element.head = APIObject()
    element.head.typeID = API_TextID
    element.head.hasMemo = True
    element.loc = APIObject()
    element.loc.x = x
    element.loc.y = y
    memo = APIObject()
    memo.textContent = text
    return CreateText(element, memo)
Anonymous
Not applicable
I would like to ask for an additional qualification regarding getting information about elements. In previous example mr.Mikhail suggested using
guid = ClickElement()
element = GetWall(guid)
structure, where one could type element.List() in order to get information and idea what properties one could use. However, how do you apply that to other objects in archicad? How would you get for example window instead of wall, when there is not GetWindow (guid) function, or GetDoor(guid) or anything similar? Or am I missing something? I was not able to find GetWall(guid) function neither in the help file.
poco2013
Mentor
If I understand correctly you are trying to create plain text, the only thing I know can be seen in "DoElementTest.py"
Nope -- I am trying to recreate "rich text" or as Graphisoft defines it - "multistyle Text". Multistyle uses a API_ParagraphType structure which , as i mentioned can not be used in Python because of the use of the "from" keyword.
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
poco2013
Mentor
Petar.Pejic wrote:
I would like to ask for an additional qualification regarding getting information about elements. In previous example mr.Mikhail suggested using
guid = ClickElement()
element = GetWall(guid)
FYI-- There is no GetWindow/GetDoor implementation YET in Archicad's Python. Since this only a experiment I assume that only a representative sample of functions were provided and more is yet to come.

However, note that the API GetElement function returns the parameters of the element. Properties describe the element. In many cases the element's parameters are duplicated in it's 'builin' properties. You may find what you need in looking through the door/window properties which you can do using the python function:

GetElementPropertyDefinitionDictionary(elem,filterID) The filter should be set to '....._All' which will give all the BuiltIn properties. May not be what you need but worth a look?
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
mr_Mikhail
Booster
Petar.Pejic wrote:
I would like to ask for an additional qualification regarding getting information about elements. In previous example mr.Mikhail suggested using
guid = ClickElement()
element = GetWall(guid)
structure, where one could type element.List() in order to get information and idea what properties one could use. However, how do you apply that to other objects in archicad? How would you get for example window instead of wall, when there is not GetWindow (guid) function, or GetDoor(guid) or anything similar? Or am I missing something? I was not able to find GetWall(guid) function neither in the help file.
There is an example "ListClickedElementMembers.py".
Inside is used GetElement (), which is not in the documentation, works with almost all types of elements
mr_Mikhail
Booster
poco2013 wrote:
If I understand correctly you are trying to create plain text, the only thing I know can be seen in "DoElementTest.py"
Nope -- I am trying to recreate "rich text" or as Graphisoft defines it - "multistyle Text". Multistyle uses a API_ParagraphType structure which , as i mentioned can not be used in Python because of the use of the "from" keyword.
I understood. Sorry, I still do not know English well and the translator does not always help
Probably have to wait for individual functions to work with multitext.
As with many others.
I tried, something to throw on API_ParagraphType, but without successfully

UPD. If it helps. See attachment
UPD2. API_ParagraphType should be passed to memo
mr_Mikhail
Booster
Please help me.
I need for a presentation why Python is needed for ARCHICAD. What it gives, why it is needed and what can be done with it.
After all, there is GDL and C++.
I've already broken my mind.
Anonymous
Not applicable
Thank you all for explaining that in more detail.
mr.Mikhail, what sort of help you need?

Edit: ListClickedElementMembers.py seams to work only for walls, it does not recognize any other elements when clicked (windows, doors, columns, roofs, slabs). Only walls. Is it just me, or others have that issue as well?
mr_Mikhail
Booster
Petar.Pejic wrote:
Thank you all for explaining that in more detail.
mr.Mikhail, what sort of help you need?
Write a list for the presentation.
  • Why do you need Python for Archicad.
  • What it can give or what it can do.
  • What is the advantage over GDL and C++.
I want to read the opinions of other people.