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

Python Question for Graphisoft

poco2013
Mentor
I have been working with the new Python API and like it a lot-- It has great potential for automation.
However, the most notable deficiency in the development environment is the lack of 'intellisence' in Pycharm.

Wondering if 'intellisence' could be added or if that is even possible. It seems that if Python's purpose is to allow automation for the average project manager, that 'intellisence would be mandatory?
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi Gerry,

Thank you for starting this topic! I hope there will be many questions here.
But I think it's clearer if you start a new topic for each question or issue related to Python API.

Some kind of intellisence is already available, just like code completion.
I've just recorded a video in Visual Studio Code how it works:
https://ttprivatenew.s3.amazonaws.com/pulse/tlorantfy-graphisoft/attachments/14146027/python_script_...
What do you think which intellisense features are missing the most?

Yes, our main purpose is to allow simple automation for BIM Managers. So I would love to hear how are you doing the Python API!
As you may have heard at the Building Together Event, we will extend the available JSON/Python commands in ARCHICAD 24 updates also and we will try to improve it continuously.

View solution in original post

10 REPLIES 10
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi Gerry,

Thank you for starting this topic! I hope there will be many questions here.
But I think it's clearer if you start a new topic for each question or issue related to Python API.

Some kind of intellisence is already available, just like code completion.
I've just recorded a video in Visual Studio Code how it works:
https://ttprivatenew.s3.amazonaws.com/pulse/tlorantfy-graphisoft/attachments/14146027/python_script_...
What do you think which intellisense features are missing the most?

Yes, our main purpose is to allow simple automation for BIM Managers. So I would love to hear how are you doing the Python API!
As you may have heard at the Building Together Event, we will extend the available JSON/Python commands in ARCHICAD 24 updates also and we will try to improve it continuously.
poco2013
Mentor
Thanks for your response Tibor:

I installed VS code and the Intellisence is working there. Not sure why it's not working in PyCharm but it doesn't matter since it looks like I'll be switching to VS code.

Looking forward to the next Python API update.
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
JSN
Enthusiast
Can confirm. It is indeed not working in PyCharm. Do I have to switch as well or do you know why it is not supported there?
poco2013
Mentor
JSN wrote:
Can confirm. It is indeed not working in PyCharm. Do I have to switch as well or do you know why it is not supported there?
I played with Pycharm a little more and did verify that it IS working somewhat. But not nearly as well as in VS code, as it is somewhat spotty. The main classes of acc,act,& acu seem to work OK but not so much others.

There are two add-ins for Pycharm which have a better reputation. JEDI and KITE. KITE seems to be the better one. Other than that,I don't have any experience with them.

I will be moving to VS code , now that I am aware of it. -- Free
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
JSN
Enthusiast
poco2013 wrote:
I played with Pycharm a little more and did verify that it IS working somewhat. But not nearly as well as in VS code, as it is somewhat spotty. The main classes of acc,act,& acu seem to work OK but not so much others.

There are two add-ins for Pycharm which have a better reputation. JEDI and KITE. KITE seems to be the better one. Other than that,I don't have any experience with them.

I will be moving to VS code , now that I am aware of it. -- Free
Ok, thx for the hint. However I guess I have to convince IT for a switch to VS Code installation as well, as otherwise, for me personally, it's a bit hard to familiarize with the syntax as I could only guess or try to look it up.
dushyant
Enthusiast
Tibor wrote:
I've just recorded a video in Visual Studio Code how it works:
https://ttprivatenew.s3.amazonaws.com/pulse/tlorantfy-graphisoft/attachments/14146027/python_script_...
Hi Tibor,
I tried running this code at my end, but I get this error:
Exception has occurred: TypeError
elements cannot be initialized with <class 'method'>
    for propertyValuesOfElement in acc.GetPropertyValuesOfElements(elements, properties):
Can you help understand what could be the reason?
Thanks.
JSN
Enthusiast
Seems like you maybe have misstyped, can only guess without seeing your actual code but, try this one with simplified variables
properties =[
    acu.GetBuiltInPropertyId("General_ElementID")
]

for e in acc.GetPropertyValuesOfElements(elements,properties):
    for pv in e.propertyValues:
        print(pv.propertyValue.value)
dushyant
Enthusiast
Thanks for your reply.

UPDATE: Yes, there was a typo-error in acc.GetAllElements
Full code:

from archicad import ACConnection

conn = ACConnection.connect()
assert conn

acc = conn.commands
act = conn.types
acu = conn.utilities

# typo-error in line below, GetAllElements() method:
elements = acc.GetAllElements 

properties = [
    acu.GetBuiltInPropertyId("General_ElementID")
]


print("\n")

for e in acc.GetPropertyValuesOfElements(elements,properties):
    for pv in e.propertyValues:
        print(pv.propertyValue.value)
Thanks JSN for pointing it out.
JSN
Enthusiast
I guess you forgot the parentheses when assigning the class to elements.

It should be
elements = acc.GetAllElements()