Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

ETABS v18 API - Cannot attach python with etabs

Status
Not open for further replies.

ThisMustBeAJoke

Structural
Jan 1, 2021
9
Hi , i imported comtypes.client and tried to start with:
ETABSObject = comtypes.client.GetActiveObject("CSI.ETABS.API.ETABSObject")
SapModel = ETABSObject.SapModel

but i got OSError so searched and found these article thread802-455667 but unfortunatelly this didn't work too. The error were saying cytypes can't be strings etc.
Please help me.
 
Replies continue below

Recommended for you

What python environment are you using (pycharm, anaconda spyder or other). Did you have etabs open when you ran your script and on which line did you get the OSError? And also check which version of comtypes you have installed. Latest is version 1.1.8 (Dec 26 2020), I'm using version 1.1.7. Only just saw that version is updated to 1.1.8 now as I check PyPI. Will install and see how well it works.

Python:
import comtypes.client;
import os;
import sys;

try:
    #get the active ETABS object
    EtabsObject=comtypes.client.GetActiveObject("CSI.ETABS.API.ETABSObject")
except (OSError,comtypes.COMError):
    print("No running instance of the program found or failed to attach.")
    sys.exit(-1)
#create SapModel object
SapModel=EtabsObject.SapModel

 
İ tried both pycharm and spyder, with creating a python 3.8 environment ,yes etabs was open. yes i am using comtypes version 1.1.8 and i tried the code that you send it gave like you expected which is No running instance of the program found... So i think this is my real problem, how do i solve this, i am using ETABS v18.1.1



this is the error message i see with using comtypes 1.1.8

Python:
Traceback (most recent call last):
  File "C:/Users/..../AppData/Local/Programs/Python/Python38-32/Lib/site-packages/comtypes/123.py", line 6, in <module>
    EtabsObject=comtypes.client.GetActiveObject("CSI.ETABS.API.ETABSObject")
  File "C:\Users\.....\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 173, in GetActiveObject
    clsid = comtypes.GUID.from_progid(progid)
  File "C:\Users\.....\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\GUID.py", line 78, in from_progid
    _CLSIDFromProgID(str(progid), byref(inst))
  File "_ctypes/callproc.c", line 948, in GetResult
OSError: [WinError -2147221005]
 

this is the error i get from the post i mentioned

Python:
Traceback (most recent call last):
  File "C:/Users/..../AppData/Local/Programs/Python/Python38-32/Lib/site-packages/comtypes/123.py", line 6, in <module>
    EtabsObject=comtypes.client.GetActiveObject("CSI.ETABS.API.ETABSObject")
  File "C:\Users\.....\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 1248, in GetActiveObject
    oledll.oleaut32.GetActiveObject(byref(clsid), None, byref(p))
TypeError: byref() argument must be a ctypes instance, not 'str'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor