Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Error when getting Python to attach to ETABS

Status
Not open for further replies.

fracture_point

Structural
Joined
Mar 7, 2019
Messages
58
Location
CA
Hi, I'm using the following code:

import sys
import comtypes.client

try:
myETABSObject = 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)
SapModel = myETABSObject.SapModel​

I'm getting an attribute error:

AttributeError: module 'comtypes.gen.CSiAPIv1' has no attribute 'cOAPI'​

Does anyone know how to fix this?

I'm using Pycharm, ETABS v18.
 
Hi. Thanks for the reply! I actually saw this thread before posting but I don't really understand what the __init__ file is doing. Are you able to provide any context? Do I need to have that at the beginning of my code? It seems Bjorn managed to fix his issue but didn't explain why.
 
I can't say I completely understand the usage of an __init__.py file for python packages.

What comtypes version are you using. When I first started using the etabs API with python early in 2019 I was using comtypes version 1.1.2, that was giving me some trouble and I had to change a little bit of the __init__.py file to get it working, I remember it being something like a try block with no exception catch. However, many of my colleagues started using my scritps and they where using comtypes 1.1.7 (still current release). Now, I think there are still some bugs with this version of comtypes, I still get errors when trying to get modal output. Will try and did into it a bit further. But what version of comtypes are you using.
 
I am working in comtypes 1.1.7. I actually switched to Anaconda instead of Pycharm and it seemed to fix the issue, I have no clue why.
 
Same here, one of my colleagues also had the same issue and I can't work it out but think it has something to do with the file that get's generated in the comtypes.gen folder. Best fix I found is uninstall and re-install.

How are the scripts going, I see by some of your other posts that you are looking to write a few custom functions to automate your workflow?
 
rscassar said:
How are the scripts going, I see by some of your other posts that you are looking to write a few custom functions to automate your workflow?

First code I'm going to write it to take raw coordinate data from Revit (using a dynamo script) and then develop a python code that will build a model with the geometric data in ETABS. I think it will be a good project to develop an understanding of the API. Then I'm not sure which direction I will go, I feel like understanding ETABS API will open a lot of doors for automation!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top