通过获取正在运行的SapObject创建
import sys
import comtypes.client
# 通过已经存在的sap2000程序创建实例对象
try:
# 获得正在运行的SapObject
mySapObject = comtypes.client.GetActiveObject("CSI.SAP2000.API.SapObject")
except (OSError, comtypes.COMError):
print("No running instance of the program found or failed to attach.")
sys.exit(-1)
# create SapModel object
SapModel = mySapObject.SapModel