Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMError: (-2147352567, '发生意外。', ('无法获取 Document 对象', 'AutoCAD', 'C:\\Program Files\\Autodesk\\AutoCAD 2020\\HELP\\OLE_ERR.CHM', -2145320900, None)) #58

Open
colomber opened this issue Sep 25, 2024 · 1 comment

Comments

@colomber
Copy link

When i run the Example, i get a Error.

@colomber
Copy link
Author

Hello, Autocad from Python

发生错误: (-2147352567, '发生意外。', ('无法获取 Document 对象', 'AutoCAD', 'C:\Program Files\Autodesk\AutoCAD 2020\HELP\OLE_ERR.CHM', -2145320900, None))

My code:
from pyautocad import Autocad, APoint

尝试连接到已经运行的AutoCAD实例

acad = Autocad(create_if_not_exists=True)

检查是否成功连接到AutoCAD

if acad:
try:
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)
except Exception as e:
    print("发生错误:", e)

else:
print("无法连接到AutoCAD")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant