pyautocad给出了不透明错误 [英] pyautocad gives ungooglable error

查看:121
本文介绍了pyautocad给出了不透明错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OSError:[WinError -2147221005]无效的类字符串

OSError: [WinError -2147221005] Invalid class string

完整追溯

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/MONSTR/Desktop/Ванжые/Yusuf bey/GUI/test1.py", line 10, in <module>
    for text in acad.iter_objects('Text'):
  File "C:\Users\MONSTR\AppData\Local\Programs\Python\Python36\lib\site-packages\pyautocad\api.py", line 111, in iter_objects
    block = self.doc.ActiveLayout.Block
  File "C:\Users\MONSTR\AppData\Local\Programs\Python\Python36\lib\site-packages\pyautocad\api.py", line 74, in doc
    return self.app.ActiveDocument
  File "C:\Users\MONSTR\AppData\Local\Programs\Python\Python36\lib\site-packages\pyautocad\api.py", line 67, in app
    self._app = comtypes.client.CreateObject('AutoCAD.Application', dynamic=True)
  File "C:\Users\MONSTR\AppData\Local\Programs\Python\Python36\lib\site-packages\comtypes\client\__init__.py", line 227, in CreateObject
    clsid = comtypes.GUID.from_progid(progid)
  File "C:\Users\MONSTR\AppData\Local\Programs\Python\Python36\lib\site-packages\comtypes\GUID.py", line 78, in from_progid
    _CLSIDFromProgID(str(progid), byref(inst))
  File "_ctypes/callproc.c", line 918, in GetResult
OSError: [WinError -2147221005] Invalid class string

当我尝试从此处 从pyautocad中的

I get this error when I am trying to compile this code from here

from pyautocad import Autocad, APoint

acad = Autocad()
acad.prompt("Hello, Autocad from Python\n")
print(acad.doc.Name)

p1 = APoint(0, 0)
p2 = APoint(50, 25)
for i in range(5):
    text = acad.model.AddText('Hi %s!' % i, p1, 2.5)
    acad.model.AddLine(p1, p2)
    acad.model.AddCircle(p1, 10)
    p1.y += 10

dp = APoint(10, 0)
for text in acad.iter_objects('Text'):
    print('text: %s at: %s' % (text.TextString, text.InsertionPoint))
    text.InsertionPoint = APoint(text.InsertionPoint) + dp

for obj in acad.iter_objects(['Circle', 'Line']):
    print(obj.ObjectName)

在Google上工作了几个小时后,我决定在这里想知道
可能是什么原因?

After few hours on google, I decided to wonder here
What can be the reason ?

推荐答案

发生该特定错误,因为您的程序无法正确打开AutoCAD.但是当我自己打开AutoCAD并运行您的代码时,会出现以下错误:

That specific error occurs because your program can't open AutoCAD properly; but when I open AutoCAD by myself and then run your code, it appears the following error:

_ctypes.COMError: (-2147467262, 'No compatible interface', (None, None, None, 0, None))

根据我的经验, COMError 通常是由于与所用程序的连接不良而出现的.我通过将 win32com pyautocad 结合起来解决了此类问题.对于这种特殊情况,应该是这样的:

In my experience, COMError often appears due to a poor connection with the used program. I solve that kind of problem by combining win32com with pyautocad. For this particular case, it would be something like this:

from pyautocad import Autocad, APoint
import win32com.client

AutoCAD = win32com.client.Dispatch("AutoCAD.Application")
acad = Autocad(create_if_not_exists = False)

p1 = APoint(0, 0)
p2 = APoint(50, 25)

for i in range(5):
text = acad.model.AddText('Hi %s!' % i, p1, 2.5)
    acad.model.AddLine(p1, p2)
    acad.model.AddCircle(p1, 10)
    p1.y += 10

dp = APoint(10, 0)
for text in acad.iter_objects(['Hi']):
    print('text: %s at: %s' % (text.TextString, text.InsertionPoint))
    text.InsertionPoint = APoint(text.InsertionPoint) + dp

for line in acad.iter_objects(dont_cast = True):
    print(line.ObjectName)

AutoCAD.Visible = True

这篇关于pyautocad给出了不透明错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆